Ejemplo n.º 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
}
Ejemplo n.º 2
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),
	}
}
Ejemplo n.º 3
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 v%s\n", shared.VersionNumber)
		return
	}

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

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

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

	case "list":
		domain.List()

	case "info":
		domain.Info(opts.Info.Domain)

	case "available":
		domain.Available(opts.Available.Domain)

	case "create":
		args := opts.Create
		domain.Create(args.Domain, args.Contact, args.Years)

	default:
		goptions.PrintHelp()
	}
}
Ejemplo n.º 4
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)
}