Use v2 identity in AuthenticatedClient.
diff --git a/openstack/client.go b/openstack/client.go
index cbfde10..aef7e71 100644
--- a/openstack/client.go
+++ b/openstack/client.go
@@ -7,6 +7,7 @@
"strings"
"github.com/rackspace/gophercloud"
+ identity2 "github.com/rackspace/gophercloud/openstack/identity/v2"
tokens3 "github.com/rackspace/gophercloud/openstack/identity/v3/tokens"
"github.com/rackspace/gophercloud/openstack/utils"
)
@@ -72,7 +73,22 @@
switch chosen.ID {
case v20:
- return errors.New("Not implemented yet.")
+ v2Client := NewIdentityV2(client)
+ v2Client.Endpoint = endpoint
+ fmt.Printf("Endpoint is: %s\n", endpoint)
+
+ result, err := identity2.Authenticate(v2Client, options)
+ if err != nil {
+ return err
+ }
+
+ token, err := identity2.GetToken(result)
+ if err != nil {
+ return err
+ }
+ client.TokenID = token.ID
+
+ return nil
case v30:
// Override the generated service endpoint with the one returned by the version endpoint.
v3Client := NewIdentityV3(client)
diff --git a/openstack/client_test.go b/openstack/client_test.go
index b8f910e..dd39e77 100644
--- a/openstack/client_test.go
+++ b/openstack/client_test.go
@@ -92,7 +92,7 @@
`, testhelper.Endpoint()+"v3/", testhelper.Endpoint()+"v2.0/")
})
- testhelper.Mux.HandleFunc("/v2/auth/tokens", func(w http.ResponseWriter, r *http.Request) {
+ testhelper.Mux.HandleFunc("/v2.0/tokens", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `
{
@@ -157,7 +157,7 @@
})
options := gophercloud.AuthOptions{
- UserID: "me",
+ Username: "me",
Password: "secret",
IdentityEndpoint: testhelper.Endpoint(),
}
diff --git a/openstack/identity/v2/requests.go b/openstack/identity/v2/requests.go
index 696ee4d..bb068b6 100644
--- a/openstack/identity/v2/requests.go
+++ b/openstack/identity/v2/requests.go
@@ -30,7 +30,7 @@
return nil, ErrCredentials
}
- url := c.Endpoint + "/tokens"
+ url := c.Endpoint + "tokens"
err := perigee.Post(url, perigee.Options{
ReqBody: &AuthContainer{
Auth: getAuthCredentials(options),
@@ -78,7 +78,7 @@
func GetExtensions(c *gophercloud.ServiceClient, options gophercloud.AuthOptions) (ExtensionsResult, error) {
var exts ExtensionsResult
- url := c.Endpoint + "/extensions"
+ url := c.Endpoint + "extensions"
err := perigee.Get(url, perigee.Options{
Results: &exts,
})