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

Commit 66803f0

Browse files
committed
Add identity admin client
1 parent 53c3b4c commit 66803f0

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)
@@ -197,6 +198,40 @@ func NewIdentityV3(client *gophercloud.ProviderClient) *gophercloud.ServiceClien
197198
}
198199
}
199200

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

0 commit comments

Comments
 (0)