func TestAuthenticatedClient(t *testing.T) { // Obtain credentials from the environment. ao, err := openstack.AuthOptionsFromEnv() if err != nil { t.Fatalf("Unable to acquire credentials: %v", err) } client, err := openstack.AuthenticatedClient(ao) if err != nil { t.Fatalf("Unable to authenticate: %v", err) } if client.TokenID == "" { t.Errorf("No token ID assigned to the client") } t.Logf("Client successfully acquired a token: %v", client.TokenID) // Find the storage service in the service catalog. storage, err := openstack.NewObjectStorageV1(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) if err != nil { t.Errorf("Unable to locate a storage service: %v", err) } else { t.Logf("Located a storage service at endpoint: [%s]", storage.Endpoint) } }
func newClient(t *testing.T) *gophercloud.ServiceClient { ao, err := openstack.AuthOptionsFromEnv() th.AssertNoErr(t, err) client, err := openstack.AuthenticatedClient(ao) th.AssertNoErr(t, err) c, err := openstack.NewObjectStorageV1(client, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) th.AssertNoErr(t, err) return c }
func NewObjectStorageClient(a gophercloud.AuthOptions, region string) (*gophercloud.ServiceClient, error) { // authenticate with provider provider, err := openstack.AuthenticatedClient(a) if err != nil { return nil, err } // Create a new client to the provider client, err := openstack.NewObjectStorageV1(provider, gophercloud.EndpointOpts{ Region: region, }) if err != nil { return nil, err } return client, nil }
func (s *Swift) Auth() error { if s.authOptions.Username != "" { log.Debugf("(OpenStack) Authenticate by username(%s)", s.authOptions.Username) } else if s.authOptions.UserID != "" { log.Debugf("(OpenStack) Authenticate by user-id(%s)", s.authOptions.UserID) } else { log.Debugf("(OpenStack) Authenticate") } provider, err := openstack.AuthenticatedClient(s.authOptions) if err != nil { return err } s.client, err = openstack.NewObjectStorageV1(provider, s.endpointOptions) if err != nil { return err } return nil }
func (c *SwiftClient) validateConfig(conf map[string]string) (err error) { if val := os.Getenv("OS_AUTH_URL"); val == "" { return fmt.Errorf("missing OS_AUTH_URL environment variable") } if val := os.Getenv("OS_USERNAME"); val == "" { return fmt.Errorf("missing OS_USERNAME environment variable") } if val := os.Getenv("OS_TENANT_NAME"); val == "" { return fmt.Errorf("missing OS_TENANT_NAME environment variable") } if val := os.Getenv("OS_PASSWORD"); val == "" { return fmt.Errorf("missing OS_PASSWORD environment variable") } path, ok := conf["path"] if !ok || path == "" { return fmt.Errorf("missing 'path' configuration") } provider, err := openstack.AuthenticatedClient(gophercloud.AuthOptions{ IdentityEndpoint: os.Getenv("OS_AUTH_URL"), Username: os.Getenv("OS_USERNAME"), TenantName: os.Getenv("OS_TENANT_NAME"), Password: os.Getenv("OS_PASSWORD"), }) if err != nil { return err } c.path = path c.client, err = openstack.NewObjectStorageV1(provider, gophercloud.EndpointOpts{ Region: os.Getenv("OS_REGION_NAME"), }) return err }
func (c *Config) objectStorageV1Client(region string) (*gophercloud.ServiceClient, error) { return openstack.NewObjectStorageV1(c.osClient, gophercloud.EndpointOpts{ Region: region, Availability: c.getEndpointType(), }) }
// NewObjectStorageV1 creates a ServiceClient that may be used with the Rackspace v1 object storage package. func NewObjectStorageV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { return os.NewObjectStorageV1(client, eo) }