Merge pull request #184 from jrperritt/v0.2.0
move 'NewClient' to function
diff --git a/acceptance/openstack/storage_test.go b/acceptance/openstack/storage_test.go
index bd12a33..1cb3bad 100644
--- a/acceptance/openstack/storage_test.go
+++ b/acceptance/openstack/storage_test.go
@@ -5,7 +5,6 @@
import (
"bytes"
"github.com/rackspace/gophercloud/acceptance/tools"
- identity "github.com/rackspace/gophercloud/openstack/identity/v2"
storage "github.com/rackspace/gophercloud/openstack/storage/v1"
"github.com/rackspace/gophercloud/openstack/storage/v1/accounts"
"github.com/rackspace/gophercloud/openstack/storage/v1/containers"
@@ -26,7 +25,7 @@
return nil, err
}
- client, err := ao.NewClient(identity.EndpointOpts{
+ client, err := utils.NewClient(ao, utils.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
Type: "object-store",
})
diff --git a/openstack/identity/v2/client.go b/openstack/utils/client.go
similarity index 77%
rename from openstack/identity/v2/client.go
rename to openstack/utils/client.go
index c2b344b..d1f0359 100644
--- a/openstack/identity/v2/client.go
+++ b/openstack/utils/client.go
@@ -1,7 +1,8 @@
-package identity
+package utils
import (
"fmt"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
)
// Client contains information that defines a generic Openstack Client.
@@ -9,9 +10,9 @@
// Endpoint is the URL against which to authenticate.
Endpoint string
// Authority holds the results of authenticating against the Endpoint.
- Authority AuthResults
+ Authority identity.AuthResults
// Options holds the authentication options. Useful for auto-reauthentication.
- Options AuthOptions
+ Options identity.AuthOptions
}
// EndpointOpts contains options for finding an endpoint for an Openstack Client.
@@ -34,24 +35,24 @@
// to create a client for the various Openstack services.
// Example (error checking omitted for brevity):
// ao, err := utils.AuthOptions()
-// c, err := ao.NewClient(identity.EndpointOpts{
+// c, err := identity.NewClient(ao, identity.EndpointOpts{
// Type: "compute",
// Name: "nova",
// })
// serversClient := servers.NewClient(c.Endpoint, c.Authority, c.Options)
-func (ao AuthOptions) NewClient(opts EndpointOpts) (Client, error) {
+func NewClient(ao identity.AuthOptions, eo EndpointOpts) (Client, error) {
client := Client{
Options: ao,
}
- ar, err := Authenticate(ao)
+ ar, err := identity.Authenticate(ao)
if err != nil {
return client, err
}
client.Authority = ar
- sc, err := GetServiceCatalog(ar)
+ sc, err := identity.GetServiceCatalog(ar)
if err != nil {
return client, err
}
@@ -61,17 +62,17 @@
return client, err
}
- var eps []Endpoint
+ var eps []identity.Endpoint
- if opts.Name != "" {
+ if eo.Name != "" {
for _, ce := range ces {
- if ce.Type == opts.Type && ce.Name == opts.Name {
+ if ce.Type == eo.Type && ce.Name == eo.Name {
eps = ce.Endpoints
}
}
} else {
for _, ce := range ces {
- if ce.Type == opts.Type {
+ if ce.Type == eo.Type {
eps = ce.Endpoints
}
}
@@ -79,8 +80,8 @@
var rep string
for _, ep := range eps {
- if ep.Region == opts.Region {
- switch opts.URLType {
+ if ep.Region == eo.Region {
+ switch eo.URLType {
case "public":
rep = ep.PublicURL
case "private":
@@ -94,7 +95,7 @@
if rep != "" {
client.Endpoint = rep
} else {
- return client, fmt.Errorf("No endpoint for given service type (%s) name (%s) and region (%s)", opts.Type, opts.Name, opts.Region)
+ return client, fmt.Errorf("No endpoint for given service type (%s) name (%s) and region (%s)", eo.Type, eo.Name, eo.Region)
}
return client, nil