Beispiel #1
0
func (r *Route53Provider) setHostedZone(rootDomainName string) error {
	if envVal := os.Getenv("ROUTE53_ZONE_ID"); envVal != "" {
		r.hostedZoneId = strings.TrimSpace(envVal)
		if err := r.validateHostedZoneId(rootDomainName); err != nil {
			return err
		}
		return nil
	}

	r.limiter.Wait(1)
	params := &awsRoute53.ListHostedZonesByNameInput{
		DNSName:  aws.String(utils.UnFqdn(rootDomainName)),
		MaxItems: aws.String("1"),
	}
	resp, err := r.client.ListHostedZonesByName(params)
	if err != nil {
		return fmt.Errorf("Could not list hosted zones: %v", err)
	}

	if len(resp.HostedZones) == 0 || *resp.HostedZones[0].Name != rootDomainName {
		return fmt.Errorf("Hosted zone for '%s' not found", rootDomainName)
	}

	zoneId := *resp.HostedZones[0].Id
	if strings.HasPrefix(zoneId, "/hostedzone/") {
		zoneId = strings.TrimPrefix(zoneId, "/hostedzone/")
	}

	r.hostedZoneId = zoneId
	return nil
}
Beispiel #2
0
func (c *CloudflareProvider) Init(rootDomainName string) error {
	var email, apiKey string
	if email = os.Getenv("CLOUDFLARE_EMAIL"); len(email) == 0 {
		return fmt.Errorf("CLOUDFLARE_EMAIL is not set")
	}

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

	c.client = api.New(&api.Options{
		Email: email,
		Key:   apiKey,
	})

	c.ctx = context.Background()
	c.root = utils.UnFqdn(rootDomainName)

	if err := c.setZone(); err != nil {
		return fmt.Errorf("Failed to set zone for root domain %s: %v", c.root, err)
	}

	logrus.Infof("Configured %s with zone '%s'", c.GetName(), c.root)
	return nil
}
Beispiel #3
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
}
Beispiel #4
0
func (d *PointHQProvider) Init(rootDomainName string) error {
	var email, apiToken string
	if email = os.Getenv("POINTHQ_EMAIL"); len(email) == 0 {
		return fmt.Errorf("POINTHQ_EMAIL is not set")
	}

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

	d.root = utils.UnFqdn(rootDomainName)
	d.client = pointdns.NewClient(email, apiToken)

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

	found := false
	for _, zone := range zones {
		if zone.Name == d.root {
			found = true
			d.zone = zone
			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
}
Beispiel #5
0
func (g *GandiProvider) Init(rootDomainName string) error {
	var apiKey string
	if apiKey = os.Getenv("GANDI_APIKEY"); len(apiKey) == 0 {
		return fmt.Errorf("GANDI_APIKEY is not set")
	}

	systemType := gandiClient.Production
	testing := os.Getenv("GANDI_TESTING")
	if len(testing) != 0 {
		logrus.Infof("GANDI_TESTING is set, using testing platform")
		systemType = gandiClient.Testing
	}

	client := gandiClient.New(apiKey, systemType)
	g.record = gandiRecord.New(client)
	g.zoneVersion = gandiZoneVersion.New(client)
	g.operation = gandiOperation.New(client)

	root := utils.UnFqdn(rootDomainName)
	split_root := strings.Split(root, ".")
	split_zoneDomain := split_root[len(split_root)-2 : len(split_root)]
	zoneDomain := strings.Join(split_zoneDomain, ".")

	domain := gandiDomain.New(client)
	domainInfo, err := domain.Info(zoneDomain)
	if err != nil {
		return fmt.Errorf("Failed to get zone ID for domain %s: %v", zoneDomain, err)
	}
	zoneId := domainInfo.ZoneId

	zone := gandiZone.New(client)
	zones, err := zone.List()
	if err != nil {
		return fmt.Errorf("Failed to list hosted zones: %v", err)
	}

	found := false
	for _, z := range zones {
		if z.Id == zoneId {
			g.root = root
			g.zone = z
			found = true
			break
		}
	}

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

	g.zoneDomain = zoneDomain
	g.zoneSuffix = fmt.Sprintf(".%s", zoneDomain)
	g.sub = strings.TrimSuffix(root, zoneDomain)
	g.zoneHandler = zone

	logrus.Infof("Configured %s for domain '%s' using zone '%s'", g.GetName(), root, g.zone.Name)
	return nil
}
Beispiel #6
0
func (c *CloudflareProvider) prepareRecord(record utils.DnsRecord) *api.Record {
	name := utils.UnFqdn(record.Fqdn)
	return &api.Record{
		Type:   record.Type,
		Name:   name,
		TTL:    sanitizeTTL(record.TTL),
		ZoneID: c.zone.ID,
	}
}
Beispiel #7
0
func (c *CloudflareProvider) findRecords(record utils.DnsRecord) ([]*api.Record, error) {
	var records []*api.Record
	result, err := c.client.Records.List(c.ctx, c.zone.ID)
	if err != nil {
		return records, fmt.Errorf("CloudFlare API call has failed: %v", err)
	}

	name := utils.UnFqdn(record.Fqdn)
	for _, rec := range result {
		if rec.Name == name && rec.Type == record.Type {
			records = append(records, rec)
		}
	}

	return records, nil
}
Beispiel #8
0
func (d *PdnsProvider) Init(rootDomainName string) error {
	var url, apiKey string
	if url = os.Getenv("POWERDNS_URL"); len(url) == 0 {
		return fmt.Errorf("POWERDNS_URL is not set")
	}

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

	d.root = utils.UnFqdn(rootDomainName)
	d.client = powerdns.New(url, "", d.root, apiKey)

	_, err := d.client.GetRecords()
	if err != nil {
		return fmt.Errorf("Failed to list records for '%s': %v", d.root, err)
	}

	logrus.Infof("Configured %s with zone '%s'", d.GetName(), d.root)
	return nil
}
Beispiel #9
0
// utils.DnsRecord.Fqdn has a trailing. | powerdns.Record.Name doesn't
func (d *PdnsProvider) parseName(record utils.DnsRecord) string {
	return utils.UnFqdn(record.Fqdn)
}