Exemple #1
0
// Authenticate creates a Rackspace-specific Gophercloud client.
func (c *Client) Authenticate(d *openstack.Driver) error {
	if c.Provider != nil {
		return nil
	}

	log.Debug("Authenticating to Rackspace.", map[string]string{
		"Username": d.Username,
	})

	apiKey := c.driver.APIKey
	opts := gophercloud.AuthOptions{
		Username: d.Username,
		APIKey:   apiKey,
	}

	provider, err := rackspace.NewClient(rackspace.RackspaceUSIdentity)
	if err != nil {
		return err
	}

	provider.UserAgent.Prepend(fmt.Sprintf("docker-machine/v%d", version.APIVersion))

	err = rackspace.Authenticate(provider, opts)
	if err != nil {
		return err
	}

	c.Provider = provider

	return nil
}
Exemple #2
0
func createClient(t *testing.T, auth bool) *gophercloud.ServiceClient {
	ao := rackspaceAuthOptions(t)

	provider, err := rackspace.NewClient(ao.IdentityEndpoint)
	th.AssertNoErr(t, err)

	if auth {
		err = rackspace.Authenticate(provider, ao)
		th.AssertNoErr(t, err)
	}

	return rackspace.NewIdentityV2(provider)
}
Exemple #3
0
// NewClient creates and returns a Rackspace client for the given service.
func NewClient(c *cli.Context, serviceType string) (*gophercloud.ServiceClient, error) {
	// get the user's authentication credentials
	ao, region, err := Credentials(c)
	if err != nil {
		return nil, err
	}

	if c.GlobalIsSet("no-cache") || c.IsSet("no-cache") {
		return authFromScratch(*ao, region, serviceType)
	}

	// form the cache key
	cacheKey := CacheKey(*ao, region, serviceType)
	// initialize cache
	cache := &Cache{}
	// get the value from the cache
	creds, err := cache.Value(cacheKey)
	// if there was an error accessing the cache or there was nothing in the cache,
	// authenticate from scratch
	if err == nil && creds != nil {
		// we successfully retrieved a value from the cache
		pc, err := rackspace.NewClient(ao.IdentityEndpoint)
		if err == nil {
			pc.TokenID = creds.TokenID
			pc.ReauthFunc = reauthFunc(pc, *ao)
			pc.UserAgent.Prepend(util.UserAgent)
			return &gophercloud.ServiceClient{
				ProviderClient: pc,
				Endpoint:       creds.ServiceEndpoint,
			}, nil
		}
	} else {
		return authFromScratch(*ao, region, serviceType)
	}

	return nil, nil
}
Exemple #4
0
func createClient(t *testing.T, cdn bool) (*gophercloud.ServiceClient, error) {
	region := os.Getenv("RS_REGION")
	if region == "" {
		t.Fatal("Please provide a Rackspace region as RS_REGION")
	}

	ao := rackspaceAuthOptions(t)

	provider, err := rackspace.NewClient(ao.IdentityEndpoint)
	th.AssertNoErr(t, err)

	err = rackspace.Authenticate(provider, ao)
	th.AssertNoErr(t, err)

	if cdn {
		return rackspace.NewObjectCDNV1(provider, gophercloud.EndpointOpts{
			Region: region,
		})
	}

	return rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{
		Region: region,
	})
}