| 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 | ed6a1d8 | 2014-09-03 12:01:00 -0400 | [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 | 11c9828 | 2014-09-08 16:05:10 -0400 | [diff] [blame] | 9 | identity2 "github.com/rackspace/gophercloud/openstack/identity/v2" | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 10 | endpoints3 "github.com/rackspace/gophercloud/openstack/identity/v3/endpoints" | 
|  | 11 | services3 "github.com/rackspace/gophercloud/openstack/identity/v3/services" | 
| Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 12 | tokens3 "github.com/rackspace/gophercloud/openstack/identity/v3/tokens" | 
| Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 13 | "github.com/rackspace/gophercloud/openstack/utils" | 
| Ash Wilson | 3c8cc77 | 2014-09-16 11:40:49 -0400 | [diff] [blame] | 14 | "github.com/rackspace/gophercloud/pagination" | 
| Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 15 | ) | 
|  | 16 |  | 
| Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 17 | const ( | 
|  | 18 | v20 = "v2.0" | 
|  | 19 | v30 = "v3.0" | 
|  | 20 | ) | 
| Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 21 |  | 
| Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 22 | // NewClient prepares an unauthenticated ProviderClient instance. | 
|  | 23 | // Most users will probably prefer using the AuthenticatedClient function instead. | 
|  | 24 | // This is useful if you wish to explicitly control the version of the identity service that's used for authentication explicitly, | 
|  | 25 | // for example. | 
|  | 26 | func NewClient(endpoint string) (*gophercloud.ProviderClient, error) { | 
| Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 27 | u, err := url.Parse(endpoint) | 
|  | 28 | if err != nil { | 
|  | 29 | return nil, err | 
|  | 30 | } | 
|  | 31 | hadPath := u.Path != "" | 
|  | 32 | u.Path, u.RawQuery, u.Fragment = "", "", "" | 
|  | 33 | base := u.String() | 
|  | 34 |  | 
| Ash Wilson | aca58d8 | 2014-09-10 17:00:35 -0400 | [diff] [blame] | 35 | endpoint = normalizeURL(endpoint) | 
|  | 36 | base = normalizeURL(base) | 
| Ash Wilson | e7da01c | 2014-09-09 12:31:06 -0400 | [diff] [blame] | 37 |  | 
| Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 38 | if hadPath { | 
|  | 39 | return &gophercloud.ProviderClient{ | 
|  | 40 | IdentityBase:     base, | 
|  | 41 | IdentityEndpoint: endpoint, | 
|  | 42 | }, nil | 
|  | 43 | } | 
|  | 44 |  | 
|  | 45 | return &gophercloud.ProviderClient{ | 
|  | 46 | IdentityBase:     base, | 
|  | 47 | IdentityEndpoint: "", | 
|  | 48 | }, nil | 
| Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 49 | } | 
|  | 50 |  | 
|  | 51 | // 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] | 52 | // returns a Client instance that's ready to operate. | 
| Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 53 | // It first queries the root identity endpoint to determine which versions of the identity service are supported, then chooses | 
|  | 54 | // the most recent identity service available to proceed. | 
| Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 55 | func AuthenticatedClient(options gophercloud.AuthOptions) (*gophercloud.ProviderClient, error) { | 
|  | 56 | client, err := NewClient(options.IdentityEndpoint) | 
|  | 57 | if err != nil { | 
|  | 58 | return nil, err | 
|  | 59 | } | 
|  | 60 |  | 
|  | 61 | err = Authenticate(client, options) | 
| Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 62 | if err != nil { | 
|  | 63 | return nil, err | 
|  | 64 | } | 
|  | 65 | return client, nil | 
|  | 66 | } | 
|  | 67 |  | 
| Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 68 | // 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] | 69 | func Authenticate(client *gophercloud.ProviderClient, options gophercloud.AuthOptions) error { | 
| Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 70 | versions := []*utils.Version{ | 
| Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 71 | &utils.Version{ID: v20, Priority: 20, Suffix: "/v2.0/"}, | 
|  | 72 | &utils.Version{ID: v30, Priority: 30, Suffix: "/v3/"}, | 
| Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 73 | } | 
|  | 74 |  | 
| Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 75 | chosen, endpoint, err := utils.ChooseVersion(client.IdentityBase, client.IdentityEndpoint, versions) | 
| Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 76 | if err != nil { | 
| Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 77 | return err | 
| Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 78 | } | 
|  | 79 |  | 
|  | 80 | switch chosen.ID { | 
|  | 81 | case v20: | 
| Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 82 | return v2auth(client, endpoint, options) | 
| Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 83 | case v30: | 
| Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 84 | return v3auth(client, endpoint, options) | 
| Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 85 | default: | 
| Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 86 | // The switch statement must be out of date from the versions list. | 
| Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 87 | return fmt.Errorf("Unrecognized identity version: %s", chosen.ID) | 
| Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 88 | } | 
|  | 89 | } | 
|  | 90 |  | 
| Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 91 | // AuthenticateV2 explicitly authenticates against the identity v2 endpoint. | 
|  | 92 | func AuthenticateV2(client *gophercloud.ProviderClient, options gophercloud.AuthOptions) error { | 
|  | 93 | return v2auth(client, "", options) | 
|  | 94 | } | 
|  | 95 |  | 
|  | 96 | func v2auth(client *gophercloud.ProviderClient, endpoint string, options gophercloud.AuthOptions) error { | 
|  | 97 | v2Client := NewIdentityV2(client) | 
|  | 98 | if endpoint != "" { | 
|  | 99 | v2Client.Endpoint = endpoint | 
|  | 100 | } | 
|  | 101 |  | 
|  | 102 | result, err := identity2.Authenticate(v2Client, options) | 
|  | 103 | if err != nil { | 
|  | 104 | return err | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | token, err := identity2.GetToken(result) | 
|  | 108 | if err != nil { | 
|  | 109 | return err | 
|  | 110 | } | 
|  | 111 |  | 
|  | 112 | client.TokenID = token.ID | 
|  | 113 | client.EndpointLocator = func(opts gophercloud.EndpointOpts) (string, error) { | 
|  | 114 | return v2endpointLocator(result, opts) | 
|  | 115 | } | 
|  | 116 |  | 
|  | 117 | return nil | 
|  | 118 | } | 
|  | 119 |  | 
| Ash Wilson | 9d9876b | 2014-09-09 09:28:00 -0400 | [diff] [blame] | 120 | func v2endpointLocator(authResults identity2.AuthResults, opts gophercloud.EndpointOpts) (string, error) { | 
|  | 121 | catalog, err := identity2.GetServiceCatalog(authResults) | 
|  | 122 | if err != nil { | 
|  | 123 | return "", err | 
|  | 124 | } | 
|  | 125 |  | 
|  | 126 | entries, err := catalog.CatalogEntries() | 
|  | 127 | if err != nil { | 
|  | 128 | return "", err | 
|  | 129 | } | 
|  | 130 |  | 
|  | 131 | // Extract Endpoints from the catalog entries that match the requested Type, Name if provided, and Region if provided. | 
| Ash Wilson | e7da01c | 2014-09-09 12:31:06 -0400 | [diff] [blame] | 132 | var endpoints = make([]identity2.Endpoint, 0, 1) | 
| Ash Wilson | 9d9876b | 2014-09-09 09:28:00 -0400 | [diff] [blame] | 133 | for _, entry := range entries { | 
| Ash Wilson | e7da01c | 2014-09-09 12:31:06 -0400 | [diff] [blame] | 134 | if (entry.Type == opts.Type) && (opts.Name == "" || entry.Name == opts.Name) { | 
| Ash Wilson | 9d9876b | 2014-09-09 09:28:00 -0400 | [diff] [blame] | 135 | for _, endpoint := range entry.Endpoints { | 
|  | 136 | if opts.Region == "" || endpoint.Region == opts.Region { | 
|  | 137 | endpoints = append(endpoints, endpoint) | 
|  | 138 | } | 
|  | 139 | } | 
|  | 140 | } | 
|  | 141 | } | 
|  | 142 |  | 
|  | 143 | // Report an error if the options were ambiguous. | 
|  | 144 | if len(endpoints) == 0 { | 
|  | 145 | return "", gophercloud.ErrEndpointNotFound | 
|  | 146 | } | 
|  | 147 | if len(endpoints) > 1 { | 
|  | 148 | return "", fmt.Errorf("Discovered %d matching endpoints: %#v", len(endpoints), endpoints) | 
|  | 149 | } | 
|  | 150 |  | 
|  | 151 | // Extract the appropriate URL from the matching Endpoint. | 
|  | 152 | for _, endpoint := range endpoints { | 
| Ash Wilson | efac18b | 2014-09-10 14:44:42 -0400 | [diff] [blame] | 153 | switch opts.Availability { | 
|  | 154 | case gophercloud.AvailabilityPublic: | 
| Ash Wilson | aca58d8 | 2014-09-10 17:00:35 -0400 | [diff] [blame] | 155 | return normalizeURL(endpoint.PublicURL), nil | 
| Ash Wilson | efac18b | 2014-09-10 14:44:42 -0400 | [diff] [blame] | 156 | case gophercloud.AvailabilityInternal: | 
| Ash Wilson | aca58d8 | 2014-09-10 17:00:35 -0400 | [diff] [blame] | 157 | return normalizeURL(endpoint.InternalURL), nil | 
| Ash Wilson | 9d9876b | 2014-09-09 09:28:00 -0400 | [diff] [blame] | 158 | default: | 
| Ash Wilson | efac18b | 2014-09-10 14:44:42 -0400 | [diff] [blame] | 159 | return "", fmt.Errorf("Unexpected availability in endpoint query: %s", opts.Availability) | 
| Ash Wilson | 9d9876b | 2014-09-09 09:28:00 -0400 | [diff] [blame] | 160 | } | 
|  | 161 | } | 
|  | 162 |  | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 163 | return "", gophercloud.ErrEndpointNotFound | 
|  | 164 | } | 
|  | 165 |  | 
| Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 166 | // AuthenticateV3 explicitly authenticates against the identity v3 service. | 
|  | 167 | func AuthenticateV3(client *gophercloud.ProviderClient, options gophercloud.AuthOptions) error { | 
|  | 168 | return v3auth(client, "", options) | 
|  | 169 | } | 
|  | 170 |  | 
|  | 171 | func v3auth(client *gophercloud.ProviderClient, endpoint string, options gophercloud.AuthOptions) error { | 
|  | 172 | // Override the generated service endpoint with the one returned by the version endpoint. | 
|  | 173 | v3Client := NewIdentityV3(client) | 
|  | 174 | if endpoint != "" { | 
|  | 175 | v3Client.Endpoint = endpoint | 
|  | 176 | } | 
|  | 177 |  | 
|  | 178 | result, err := tokens3.Create(v3Client, options, nil) | 
|  | 179 | if err != nil { | 
|  | 180 | return err | 
|  | 181 | } | 
|  | 182 |  | 
|  | 183 | client.TokenID, err = result.TokenID() | 
|  | 184 | if err != nil { | 
|  | 185 | return err | 
|  | 186 | } | 
|  | 187 | client.EndpointLocator = func(opts gophercloud.EndpointOpts) (string, error) { | 
|  | 188 | return v3endpointLocator(v3Client, opts) | 
|  | 189 | } | 
|  | 190 |  | 
|  | 191 | return nil | 
|  | 192 | } | 
|  | 193 |  | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 194 | func v3endpointLocator(v3Client *gophercloud.ServiceClient, opts gophercloud.EndpointOpts) (string, error) { | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 195 | // Discover the service we're interested in. | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 196 | var services = make([]services3.Service, 0, 1) | 
| Ash Wilson | 6b35e50 | 2014-09-12 15:15:23 -0400 | [diff] [blame] | 197 | servicePager := services3.List(v3Client, services3.ListOpts{ServiceType: opts.Type}) | 
| Ash Wilson | 3c8cc77 | 2014-09-16 11:40:49 -0400 | [diff] [blame] | 198 | err := servicePager.EachPage(func(page pagination.Page) (bool, error) { | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 199 | part, err := services3.ExtractServices(page) | 
|  | 200 | if err != nil { | 
| Ash Wilson | 6b35e50 | 2014-09-12 15:15:23 -0400 | [diff] [blame] | 201 | return false, err | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 202 | } | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 203 |  | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 204 | for _, service := range part { | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 205 | if service.Name == opts.Name { | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 206 | services = append(services, service) | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 207 | } | 
|  | 208 | } | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 209 |  | 
| Ash Wilson | 6b35e50 | 2014-09-12 15:15:23 -0400 | [diff] [blame] | 210 | return true, nil | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 211 | }) | 
|  | 212 | if err != nil { | 
|  | 213 | return "", err | 
|  | 214 | } | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 215 |  | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 216 | if len(services) == 0 { | 
|  | 217 | return "", gophercloud.ErrServiceNotFound | 
|  | 218 | } | 
|  | 219 | if len(services) > 1 { | 
|  | 220 | return "", fmt.Errorf("Discovered %d matching services: %#v", len(services), services) | 
|  | 221 | } | 
|  | 222 | service := services[0] | 
|  | 223 |  | 
|  | 224 | // Enumerate the endpoints available for this service. | 
|  | 225 | var endpoints []endpoints3.Endpoint | 
| Ash Wilson | 6b35e50 | 2014-09-12 15:15:23 -0400 | [diff] [blame] | 226 | endpointPager := endpoints3.List(v3Client, endpoints3.ListOpts{ | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 227 | Availability: opts.Availability, | 
|  | 228 | ServiceID:    service.ID, | 
| Ash Wilson | 6b35e50 | 2014-09-12 15:15:23 -0400 | [diff] [blame] | 229 | }) | 
| Ash Wilson | 3c8cc77 | 2014-09-16 11:40:49 -0400 | [diff] [blame] | 230 | err = endpointPager.EachPage(func(page pagination.Page) (bool, error) { | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 231 | part, err := endpoints3.ExtractEndpoints(page) | 
|  | 232 | if err != nil { | 
| Ash Wilson | 6b35e50 | 2014-09-12 15:15:23 -0400 | [diff] [blame] | 233 | return false, err | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 234 | } | 
|  | 235 |  | 
|  | 236 | for _, endpoint := range part { | 
| Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame] | 237 | if opts.Region == "" || endpoint.Region == opts.Region { | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 238 | endpoints = append(endpoints, endpoint) | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 239 | } | 
|  | 240 | } | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 241 |  | 
| Ash Wilson | 6b35e50 | 2014-09-12 15:15:23 -0400 | [diff] [blame] | 242 | return true, nil | 
| Ash Wilson | 566613e | 2014-09-12 14:51:46 -0400 | [diff] [blame] | 243 | }) | 
|  | 244 | if err != nil { | 
|  | 245 | return "", err | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 246 | } | 
|  | 247 |  | 
|  | 248 | if len(endpoints) == 0 { | 
|  | 249 | return "", gophercloud.ErrEndpointNotFound | 
|  | 250 | } | 
|  | 251 | if len(endpoints) > 1 { | 
|  | 252 | return "", fmt.Errorf("Discovered %d matching endpoints: %#v", len(endpoints), endpoints) | 
|  | 253 | } | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 254 | endpoint := endpoints[0] | 
|  | 255 |  | 
| Ash Wilson | aca58d8 | 2014-09-10 17:00:35 -0400 | [diff] [blame] | 256 | return normalizeURL(endpoint.URL), nil | 
|  | 257 | } | 
|  | 258 |  | 
|  | 259 | // normalizeURL ensures that each endpoint URL has a closing `/`, as expected by ServiceClient. | 
|  | 260 | func normalizeURL(url string) string { | 
|  | 261 | if !strings.HasSuffix(url, "/") { | 
|  | 262 | return url + "/" | 
|  | 263 | } | 
|  | 264 | return url | 
| Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 265 | } | 
|  | 266 |  | 
| Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 267 | // NewIdentityV2 creates a ServiceClient that may be used to interact with the v2 identity service. | 
|  | 268 | func NewIdentityV2(client *gophercloud.ProviderClient) *gophercloud.ServiceClient { | 
| Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 269 | v2Endpoint := client.IdentityBase + "v2.0/" | 
| Ash Wilson | ccd020b | 2014-09-02 10:40:54 -0400 | [diff] [blame] | 270 |  | 
| Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 271 | return &gophercloud.ServiceClient{ | 
|  | 272 | Provider: client, | 
|  | 273 | Endpoint: v2Endpoint, | 
| Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame] | 274 | } | 
| Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 275 | } | 
|  | 276 |  | 
| Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 277 | // NewIdentityV3 creates a ServiceClient that may be used to access the v3 identity service. | 
|  | 278 | func NewIdentityV3(client *gophercloud.ProviderClient) *gophercloud.ServiceClient { | 
| Ash Wilson | 09694b9 | 2014-09-09 14:08:27 -0400 | [diff] [blame] | 279 | v3Endpoint := client.IdentityBase + "v3/" | 
| Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame] | 280 |  | 
|  | 281 | return &gophercloud.ServiceClient{ | 
|  | 282 | Provider: client, | 
|  | 283 | Endpoint: v3Endpoint, | 
|  | 284 | } | 
| Ash Wilson | 8ba8224 | 2014-08-28 15:38:55 -0400 | [diff] [blame] | 285 | } | 
| Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame] | 286 |  | 
|  | 287 | // NewStorageV1 creates a ServiceClient that may be used with the v1 object storage package. | 
| Jon Perritt | 509fbb6 | 2014-09-10 13:29:56 -0500 | [diff] [blame] | 288 | func NewStorageV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { | 
|  | 289 | eo.ApplyDefaults("object-store") | 
|  | 290 | url, err := client.EndpointLocator(eo) | 
| Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame] | 291 | if err != nil { | 
|  | 292 | return nil, err | 
|  | 293 | } | 
|  | 294 | return &gophercloud.ServiceClient{Provider: client, Endpoint: url}, nil | 
|  | 295 | } | 
| Ash Wilson | 5e57c1b | 2014-09-17 09:24:46 -0400 | [diff] [blame] | 296 |  | 
|  | 297 | // NewComputeV2 creates a ServiceClient that may be used with the v2 compute package. | 
|  | 298 | func NewComputeV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { | 
|  | 299 | eo.ApplyDefaults("compute") | 
|  | 300 | url, err := client.EndpointLocator(eo) | 
|  | 301 | if err != nil { | 
|  | 302 | return nil, err | 
|  | 303 | } | 
|  | 304 | return &gophercloud.ServiceClient{Provider: client, Endpoint: url}, nil | 
|  | 305 | } |