예제 #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
}
예제 #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)
}
예제 #3
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,
	})
}