Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 1 | package openstack |
| 2 | |
| 3 | import ( |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 4 | "fmt" |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 5 | "net/url" |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 6 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 7 | "github.com/gophercloud/gophercloud" |
| 8 | tokens2 "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens" |
| 9 | tokens3 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" |
| 10 | "github.com/gophercloud/gophercloud/openstack/utils" |
Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 11 | ) |
| 12 | |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 13 | const ( |
| 14 | v20 = "v2.0" |
| 15 | v30 = "v3.0" |
| 16 | ) |
Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 17 | |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 18 | // NewClient prepares an unauthenticated ProviderClient instance. |
| 19 | // Most users will probably prefer using the AuthenticatedClient function instead. |
| 20 | // This is useful if you wish to explicitly control the version of the identity service that's used for authentication explicitly, |
| 21 | // for example. |
| 22 | func NewClient(endpoint string) (*gophercloud.ProviderClient, error) { |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 23 | u, err := url.Parse(endpoint) |
| 24 | if err != nil { |
| 25 | return nil, err |
| 26 | } |
| 27 | hadPath := u.Path != "" |
| 28 | u.Path, u.RawQuery, u.Fragment = "", "", "" |
| 29 | base := u.String() |
| 30 | |
Ash Wilson | a844064 | 2014-10-07 09:55:58 -0400 | [diff] [blame] | 31 | endpoint = gophercloud.NormalizeURL(endpoint) |
| 32 | base = gophercloud.NormalizeURL(base) |
Ash Wilson | e7da01c | 2014-09-09 12:31:06 -0400 | [diff] [blame] | 33 | |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 34 | if hadPath { |
| 35 | return &gophercloud.ProviderClient{ |
| 36 | IdentityBase: base, |
| 37 | IdentityEndpoint: endpoint, |
| 38 | }, nil |
| 39 | } |
| 40 | |
| 41 | return &gophercloud.ProviderClient{ |
| 42 | IdentityBase: base, |
| 43 | IdentityEndpoint: "", |
| 44 | }, nil |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | // AuthenticatedClient logs in to an OpenStack cloud found at the identity endpoint specified by options, acquires a token, and |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 48 | // returns a Client instance that's ready to operate. |
Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 49 | // It first queries the root identity endpoint to determine which versions of the identity service are supported, then chooses |
| 50 | // the most recent identity service available to proceed. |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 51 | func AuthenticatedClient(options gophercloud.AuthOptions) (*gophercloud.ProviderClient, error) { |
| 52 | client, err := NewClient(options.IdentityEndpoint) |
| 53 | if err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | |
| 57 | err = Authenticate(client, options) |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 58 | if err != nil { |
| 59 | return nil, err |
| 60 | } |
| 61 | return client, nil |
| 62 | } |
| 63 | |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 64 | // Authenticate or re-authenticate against the most recent identity service supported at the provided endpoint. |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 65 | func Authenticate(client *gophercloud.ProviderClient, options gophercloud.AuthOptions) error { |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 66 | versions := []*utils.Version{ |
feisky | 66803f0 | 2015-08-28 22:06:34 +0800 | [diff] [blame] | 67 | {ID: v20, Priority: 20, Suffix: "/v2.0/"}, |
| 68 | {ID: v30, Priority: 30, Suffix: "/v3/"}, |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 69 | } |
| 70 | |
Ash Wilson | 2491b4c | 2015-02-12 16:13:39 -0500 | [diff] [blame] | 71 | chosen, endpoint, err := utils.ChooseVersion(client, versions) |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 72 | if err != nil { |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 73 | return err |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | switch chosen.ID { |
| 77 | case v20: |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 78 | return v2auth(client, endpoint, options, gophercloud.EndpointOpts{}) |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 79 | case v30: |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 80 | return v3auth(client, endpoint, options, gophercloud.EndpointOpts{}) |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 81 | default: |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 82 | // The switch statement must be out of date from the versions list. |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 83 | return fmt.Errorf("Unrecognized identity version: %s", chosen.ID) |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 87 | // AuthenticateV2 explicitly authenticates against the identity v2 endpoint. |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 88 | func AuthenticateV2(client *gophercloud.ProviderClient, options gophercloud.AuthOptions, eo gophercloud.EndpointOpts) error { |
| 89 | return v2auth(client, "", options, eo) |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 92 | func v2auth(client *gophercloud.ProviderClient, endpoint string, options gophercloud.AuthOptions, eo gophercloud.EndpointOpts) error { |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 93 | v2Client, err := NewIdentityV2(client, eo) |
| 94 | if err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 98 | if endpoint != "" { |
| 99 | v2Client.Endpoint = endpoint |
| 100 | } |
| 101 | |
jrperritt | 64d0ef0 | 2016-04-13 13:10:04 -0500 | [diff] [blame] | 102 | v2Opts := tokens2.AuthOptions{ |
| 103 | IdentityEndpoint: options.IdentityEndpoint, |
| 104 | Username: options.Username, |
| 105 | Password: options.Password, |
| 106 | TenantID: options.TenantID, |
| 107 | TenantName: options.TenantName, |
| 108 | AllowReauth: options.AllowReauth, |
| 109 | TokenID: options.TokenID, |
| 110 | } |
| 111 | |
| 112 | result := tokens2.Create(v2Client, v2Opts) |
Ash Wilson | 52fbd18 | 2014-10-03 13:48:06 -0400 | [diff] [blame] | 113 | |
| 114 | token, err := result.ExtractToken() |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 115 | if err != nil { |
| 116 | return err |
| 117 | } |
| 118 | |
Ash Wilson | 52fbd18 | 2014-10-03 13:48:06 -0400 | [diff] [blame] | 119 | catalog, err := result.ExtractServiceCatalog() |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | |
Jon Perritt | f4052c6 | 2015-02-14 09:48:18 -0700 | [diff] [blame] | 124 | if options.AllowReauth { |
Jon Perritt | 6fe7c40 | 2015-02-17 12:24:53 -0700 | [diff] [blame] | 125 | client.ReauthFunc = func() error { |
Masahiro Sano | 1b2bafe | 2015-03-06 23:26:54 +0900 | [diff] [blame] | 126 | client.TokenID = "" |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 127 | return v2auth(client, endpoint, options, eo) |
Jon Perritt | 6fe7c40 | 2015-02-17 12:24:53 -0700 | [diff] [blame] | 128 | } |
Jon Perritt | f4052c6 | 2015-02-14 09:48:18 -0700 | [diff] [blame] | 129 | } |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 130 | client.TokenID = token.ID |
Ash Wilson | 130a6e2 | 2014-10-07 10:48:17 -0400 | [diff] [blame] | 131 | client.EndpointLocator = func(opts gophercloud.EndpointOpts) (string, error) { |
| 132 | return V2EndpointURL(catalog, opts) |
| 133 | } |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 134 | |
| 135 | return nil |
| 136 | } |
| 137 | |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 138 | // AuthenticateV3 explicitly authenticates against the identity v3 service. |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 139 | func AuthenticateV3(client *gophercloud.ProviderClient, options gophercloud.AuthOptions, eo gophercloud.EndpointOpts) error { |
| 140 | return v3auth(client, "", options, eo) |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 143 | func v3auth(client *gophercloud.ProviderClient, endpoint string, options gophercloud.AuthOptions, eo gophercloud.EndpointOpts) error { |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 144 | // Override the generated service endpoint with the one returned by the version endpoint. |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 145 | v3Client, err := NewIdentityV3(client, eo) |
| 146 | if err != nil { |
| 147 | return err |
| 148 | } |
| 149 | |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 150 | if endpoint != "" { |
| 151 | v3Client.Endpoint = endpoint |
| 152 | } |
| 153 | |
jrperritt | 69cc337 | 2016-04-06 13:51:52 -0500 | [diff] [blame] | 154 | // copy the auth options to a local variable that we can change. `options` |
| 155 | // needs to stay as-is for reauth purposes |
| 156 | v3Options := options |
| 157 | |
Guillaume Giamarchi | 08b33d5 | 2015-04-01 01:34:17 +0200 | [diff] [blame] | 158 | var scope *tokens3.Scope |
| 159 | if options.TenantID != "" { |
| 160 | scope = &tokens3.Scope{ |
| 161 | ProjectID: options.TenantID, |
| 162 | } |
jrperritt | 69cc337 | 2016-04-06 13:51:52 -0500 | [diff] [blame] | 163 | v3Options.TenantID = "" |
| 164 | v3Options.TenantName = "" |
Guillaume Giamarchi | 08b33d5 | 2015-04-01 01:34:17 +0200 | [diff] [blame] | 165 | } else { |
| 166 | if options.TenantName != "" { |
| 167 | scope = &tokens3.Scope{ |
| 168 | ProjectName: options.TenantName, |
| 169 | DomainID: options.DomainID, |
| 170 | DomainName: options.DomainName, |
| 171 | } |
jrperritt | 69cc337 | 2016-04-06 13:51:52 -0500 | [diff] [blame] | 172 | v3Options.TenantName = "" |
Guillaume Giamarchi | 08b33d5 | 2015-04-01 01:34:17 +0200 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 176 | v3Opts := tokens3.AuthOptions{ |
| 177 | IdentityEndpoint: options.IdentityEndpoint, |
| 178 | Username: options.Username, |
| 179 | UserID: options.UserID, |
| 180 | Password: options.Password, |
| 181 | DomainID: options.DomainID, |
| 182 | DomainName: options.DomainName, |
| 183 | TenantID: options.TenantID, |
| 184 | TenantName: options.TenantName, |
| 185 | AllowReauth: options.AllowReauth, |
| 186 | TokenID: options.TokenID, |
| 187 | } |
| 188 | |
| 189 | result := tokens3.Create(v3Client, v3Opts, scope) |
Guillaume Giamarchi | b2663b2 | 2015-04-01 01:23:29 +0200 | [diff] [blame] | 190 | |
| 191 | token, err := result.ExtractToken() |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 192 | if err != nil { |
| 193 | return err |
| 194 | } |
Guillaume Giamarchi | b2663b2 | 2015-04-01 01:23:29 +0200 | [diff] [blame] | 195 | |
| 196 | catalog, err := result.ExtractServiceCatalog() |
| 197 | if err != nil { |
| 198 | return err |
| 199 | } |
| 200 | |
Ash Wilson | 63b2a29 | 2014-10-02 09:29:06 -0400 | [diff] [blame] | 201 | client.TokenID = token.ID |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 202 | |
Jon Perritt | f4052c6 | 2015-02-14 09:48:18 -0700 | [diff] [blame] | 203 | if options.AllowReauth { |
Jon Perritt | 6fe7c40 | 2015-02-17 12:24:53 -0700 | [diff] [blame] | 204 | client.ReauthFunc = func() error { |
hzlouchao | f6e2926 | 2015-10-27 12:51:08 +0800 | [diff] [blame] | 205 | client.TokenID = "" |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 206 | return v3auth(client, endpoint, options, eo) |
Jon Perritt | 6fe7c40 | 2015-02-17 12:24:53 -0700 | [diff] [blame] | 207 | } |
Jon Perritt | f4052c6 | 2015-02-14 09:48:18 -0700 | [diff] [blame] | 208 | } |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 209 | client.EndpointLocator = func(opts gophercloud.EndpointOpts) (string, error) { |
Guillaume Giamarchi | b2663b2 | 2015-04-01 01:23:29 +0200 | [diff] [blame] | 210 | return V3EndpointURL(catalog, opts) |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | return nil |
| 214 | } |
| 215 | |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 216 | // NewIdentityV2 creates a ServiceClient that may be used to interact with the v2 identity service. |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 217 | func NewIdentityV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 218 | v2Endpoint := client.IdentityBase + "v2.0/" |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 219 | /* |
| 220 | eo.ApplyDefaults("identity") |
| 221 | url, err := client.EndpointLocator(eo) |
| 222 | if err != nil { |
| 223 | return nil, err |
| 224 | } |
| 225 | */ |
Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 226 | |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 227 | return &gophercloud.ServiceClient{ |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 228 | ProviderClient: client, |
| 229 | Endpoint: v2Endpoint, |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 230 | //Endpoint: url, |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 231 | }, nil |
Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 232 | } |
| 233 | |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 234 | // NewIdentityV3 creates a ServiceClient that may be used to access the v3 identity service. |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 235 | func NewIdentityV3(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 236 | v3Endpoint := client.IdentityBase + "v3/" |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 237 | /* |
| 238 | eo.ApplyDefaults("identity") |
| 239 | url, err := client.EndpointLocator(eo) |
| 240 | if err != nil { |
| 241 | return nil, err |
| 242 | } |
| 243 | */ |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 244 | |
| 245 | return &gophercloud.ServiceClient{ |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 246 | ProviderClient: client, |
| 247 | Endpoint: v3Endpoint, |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 248 | //Endpoint: url, |
Jon Perritt | 376dfce | 2016-02-28 23:39:09 -0600 | [diff] [blame] | 249 | }, nil |
feisky | 66803f0 | 2015-08-28 22:06:34 +0800 | [diff] [blame] | 250 | } |
| 251 | |
Jon Perritt | bb5e981 | 2014-10-15 17:53:44 -0500 | [diff] [blame] | 252 | // NewObjectStorageV1 creates a ServiceClient that may be used with the v1 object storage package. |
| 253 | func NewObjectStorageV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
Jon Perritt | 509fbb6 | 2014-09-10 13:29:56 -0500 | [diff] [blame] | 254 | eo.ApplyDefaults("object-store") |
| 255 | url, err := client.EndpointLocator(eo) |
Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame] | 256 | if err != nil { |
| 257 | return nil, err |
| 258 | } |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 259 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame] | 260 | } |
Ash Wilson | 5e57c1b | 2014-09-17 09:24:46 -0400 | [diff] [blame] | 261 | |
| 262 | // NewComputeV2 creates a ServiceClient that may be used with the v2 compute package. |
| 263 | func NewComputeV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 264 | eo.ApplyDefaults("compute") |
| 265 | url, err := client.EndpointLocator(eo) |
| 266 | if err != nil { |
| 267 | return nil, err |
| 268 | } |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 269 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
Ash Wilson | 5e57c1b | 2014-09-17 09:24:46 -0400 | [diff] [blame] | 270 | } |
Ash Wilson | ebc3d12 | 2014-09-24 13:44:05 -0400 | [diff] [blame] | 271 | |
| 272 | // NewNetworkV2 creates a ServiceClient that may be used with the v2 network package. |
Jamie Hannaford | 7ea2958 | 2014-09-11 15:49:46 +0200 | [diff] [blame] | 273 | func NewNetworkV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 274 | eo.ApplyDefaults("network") |
| 275 | url, err := client.EndpointLocator(eo) |
| 276 | if err != nil { |
| 277 | return nil, err |
| 278 | } |
Ash Wilson | 99541ab | 2014-10-06 17:32:39 -0400 | [diff] [blame] | 279 | return &gophercloud.ServiceClient{ |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 280 | ProviderClient: client, |
| 281 | Endpoint: url, |
| 282 | ResourceBase: url + "v2.0/", |
Ash Wilson | 99541ab | 2014-10-06 17:32:39 -0400 | [diff] [blame] | 283 | }, nil |
Jamie Hannaford | 7ea2958 | 2014-09-11 15:49:46 +0200 | [diff] [blame] | 284 | } |
Jon Perritt | c5ee85e | 2014-09-17 00:53:19 -0500 | [diff] [blame] | 285 | |
| 286 | // NewBlockStorageV1 creates a ServiceClient that may be used to access the v1 block storage service. |
| 287 | func NewBlockStorageV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 288 | eo.ApplyDefaults("volume") |
| 289 | url, err := client.EndpointLocator(eo) |
| 290 | if err != nil { |
| 291 | return nil, err |
| 292 | } |
Ash Wilson | 92c380c | 2014-10-22 09:14:53 -0400 | [diff] [blame] | 293 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
Jon Perritt | c5ee85e | 2014-09-17 00:53:19 -0500 | [diff] [blame] | 294 | } |
Jon Perritt | ebd18ec | 2015-01-16 09:13:31 -0700 | [diff] [blame] | 295 | |
| 296 | // NewCDNV1 creates a ServiceClient that may be used to access the OpenStack v1 |
| 297 | // CDN service. |
| 298 | func NewCDNV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 299 | eo.ApplyDefaults("cdn") |
| 300 | url, err := client.EndpointLocator(eo) |
| 301 | if err != nil { |
| 302 | return nil, err |
| 303 | } |
| 304 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
| 305 | } |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 306 | |
| 307 | // NewOrchestrationV1 creates a ServiceClient that may be used to access the v1 orchestration service. |
| 308 | func NewOrchestrationV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 309 | eo.ApplyDefaults("orchestration") |
| 310 | url, err := client.EndpointLocator(eo) |
| 311 | if err != nil { |
| 312 | return nil, err |
| 313 | } |
| 314 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
| 315 | } |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 316 | |
Jamie Hannaford | 75e8cc4 | 2015-11-16 14:09:25 +0100 | [diff] [blame] | 317 | // NewDBV1 creates a ServiceClient that may be used to access the v1 DB service. |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 318 | func NewDBV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { |
| 319 | eo.ApplyDefaults("database") |
| 320 | url, err := client.EndpointLocator(eo) |
| 321 | if err != nil { |
| 322 | return nil, err |
| 323 | } |
| 324 | return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil |
| 325 | } |