blob: 2ecd3ca184d2b2d65eca44255af43073eba9f579 [file] [log] [blame]
Ash Wilsonf4aee1e2014-10-03 15:25:13 -04001// +build acceptance
2
3package v2
4
5import (
6 "testing"
7
8 "github.com/rackspace/gophercloud"
9 "github.com/rackspace/gophercloud/openstack"
10 "github.com/rackspace/gophercloud/openstack/utils"
11 th "github.com/rackspace/gophercloud/testhelper"
12)
13
14func v2AuthOptions(t *testing.T) gophercloud.AuthOptions {
15 // Obtain credentials from the environment.
16 ao, err := utils.AuthOptions()
17 th.AssertNoErr(t, err)
18
19 // Trim out unused fields. Prefer authentication by API key to password.
20 ao.UserID, ao.DomainID, ao.DomainName = "", "", ""
21 if ao.APIKey != "" {
22 ao.Password = ""
23 }
24
25 return ao
26}
27
28func createClient(t *testing.T, auth bool) *gophercloud.ServiceClient {
29 ao := v2AuthOptions(t)
30
31 provider, err := openstack.NewClient(ao.IdentityEndpoint)
32 th.AssertNoErr(t, err)
33
34 if auth {
35 err = openstack.AuthenticateV2(provider, ao)
36 th.AssertNoErr(t, err)
37 }
38
39 return openstack.NewIdentityV2(provider)
40}
41
42func unauthenticatedClient(t *testing.T) *gophercloud.ServiceClient {
43 return createClient(t, false)
44}
45
46func authenticatedClient(t *testing.T) *gophercloud.ServiceClient {
47 return createClient(t, true)
48}