Example #1
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
}
Example #2
0
func cloneLatestZone(c *client.Client, zId int64) (int64, error) {
	z := zone.New(c)
	zInfo, err := z.Info(zId)
	if err != nil {
		return 0, nil
	}

	zv := version.New(c)
	newVersion, err := zv.New(zId, zInfo.Version)
	if err != nil {
		return 0, nil
	}

	return newVersion, nil
}
Example #3
0
func New(testing bool) *Domain {
	// Load the gandi config file, which contains the api keys
	cfg := config.Load("")
	var c *client.Client
	if testing {
		c = client.New(cfg.ApiTestKey, client.Testing)
	} else {
		c = client.New(cfg.ApiProdKey, client.Production)
	}

	return &Domain{
		domain:  domain.New(c),
		zone:    zone.New(c),
		record:  record.New(c),
		version: version.New(c),
	}
}
Example #4
0
func main() {
	opts := &Options{}
	goptions.ParseAndFail(opts)

	// Print version number and exit if the version flag is set
	if opts.Version {
		fmt.Printf("gandi-domain-zone v%s\n", shared.VersionNumber)
		return
	}

	// Get gandi client
	client := shared.NewGandiClient(opts.ConfigPath, opts.Testing)

	// Create api and zone instances
	api := api.New(client)
	zone := cli.New(api)

	switch opts.Verbs {
	case "count":
		zone.Count()

	case "list":
		zone.List()

	case "info":
		zone.Info(opts.Info.Zone)

	case "create":
		zone.Create(opts.Create.Name)

	case "delete":
		zone.Delete(opts.Delete.Zone)

	case "set":
		zone.Set(opts.Set.Domain, opts.Set.Zone)

	default:
		goptions.PrintHelp()
	}
}
Example #5
0
func init() {
	gandiHandler := &GandiHandler{}

	apiKey := os.Getenv("GANDI_APIKEY")
	if len(apiKey) == 0 {
		logrus.Infof("GANDI_APIKEY is not set, skipping init of %s provider", gandiHandler.GetName())
		return
	}

	if err := RegisterProvider("gandi", gandiHandler); err != nil {
		logrus.Fatal("Could not register Gandi provider")
	}

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

	client := gandi.New(apiKey, systemType)
	gandiHandler.record = gandiRecord.New(client)
	gandiHandler.zoneVersion = gandiZoneVersion.New(client)

	root := strings.TrimSuffix(dns.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 {
		logrus.Fatalf("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 {
		logrus.Fatalf("Failed to list hosted zones: %v", err)
	}

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

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

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

	logrus.Infof("Configured %s for domain %s using hosted zone %q ", gandiHandler.GetName(), root, gandiHandler.zone.Name)
}