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