Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 6769c3b

Browse files
committed
Merge pull request #471 from feiskyer/keystone
[rfr] Add identity admin client
2 parents 89bdd4f + 66803f0 commit 6769c3b

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

openstack/client.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package openstack
33
import (
44
"fmt"
55
"net/url"
6+
"strings"
67

78
"github.com/rackspace/gophercloud"
89
tokens2 "github.com/rackspace/gophercloud/openstack/identity/v2/tokens"
@@ -64,8 +65,8 @@ func AuthenticatedClient(options gophercloud.AuthOptions) (*gophercloud.Provider
6465
// Authenticate or re-authenticate against the most recent identity service supported at the provided endpoint.
6566
func Authenticate(client *gophercloud.ProviderClient, options gophercloud.AuthOptions) error {
6667
versions := []*utils.Version{
67-
&utils.Version{ID: v20, Priority: 20, Suffix: "/v2.0/"},
68-
&utils.Version{ID: v30, Priority: 30, Suffix: "/v3/"},
68+
{ID: v20, Priority: 20, Suffix: "/v2.0/"},
69+
{ID: v30, Priority: 30, Suffix: "/v3/"},
6970
}
7071

7172
chosen, endpoint, err := utils.ChooseVersion(client, versions)
@@ -198,6 +199,40 @@ func NewIdentityV3(client *gophercloud.ProviderClient) *gophercloud.ServiceClien
198199
}
199200
}
200201

202+
func NewIdentityAdminV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
203+
eo.ApplyDefaults("identity")
204+
eo.Availability = gophercloud.AvailabilityAdmin
205+
206+
url, err := client.EndpointLocator(eo)
207+
if err != nil {
208+
return nil, err
209+
}
210+
211+
// Force using v2 API
212+
if strings.Contains(url, "/v3") {
213+
url = strings.Replace(url, "/v3", "/v2.0", -1)
214+
}
215+
216+
return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil
217+
}
218+
219+
func NewIdentityAdminV3(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
220+
eo.ApplyDefaults("identity")
221+
eo.Availability = gophercloud.AvailabilityAdmin
222+
223+
url, err := client.EndpointLocator(eo)
224+
if err != nil {
225+
return nil, err
226+
}
227+
228+
// Force using v3 API
229+
if strings.Contains(url, "/v2.0") {
230+
url = strings.Replace(url, "/v2.0", "/v3", -1)
231+
}
232+
233+
return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil
234+
}
235+
201236
// NewObjectStorageV1 creates a ServiceClient that may be used with the v1 object storage package.
202237
func NewObjectStorageV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
203238
eo.ApplyDefaults("object-store")

0 commit comments

Comments
 (0)