コード例 #1
0
ファイル: client.go プロジェクト: philips/coreup
func FromName(provider, project, region, cachePath string) (Client, error) {
	switch provider {
	case "ec2":
		return ec2.GetClient(project, region, cachePath)
	case "rackspace":
		return rackspace.GetClient(project, region, cachePath)
	case "google":
		return gce.GetClient(project, region, cachePath)
	}
	return nil, errors.New("Unable to find provider")
}
コード例 #2
0
ファイル: ec2.go プロジェクト: polvi/coreup
func GetClient(project string, region string, cache_path string) (Client, error) {
	// this will cause the google cache to be populated
	gce.GetClient(project, region, cache_path)
	c := Client{}
	cache, err := config.LoadCredCache(cache_path)
	if err != nil {
		return c, err
	}
	c.cache = cache
	if region == "" {
		region = defaultRegion
	}
	c.region = region
	if cache.AWS.RoleARN == "" {
		var arn string
		fmt.Printf("amazon role arn: ")
		_, err = fmt.Scanf("%s", &arn)
		if err != nil {
			return c, err
		}
		c.cache.AWS.RoleARN = strings.TrimSpace(arn)
		c.cache.Save()
	}
	if c.cache.AWS.Token.Expiry.Before(time.Now()) {
		auth, err := authAWSFromToken(&c.cache.GCE.Token, c.cache.AWS.RoleARN)
		if err != nil {
			return c, err
		}
		c.cache.AWS.Token = *auth
		c.cache.Save()
	}
	if _, ok := aws.Regions[c.region]; !ok {
		return c, errors.New("could not find region " + c.region)
	}
	c.client = ec2.New(c.cache.AWS.Token.Auth, aws.Regions[c.region])
	return c, nil
}