@@ -3,6 +3,7 @@ package openstack
33import (
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.
6566func 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 )
@@ -110,7 +111,7 @@ func v2auth(client *gophercloud.ProviderClient, endpoint string, options gopherc
110111 if options .AllowReauth {
111112 client .ReauthFunc = func () error {
112113 client .TokenID = ""
113- return AuthenticateV2 (client , options )
114+ return v2auth (client , endpoint , options )
114115 }
115116 }
116117 client .TokenID = token .ID
@@ -168,7 +169,7 @@ func v3auth(client *gophercloud.ProviderClient, endpoint string, options gopherc
168169 if options .AllowReauth {
169170 client .ReauthFunc = func () error {
170171 client .TokenID = ""
171- return AuthenticateV3 (client , options )
172+ return v3auth (client , endpoint , options )
172173 }
173174 }
174175 client .EndpointLocator = func (opts gophercloud.EndpointOpts ) (string , error ) {
@@ -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.
202237func NewObjectStorageV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
203238 eo .ApplyDefaults ("object-store" )
0 commit comments