コード例 #1
0
ファイル: main.go プロジェクト: cycps/addie
func main() {

	if len(os.Args) != 2 {
		fmt.Fprintf(os.Stderr, "usage: keygen <dns name>\n")
		os.Exit(1)
	}

	key, err := dnsc.Keygen(os.Args[1])
	if err != nil {
		fmt.Fprint(os.Stderr, "error executing dnssec-keygen\n")
		fmt.Fprintf(os.Stderr, "%v\n", err)
	}

	fmt.Printf("key: %s\n", key)
}
コード例 #2
0
ファイル: main.go プロジェクト: cycps/addie
func generateDnsServerConfig() error {

	var spec dnsc.ServerSpec

	spec.Xpname = design.Name
	spec.FQDN = "dns." + spec.Xpname + ".cypress.net"
	spec.Addr = "2001:cc:0:0::d47"

	for _, e := range design.Elements {
		switch e.(type) {
		case addie.Computer:
			c := e.(addie.Computer)
			cs := dnsc.ClientSpec{}
			cs.FQDN = fmt.Sprintf("%s.%s.cypress.net", c.Name, design.Name)
			key, err := dnsc.Keygen(cs.FQDN)
			if err != nil {
				return err
			}
			cs.Key = key
			spec.Clients = append(spec.Clients, cs)
		case addie.Sax:
			s := e.(addie.Sax)
			cs := dnsc.ClientSpec{}
			cs.FQDN = fmt.Sprintf("%s.%s.cypress.net", s.Name, design.Name)
			key, err := dnsc.Keygen(cs.FQDN)
			if err != nil {
				return err
			}
			cs.Key = key
			spec.Clients = append(spec.Clients, cs)
		}
	}

	js, err := json.MarshalIndent(spec, "", "  ")
	if err != nil {
		log.Println(err)
		return fmt.Errorf("Failed to marshal dns server spec")
	}

	dir := userDir() + "/" + design.Name + ".dns"
	os.MkdirAll(dir, 0755)
	err = ioutil.WriteFile(dir+"/server_spec.json", js, 0644)
	if err != nil {
		log.Println(err)
		return fmt.Errorf("Failed to write dns spec file")
	}

	for _, cs := range spec.Clients {
		js, err = json.MarshalIndent(cs, "", "  ")
		if err != nil {
			log.Println(err)
			return fmt.Errorf("Failed to marshal dns client spec")
		}
		shortname := strings.Split(cs.FQDN, ".")[0]
		err = ioutil.WriteFile(dir+"/"+shortname+".json", js, 0644)
		if err != nil {
			log.Println(err)
			return fmt.Errorf("Failed to write dns client file")
		}
	}

	return nil
}