v2 is now golint clean :lipstick:
diff --git a/openstack/identity/v2/requests.go b/openstack/identity/v2/requests.go
index dbd367e..d027962 100644
--- a/openstack/identity/v2/requests.go
+++ b/openstack/identity/v2/requests.go
@@ -2,6 +2,7 @@
import (
"github.com/racker/perigee"
+ "github.com/rackspace/gophercloud"
)
// AuthResults encapsulates the raw results from an authentication request.
@@ -11,60 +12,25 @@
// such as ServiceCatalog() and Token().
type AuthResults map[string]interface{}
-// AuthOptions lets anyone calling Authenticate() supply the required access
-// credentials. At present, only Identity V2 API support exists; therefore,
-// only Username, Password, and optionally, TenantId are provided. If future
-// Identity API versions become available, alternative fields unique to those
-// versions may appear here.
-//
-// Endpoint specifies the HTTP endpoint offering the Identity V2 API.
-// Required.
-//
-// Username is required if using Identity V2 API. Consult with your provider's
-// control panel to discover your account's username.
-//
-// At most one of Password or ApiKey is required if using Identity V2 API.
-// Consult with your provider's control panel to discover your account's
-// preferred method of authentication.
-//
-// The TenantId and TenantName fields are optional for the Identity V2 API.
-// Some providers allow you to specify a TenantName instead of the TenantId.
-// Some require both. Your provider's authentication policies will determine
-// how these fields influence authentication.
-//
-// AllowReauth should be set to true if you grant permission for Gophercloud to
-// cache your credentials in memory, and to allow Gophercloud to attempt to
-// re-authenticate automatically if/when your token expires. If you set it to
-// false, it will not cache these settings, but re-authentication will not be
-// possible. This setting defaults to false.
-type AuthOptions struct {
- Endpoint string
- Username string
- Password, ApiKey string
- TenantId string
- TenantName string
- AllowReauth bool
-}
-
// Authenticate passes the supplied credentials to the OpenStack provider for authentication.
// If successful, the caller may use Token() to retrieve the authentication token,
// and ServiceCatalog() to retrieve the set of services available to the API user.
-func Authenticate(options AuthOptions) (AuthResults, error) {
+func Authenticate(service gophercloud.ServiceClient, options gophercloud.AuthOptions) (AuthResults, error) {
type AuthContainer struct {
Auth auth `json:"auth"`
}
var ar AuthResults
- if options.Endpoint == "" {
+ if options.IdentityEndpoint == "" {
return nil, ErrEndpoint
}
- if (options.Username == "") || (options.Password == "" && options.ApiKey == "") {
+ if (options.Username == "") || (options.Password == "" && options.APIKey == "") {
return nil, ErrCredentials
}
- url := options.Endpoint + "/tokens"
+ url := options.IdentityEndpoint + "/tokens"
err := perigee.Post(url, perigee.Options{
ReqBody: &AuthContainer{
Auth: getAuthCredentials(options),
@@ -74,8 +40,8 @@
return ar, err
}
-func getAuthCredentials(options AuthOptions) auth {
- if options.ApiKey == "" {
+func getAuthCredentials(options gophercloud.AuthOptions) auth {
+ if options.APIKey == "" {
return auth{
PasswordCredentials: &struct {
Username string `json:"username"`
@@ -84,35 +50,35 @@
Username: options.Username,
Password: options.Password,
},
- TenantId: options.TenantId,
+ TenantID: options.TenantID,
TenantName: options.TenantName,
}
- } else {
- return auth{
- ApiKeyCredentials: &struct {
- Username string `json:"username"`
- ApiKey string `json:"apiKey"`
- }{
- Username: options.Username,
- ApiKey: options.ApiKey,
- },
- TenantId: options.TenantId,
- TenantName: options.TenantName,
- }
+ }
+ return auth{
+ APIKeyCredentials: &struct {
+ Username string `json:"username"`
+ APIKey string `json:"apiKey"`
+ }{
+ Username: options.Username,
+ APIKey: options.APIKey,
+ },
+ TenantID: options.TenantID,
+ TenantName: options.TenantName,
}
}
type auth struct {
PasswordCredentials interface{} `json:"passwordCredentials,omitempty"`
- ApiKeyCredentials interface{} `json:"RAX-KSKEY:apiKeyCredentials,omitempty"`
- TenantId string `json:"tenantId,omitempty"`
+ APIKeyCredentials interface{} `json:"RAX-KSKEY:apiKeyCredentials,omitempty"`
+ TenantID string `json:"tenantId,omitempty"`
TenantName string `json:"tenantName,omitempty"`
}
-func GetExtensions(options AuthOptions) (ExtensionsResult, error) {
+// GetExtensions returns the OpenStack extensions available from this service.
+func GetExtensions(options gophercloud.AuthOptions) (ExtensionsResult, error) {
var exts ExtensionsResult
- url := options.Endpoint + "/extensions"
+ url := options.IdentityEndpoint + "/extensions"
err := perigee.Get(url, perigee.Options{
Results: &exts,
})
diff --git a/openstack/identity/v2/service_catalog.go b/openstack/identity/v2/service_catalog.go
index 035f671..4147723 100644
--- a/openstack/identity/v2/service_catalog.go
+++ b/openstack/identity/v2/service_catalog.go
@@ -40,11 +40,11 @@
//
// In all cases, fields which aren't supported by the provider and service combined will assume a zero-value ("").
type Endpoint struct {
- TenantId string
+ TenantID string
PublicURL string
InternalURL string
Region string
- VersionId string
+ VersionID string
VersionInfo string
VersionList string
}
diff --git a/openstack/identity/v2/service_catalog_test.go b/openstack/identity/v2/service_catalog_test.go
index f810609..d089482 100644
--- a/openstack/identity/v2/service_catalog_test.go
+++ b/openstack/identity/v2/service_catalog_test.go
@@ -45,8 +45,8 @@
return
}
for _, ep := range eps {
- if strNotInStrList(ep.VersionId, "1", "1.1", "1.1") {
- t.Errorf("Expected versionId field of compute resource to be one of 1 or 1.1")
+ if strNotInStrList(ep.VersionID, "1", "1.1", "1.1") {
+ t.Errorf("Expected versionID field of compute resource to be one of 1 or 1.1")
return
}
}
@@ -57,7 +57,7 @@
return
}
for _, ep := range eps {
- if ep.VersionId != "1" {
+ if ep.VersionID != "1" {
t.Errorf("Expected only version 1 object store API version")
return
}
@@ -68,7 +68,7 @@
t.Errorf("Expected 1 endpoint for DNS-as-a-Service service")
return
}
- if eps[0].VersionId != "2.0" {
+ if eps[0].VersionID != "2.0" {
t.Errorf("Expected version 2.0 of DNS-as-a-Service service")
return
}
diff --git a/openstack/identity/v2/token.go b/openstack/identity/v2/token.go
index d50cce0..b2c526a 100644
--- a/openstack/identity/v2/token.go
+++ b/openstack/identity/v2/token.go
@@ -21,21 +21,21 @@
//
// TenantName provides a human-readable tenant name corresponding to the TenantId.
type Token struct {
- Id, Expires string
- TenantId, TenantName string
+ ID, Expires string
+ TenantID, TenantName string
}
-// GetToken, if successful, yields an unpacked collection of fields related to the user's access credentials, called a "token."
+// GetToken yields an unpacked collection of fields related to the user's access credentials, called a "token", if successful.
// See the Token structure for more details.
func GetToken(m AuthResults) (*Token, error) {
type (
Tenant struct {
- Id string
+ ID string
Name string
}
TokenDesc struct {
- Id string `mapstructure:"id"`
+ ID string `mapstructure:"id"`
Expires string `mapstructure:"expires"`
Tenant
}
@@ -55,9 +55,9 @@
return nil, err
}
td := &Token{
- Id: t.Id,
+ ID: t.ID,
Expires: t.Expires,
- TenantId: t.Tenant.Id,
+ TenantID: t.Tenant.ID,
TenantName: t.Tenant.Name,
}
return td, nil
diff --git a/openstack/identity/v2/token_test.go b/openstack/identity/v2/token_test.go
index 5e96496..872813f 100644
--- a/openstack/identity/v2/token_test.go
+++ b/openstack/identity/v2/token_test.go
@@ -18,8 +18,8 @@
t.Error(err)
return
}
- if tok.Id != "ab48a9efdfedb23ty3494" {
- t.Errorf("Expected token \"ab48a9efdfedb23ty3494\"; got \"%s\" instead", tok.Id)
+ if tok.ID != "ab48a9efdfedb23ty3494" {
+ t.Errorf("Expected token \"ab48a9efdfedb23ty3494\"; got \"%s\" instead", tok.ID)
return
}
}