Exemplo n.º 1
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-operation v%s\n", shared.VersionNumber)
		return
	}

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

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

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

	case "list":
		operation.List()

	case "info":
		operation.Info(opts.Info.Operation)

	case "cancel":
		operation.Cancel(opts.Cancel.Operation)

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