Exemplo n.º 1
0
func (d *DNSimpleProvider) Init(rootDomainName string) error {
	var email, apiToken string
	if email = os.Getenv("DNSIMPLE_EMAIL"); len(email) == 0 {
		return fmt.Errorf("DNSIMPLE_EMAIL is not set")
	}

	if apiToken = os.Getenv("DNSIMPLE_TOKEN"); len(apiToken) == 0 {
		return fmt.Errorf("DNSIMPLE_TOKEN is not set")
	}

	d.root = utils.UnFqdn(rootDomainName)
	d.client = api.NewClient(apiToken, email)
	d.limiter = ratelimit.NewBucketWithRate(1.5, 5)

	domains, _, err := d.client.Domains.List()
	if err != nil {
		return fmt.Errorf("Failed to list zones: %v", err)
	}

	found := false
	for _, domain := range domains {
		if domain.Name == d.root {
			found = true
			break
		}
	}

	if !found {
		return fmt.Errorf("Zone for '%s' not found", d.root)
	}

	logrus.Infof("Configured %s with zone '%s'", d.GetName(), d.root)
	return nil
}
Exemplo n.º 2
0
// NewDNSProviderDNSimple returns a DNSProviderDNSimple instance with a configured dnsimple client.
// Authentication is either done using the passed credentials or - when empty - using the environment
// variables DNSIMPLE_EMAIL and DNSIMPLE_API_KEY.
func NewDNSProviderDNSimple(dnsimpleEmail, dnsimpleApiKey string) (*DNSProviderDNSimple, error) {
	if dnsimpleEmail == "" || dnsimpleApiKey == "" {
		dnsimpleEmail, dnsimpleApiKey = dnsimpleEnvAuth()
		if dnsimpleEmail == "" || dnsimpleApiKey == "" {
			return nil, fmt.Errorf("DNSimple credentials missing")
		}
	}

	c := &DNSProviderDNSimple{
		client: dnsimple.NewClient(dnsimpleApiKey, dnsimpleEmail),
	}

	return c, nil
}
Exemplo n.º 3
0
func init() {
	apiToken := os.Getenv("DNSIMPLE_TOKEN")
	if len(apiToken) == 0 {
		logrus.Info("DNSIMPLE_TOKEN is not set, skipping init of DNSimple provider")
		return
	}

	email := os.Getenv("DNSIMPLE_EMAIL")
	if len(email) == 0 {
		logrus.Info("DNSIMPLE_EMAIL is not set, skipping init of DNSimple provider")
		return
	}

	dnsimpleHandler := &DNSimpleHandler{}
	if err := RegisterProvider("dnsimple", dnsimpleHandler); err != nil {
		logrus.Fatal("Could not register dnsimple provider")
	}

	dnsimpleHandler.root = strings.TrimSuffix(dns.RootDomainName, ".")
	dnsimpleHandler.client = dnsimple.NewClient(apiToken, email)

	domains, _, err := dnsimpleHandler.client.Domains.List()
	if err != nil {
		logrus.Fatalf("Failed to list hosted zones: %v", err)
	}

	found := false
	for _, domain := range domains {
		if domain.Name == dnsimpleHandler.root {
			found = true
			break
		}
	}

	if !found {
		logrus.Fatalf("Hosted zone %s is missing", dnsimpleHandler.root)
	}

	logrus.Infof("Configured %s with hosted zone %q ", dnsimpleHandler.GetName(), dnsimpleHandler.root)
}
Exemplo n.º 4
0
// Go starts the dns manager
func Go() (err error) {
	instanceID = os.Getenv("INSTANCE_ID")
	if instanceID == "" {
		return fmt.Errorf("INSTANCE_ID not defined")
	}

	proxyIPv4 = os.Getenv("COREOS_PUBLIC_IPV4")
	if proxyIPv4 == "" {
		return fmt.Errorf("COREOS_PUBLIC_IPV4 not defined")
	}

	proxyIPv6 = os.Getenv("COREOS_PUBLIC_IPV6")
	if proxyIPv6 == "" {
		return fmt.Errorf("COREOS_PUBLIC_IPV6 not defined")
	}

	dnsimpleEmail = os.Getenv("DNSIMPLE_EMAIL")
	if dnsimpleEmail == "" {
		return fmt.Errorf("DNSIMPLE_EMAIL not defined")
	}

	dnsimpleAPI = os.Getenv("DNSIMPLE_API")
	if dnsimpleAPI == "" {
		return fmt.Errorf("DNSIMPLE_API not defined")
	}

	// Create a new dnsimple client
	dns = dnsimple.NewClient(dnsimpleAPI, dnsimpleEmail).Domains

	// Create a new etcd client
	etcd, err = client.New(client.Config{
		Endpoints: strings.Split(os.Getenv("ETCD_ENDPOINTS"), ","),
		Transport: client.DefaultTransport,
	})
	if err != nil {
		return err
	}

	// See if we already have a recordid in etcd
	k := client.NewKeysAPI(etcd)

	// Get IPv4 recordid
	resp, err := k.Get(context.Background(), dnsNamespace+"/ipv4/"+instanceID, nil)
	if err != nil {
		if err.(client.Error).Code != client.ErrorCodeKeyNotFound {
			return err
		}
	} else {
		recordID4, err = strconv.Atoi(resp.Node.Value)
		if err != nil {
			fmt.Println("Failed to parse etcd recordID4", err.Error())
		}
	}

	// Get IPv6 recordid
	resp, err = k.Get(context.Background(), dnsNamespace+"/ipv6/"+instanceID, nil)
	if err != nil {
		if err.(client.Error).Code != client.ErrorCodeKeyNotFound {
			return err
		}
	} else {
		recordID6, err = strconv.Atoi(resp.Node.Value)
		if err != nil {
			fmt.Println("Failed to parse etcd recordID6", err.Error())
		}
	}

	// Update the DNS record with our IP
	err = Update()
	if err != nil {
		return err
	}

	return nil
}