tmp commit, auth unit tests broken
diff --git a/auth_options.go b/auth_options.go
index 46e55f9..0b4a02b 100644
--- a/auth_options.go
+++ b/auth_options.go
@@ -74,278 +74,223 @@
if err != nil {
return nil, err
}
- /*
- if opts.TokenID == "" {
- delete(b["auth"].(map[string]interface{}), "token")
- return b, nil
- }
-
- delete(b["auth"].(map[string]interface{}), "passwordCredentials")*/
return b, nil
}
func (opts AuthOptions) ToTokenV3CreateMap(scope *ScopeOptsV3) (map[string]interface{}, error) {
- /*
- type domainReq struct {
- ID *string `json:"id,omitempty"`
- Name *string `json:"name,omitempty"`
- }
+ type domainReq struct {
+ ID *string `json:"id,omitempty"`
+ Name *string `json:"name,omitempty"`
+ }
- type projectReq struct {
- Domain *domainReq `json:"domain,omitempty"`
- Name *string `json:"name,omitempty"`
- ID *string `json:"id,omitempty"`
- }
+ type projectReq struct {
+ Domain *domainReq `json:"domain,omitempty"`
+ Name *string `json:"name,omitempty"`
+ ID *string `json:"id,omitempty"`
+ }
- type userReq struct {
- ID *string `json:"id,omitempty"`
- Name *string `json:"name,omitempty"`
- Password string `json:"password"`
- Domain *domainReq `json:"domain,omitempty"`
- }
+ type userReq struct {
+ ID *string `json:"id,omitempty"`
+ Name *string `json:"name,omitempty"`
+ Password string `json:"password"`
+ Domain *domainReq `json:"domain,omitempty"`
+ }
- type passwordReq struct {
- User userReq `json:"user"`
- }
+ type passwordReq struct {
+ User userReq `json:"user"`
+ }
- type tokenReq struct {
- ID string `json:"id"`
- }
+ type tokenReq struct {
+ ID string `json:"id"`
+ }
- type identityReq struct {
- Methods []string `json:"methods"`
- Password *passwordReq `json:"password,omitempty"`
- Token *tokenReq `json:"token,omitempty"`
- }
+ type identityReq struct {
+ Methods []string `json:"methods"`
+ Password *passwordReq `json:"password,omitempty"`
+ Token *tokenReq `json:"token,omitempty"`
+ }
- type scopeReq struct {
- Domain *domainReq `json:"domain,omitempty"`
- Project *projectReq `json:"project,omitempty"`
- }
+ type scopeReq struct {
+ Domain *domainReq `json:"domain,omitempty"`
+ Project *projectReq `json:"project,omitempty"`
+ }
- type authReq struct {
- Identity identityReq `json:"identity"`
- Scope *scopeReq `json:"scope,omitempty"`
- }
+ type authReq struct {
+ Identity identityReq `json:"identity"`
+ Scope *scopeReq `json:"scope,omitempty"`
+ }
- type request struct {
- Auth authReq `json:"auth"`
- }
+ type request struct {
+ Auth authReq `json:"auth"`
+ }
- // Populate the request structure based on the provided arguments. Create and return an error
- // if insufficient or incompatible information is present.
- var req request
+ // Populate the request structure based on the provided arguments. Create and return an error
+ // if insufficient or incompatible information is present.
+ var (
+ req request
+ err = ErrInvalidInput{}
+ )
- // Test first for unrecognized arguments.
- if options.APIKey != "" {
- return createErr(ErrAPIKeyProvided)
- }
- if options.TenantID != "" {
- return createErr(ErrTenantIDProvided)
- }
- if options.TenantName != "" {
- return createErr(ErrTenantNameProvided)
- }
+ if opts.Password == "" {
+ if opts.TokenID != "" {
+ // Because we aren't using password authentication, it's an error to also provide any of the user-based authentication
+ // parameters.
+ if opts.Username != "" {
+ err.Info = "You may not provide a username when using token-based authentication."
+ return nil, err
+ //return createErr(ErrUsernameWithToken)
+ }
+ if opts.UserID != "" {
+ err.Info = "You may not provide a user ID when using token-based authentication."
+ return nil, err
+ }
+ if opts.DomainID != "" {
+ err.Info = "You may not provide a domain ID when using token-based authentication."
+ return nil, err
+ }
+ if opts.DomainName != "" {
+ err.Info = "You may not provide a domain name when using token-based authentication."
+ return nil, err
+ }
- if options.Password == "" {
- if c.TokenID != "" {
- // Because we aren't using password authentication, it's an error to also provide any of the user-based authentication
- // parameters.
- if options.Username != "" {
- return createErr(ErrUsernameWithToken)
- }
- if options.UserID != "" {
- return createErr(ErrUserIDWithToken)
- }
- if options.DomainID != "" {
- return createErr(ErrDomainIDWithToken)
- }
- if options.DomainName != "" {
- return createErr(ErrDomainNameWithToken)
- }
-
- // Configure the request for Token authentication.
- req.Auth.Identity.Methods = []string{"token"}
- req.Auth.Identity.Token = &tokenReq{
- ID: c.TokenID,
- }
- } else {
- // If no password or token ID are available, authentication can't continue.
- return createErr(ErrMissingPassword)
+ // Configure the request for Token authentication.
+ req.Auth.Identity.Methods = []string{"token"}
+ req.Auth.Identity.Token = &tokenReq{
+ ID: opts.TokenID,
}
} else {
- // Password authentication.
- req.Auth.Identity.Methods = []string{"password"}
-
- // At least one of Username and UserID must be specified.
- if options.Username == "" && options.UserID == "" {
- return createErr(ErrUsernameOrUserID)
- }
-
- if options.Username != "" {
- // If Username is provided, UserID may not be provided.
- if options.UserID != "" {
- return createErr(ErrUsernameOrUserID)
- }
-
- // Either DomainID or DomainName must also be specified.
- if options.DomainID == "" && options.DomainName == "" {
- return createErr(ErrDomainIDOrDomainName)
- }
-
- if options.DomainID != "" {
- if options.DomainName != "" {
- return createErr(ErrDomainIDOrDomainName)
- }
-
- // Configure the request for Username and Password authentication with a DomainID.
- req.Auth.Identity.Password = &passwordReq{
- User: userReq{
- Name: &options.Username,
- Password: options.Password,
- Domain: &domainReq{ID: &options.DomainID},
- },
- }
- }
-
- if options.DomainName != "" {
- // Configure the request for Username and Password authentication with a DomainName.
- req.Auth.Identity.Password = &passwordReq{
- User: userReq{
- Name: &options.Username,
- Password: options.Password,
- Domain: &domainReq{Name: &options.DomainName},
- },
- }
- }
- }
-
- if options.UserID != "" {
- // If UserID is specified, neither DomainID nor DomainName may be.
- if options.DomainID != "" {
- return createErr(ErrDomainIDWithUserID)
- }
- if options.DomainName != "" {
- return createErr(ErrDomainNameWithUserID)
- }
-
- // Configure the request for UserID and Password authentication.
- req.Auth.Identity.Password = &passwordReq{
- User: userReq{ID: &options.UserID, Password: options.Password},
- }
- }
+ // If no password or token ID are available, authentication can't continue.
+ err.Info = "You must provide either a password or a token."
+ return nil, err
}
-
- // Add a "scope" element if a Scope has been provided.
- if scope != nil {
- if scope.ProjectName != "" {
- // ProjectName provided: either DomainID or DomainName must also be supplied.
- // ProjectID may not be supplied.
- if scope.DomainID == "" && scope.DomainName == "" {
- return createErr(ErrScopeDomainIDOrDomainName)
- }
- if scope.ProjectID != "" {
- return createErr(ErrScopeProjectIDOrProjectName)
- }
-
- if scope.DomainID != "" {
- // ProjectName + DomainID
- req.Auth.Scope = &scopeReq{
- Project: &projectReq{
- Name: &scope.ProjectName,
- Domain: &domainReq{ID: &scope.DomainID},
- },
- }
- }
-
- if scope.DomainName != "" {
- // ProjectName + DomainName
- req.Auth.Scope = &scopeReq{
- Project: &projectReq{
- Name: &scope.ProjectName,
- Domain: &domainReq{Name: &scope.DomainName},
- },
- }
- }
- } else if scope.ProjectID != "" {
- // ProjectID provided. ProjectName, DomainID, and DomainName may not be provided.
- if scope.DomainID != "" {
- return createErr(ErrScopeProjectIDAlone)
- }
- if scope.DomainName != "" {
- return createErr(ErrScopeProjectIDAlone)
- }
-
- // ProjectID
- req.Auth.Scope = &scopeReq{
- Project: &projectReq{ID: &scope.ProjectID},
- }
- } else if scope.DomainID != "" {
- // DomainID provided. ProjectID, ProjectName, and DomainName may not be provided.
- if scope.DomainName != "" {
- return createErr(ErrScopeDomainIDOrDomainName)
- }
-
- // DomainID
- req.Auth.Scope = &scopeReq{
- Domain: &domainReq{ID: &scope.DomainID},
- }
- } else if scope.DomainName != "" {
- return createErr(ErrScopeDomainName)
- } else {
- return createErr(ErrScopeEmpty)
- }
- }
- */
-
- var methods []string
- if opts.TokenID != "" {
- methods = []string{"token"}
} else {
- methods = []string{"password"}
- }
+ // Password authentication.
+ req.Auth.Identity.Methods = []string{"password"}
- v3Opts := AuthOptionsV3{
- Identity: &IdentityCredentialsV3{
- Methods: methods,
- PasswordCredentials: &PasswordCredentialsV3{
- User: &UserV3{
- ID: opts.UserID,
- Name: opts.Username,
- Password: opts.Password,
- Domain: &DomainV3{
- ID: opts.DomainID,
- Name: opts.DomainName,
+ // At least one of Username and UserID must be specified.
+ if opts.Username == "" && opts.UserID == "" {
+ err.Info = "You may not provide a username when using token-based authentication."
+ return nil, err
+ }
+
+ if opts.Username != "" {
+ // If Username is provided, UserID may not be provided.
+ if opts.UserID != "" {
+ err.Info = "One and only one of username and user ID may be provided for password-based authentication."
+ return nil, err
+ //return createErr(ErrUsernameOrUserID)
+ }
+
+ // Either DomainID or DomainName must also be specified.
+ if opts.DomainID == "" && opts.DomainName == "" {
+ err.Info = "You must provide exactly one of DomainID or DomainName to authenticate by Username"
+ return nil, err
+ //return createErr(ErrDomainIDOrDomainName)
+ }
+
+ if opts.DomainID != "" {
+ if opts.DomainName != "" {
+ err.Info = "You must provide exactly one of DomainID or DomainName to authenticate by Username"
+ return nil, err
+ //return createErr(ErrDomainIDOrDomainName)
+ }
+
+ // Configure the request for Username and Password authentication with a DomainID.
+ req.Auth.Identity.Password = &passwordReq{
+ User: userReq{
+ Name: &opts.Username,
+ Password: opts.Password,
+ Domain: &domainReq{ID: &opts.DomainID},
},
- },
- },
- TokenCredentials: &TokenCredentialsV3{
- ID: opts.TokenID,
- },
- },
- }
+ }
+ }
- if scope != nil {
- v3Opts.Scope = &ScopeV3{
- Domain: &ScopeDomainV3{
- ID: scope.DomainID,
- Name: scope.DomainName,
- },
- Project: &ScopeProjectV3{
- Domain: &ScopeProjectDomainV3{
- ID: scope.DomainID,
- Name: scope.DomainName,
- },
- ID: scope.ProjectID,
- Name: scope.ProjectName,
- },
+ if opts.DomainName != "" {
+ // Configure the request for Username and Password authentication with a DomainName.
+ req.Auth.Identity.Password = &passwordReq{
+ User: userReq{
+ Name: &opts.Username,
+ Password: opts.Password,
+ Domain: &domainReq{Name: &opts.DomainName},
+ },
+ }
+ }
+ }
+
+ if opts.UserID != "" {
+ // If UserID is specified, neither DomainID nor DomainName may be.
+ if opts.DomainID != "" {
+ return createErr(ErrDomainIDWithUserID)
+ }
+ if opts.DomainName != "" {
+ return createErr(ErrDomainNameWithUserID)
+ }
+
+ // Configure the request for UserID and Password authentication.
+ req.Auth.Identity.Password = &passwordReq{
+ User: userReq{ID: &opts.UserID, Password: opts.Password},
+ }
}
}
- b, err := BuildRequestBody(v3Opts, "auth")
- if err != nil {
- return nil, err
- }
+ // Add a "scope" element if a Scope has been provided.
+ if scope != nil {
+ if scope.ProjectName != "" {
+ // ProjectName provided: either DomainID or DomainName must also be supplied.
+ // ProjectID may not be supplied.
+ if scope.DomainID == "" && scope.DomainName == "" {
+ return createErr(ErrScopeDomainIDOrDomainName)
+ }
+ if scope.ProjectID != "" {
+ return createErr(ErrScopeProjectIDOrProjectName)
+ }
- return b, nil
+ if scope.DomainID != "" {
+ // ProjectName + DomainID
+ req.Auth.Scope = &scopeReq{
+ Project: &projectReq{
+ Name: &scope.ProjectName,
+ Domain: &domainReq{ID: &scope.DomainID},
+ },
+ }
+ }
+
+ if scope.DomainName != "" {
+ // ProjectName + DomainName
+ req.Auth.Scope = &scopeReq{
+ Project: &projectReq{
+ Name: &scope.ProjectName,
+ Domain: &domainReq{Name: &scope.DomainName},
+ },
+ }
+ }
+ } else if scope.ProjectID != "" {
+ // ProjectID provided. ProjectName, DomainID, and DomainName may not be provided.
+ if scope.DomainID != "" {
+ return createErr(ErrScopeProjectIDAlone)
+ }
+ if scope.DomainName != "" {
+ return createErr(ErrScopeProjectIDAlone)
+ }
+
+ // ProjectID
+ req.Auth.Scope = &scopeReq{
+ Project: &projectReq{ID: &scope.ProjectID},
+ }
+ } else if scope.DomainID != "" {
+ // DomainID provided. ProjectID, ProjectName, and DomainName may not be provided.
+ if scope.DomainName != "" {
+ return createErr(ErrScopeDomainIDOrDomainName)
+ }
+
+ // DomainID
+ req.Auth.Scope = &scopeReq{
+ Domain: &domainReq{ID: &scope.DomainID},
+ }
+ } else if scope.DomainName != "" {
+ return createErr(ErrScopeDomainName)
+ } else {
+ return createErr(ErrScopeEmpty)
+ }
+ }
}
diff --git a/authv2.go b/auth_options_v2.go
similarity index 74%
rename from authv2.go
rename to auth_options_v2.go
index 6eed8af..8d6834e 100644
--- a/authv2.go
+++ b/auth_options_v2.go
@@ -9,7 +9,7 @@
ID string `json:"id,omitempty" required:"true"`
}
-// AuthOptions wraps a gophercloud AuthOptions in order to adhere to the AuthOptionsBuilder
+// AuthOptionsV2 wraps a gophercloud AuthOptions in order to adhere to the AuthOptionsBuilder
// interface.
type AuthOptionsV2 struct {
PasswordCredentials *PasswordCredentialsV2 `json:"passwordCredentials,omitempty" xor:"TokenCredentials"`
@@ -25,9 +25,3 @@
// authentication token ID.
TokenCredentials *TokenCredentialsV2 `json:"token,omitempty" xor:"PasswordCredentials"`
}
-
-// ToTokenV2CreateMap allows AuthOptionsV2 to satisfy the AuthOptionsBuilder
-// interface in the v2 tokens package
-func (opts AuthOptionsV2) ToTokenV2CreateMap() (map[string]interface{}, error) {
- return BuildRequestBody(opts, "auth")
-}
diff --git a/authv3.go b/auth_options_v3.go
similarity index 80%
rename from authv3.go
rename to auth_options_v3.go
index 3099b95..bef7655 100644
--- a/authv3.go
+++ b/auth_options_v3.go
@@ -59,23 +59,3 @@
Identity *IdentityCredentialsV3 `json:"identity" required:"true"`
Scope *ScopeV3 `json:"scope,omitempty"`
}
-
-func (opts AuthOptionsV3) ToTokenV3CreateMap(scope *ScopeOptsV3) (map[string]interface{}, error) {
- if scope != nil {
- opts.Scope = &ScopeV3{
- Domain: &ScopeDomainV3{
- ID: scope.DomainID,
- Name: scope.DomainName,
- },
- Project: &ScopeProjectV3{
- Domain: &ScopeProjectDomainV3{
- ID: scope.DomainID,
- Name: scope.DomainName,
- },
- ID: scope.ProjectID,
- Name: scope.ProjectName,
- },
- }
- }
- return BuildRequestBody(opts, "auth")
-}
diff --git a/errors.go b/errors.go
index 0333977..978fcb5 100644
--- a/errors.go
+++ b/errors.go
@@ -4,12 +4,20 @@
// BaseError is an error type that all other error types embed.
type BaseError struct {
- Info string
- //Function string
+ DefaultErrString string
+ Info string
}
func (e BaseError) Error() string {
- return "An error occurred while executing a Gophercloud request."
+ e.DefaultErrString = "An error occurred while executing a Gophercloud request."
+ return e.choseErrString()
+}
+
+func (e BaseError) choseErrString() string {
+ if e.Info != "" {
+ return e.Info
+ }
+ return e.DefaultErrString
}
// ErrMissingInput is the error when input is required in a particular
@@ -20,7 +28,8 @@
}
func (e ErrMissingInput) Error() string {
- return fmt.Sprintf("Missing input for argument [%s]", e.Argument)
+ e.DefaultErrString = fmt.Sprintf("Missing input for argument [%s]", e.Argument)
+ return e.choseErrString()
}
// ErrInvalidInput is an error type used for most non-HTTP Gophercloud errors.
@@ -30,7 +39,8 @@
}
func (e ErrInvalidInput) Error() string {
- return fmt.Sprintf("Invalid input provided for argument [%s]: [%+v]", e.Argument, e.Value)
+ e.DefaultErrString = fmt.Sprintf("Invalid input provided for argument [%s]: [%+v]", e.Argument, e.Value)
+ return e.choseErrString()
}
// ErrUnexpectedResponseCode is returned by the Request method when a response code other than
@@ -44,11 +54,12 @@
Body []byte
}
-func (err ErrUnexpectedResponseCode) Error() string {
- return fmt.Sprintf(
+func (e ErrUnexpectedResponseCode) Error() string {
+ e.DefaultErrString = fmt.Sprintf(
"Expected HTTP response code %v when accessing [%s %s], but got %d instead\n%s",
- err.Expected, err.Method, err.URL, err.Actual, err.Body,
+ e.Expected, e.Method, e.URL, e.Actual, e.Body,
)
+ return e.choseErrString()
}
// ErrDefault400 is the default error type returned on a 400 HTTP response code.
@@ -172,7 +183,8 @@
}
func (e ErrTimeOut) Error() string {
- return "A time out occurred"
+ e.DefaultErrString = "A time out occurred"
+ return e.choseErrString()
}
// ErrUnableToReauthenticate is the error type returned when reauthentication fails.
@@ -182,7 +194,8 @@
}
func (e ErrUnableToReauthenticate) Error() string {
- return fmt.Sprintf("Unable to re-authenticate: %s", e.ErrOriginal)
+ e.DefaultErrString = fmt.Sprintf("Unable to re-authenticate: %s", e.ErrOriginal)
+ return e.choseErrString()
}
// ErrErrorAfterReauthentication is the error type returned when reauthentication
@@ -193,7 +206,8 @@
}
func (e ErrErrorAfterReauthentication) Error() string {
- return fmt.Sprintf("Successfully re-authenticated, but got error executing request: %s", e.ErrOriginal)
+ e.DefaultErrString = fmt.Sprintf("Successfully re-authenticated, but got error executing request: %s", e.ErrOriginal)
+ return e.choseErrString()
}
// ErrServiceNotFound is returned when no service in a service catalog matches
@@ -205,7 +219,8 @@
}
func (e ErrServiceNotFound) Error() string {
- return "No suitable service could be found in the service catalog."
+ e.DefaultErrString = "No suitable service could be found in the service catalog."
+ return e.choseErrString()
}
// ErrEndpointNotFound is returned when no available endpoints match the
@@ -217,7 +232,8 @@
}
func (e ErrEndpointNotFound) Error() string {
- return "No suitable endpoint could be found in the service catalog."
+ e.DefaultErrString = "No suitable endpoint could be found in the service catalog."
+ return e.choseErrString()
}
// ErrResourceNotFound is the error when trying to retrieve a resource's
@@ -229,7 +245,8 @@
}
func (e ErrResourceNotFound) Error() string {
- return fmt.Sprintf("Unable to find %s with name %s", e.ResourceType, e.Name)
+ e.DefaultErrString = fmt.Sprintf("Unable to find %s with name %s", e.ResourceType, e.Name)
+ return e.choseErrString()
}
// ErrMultipleResourcesFound is the error when trying to retrieve a resource's
@@ -242,7 +259,8 @@
}
func (e ErrMultipleResourcesFound) Error() string {
- return fmt.Sprintf("Found %d %ss matching %s", e.Count, e.ResourceType, e.Name)
+ e.DefaultErrString = fmt.Sprintf("Found %d %ss matching %s", e.Count, e.ResourceType, e.Name)
+ return e.choseErrString()
}
// ErrUnexpectedType is the error when an unexpected type is encountered
@@ -253,5 +271,6 @@
}
func (e ErrUnexpectedType) Error() string {
- return fmt.Sprintf("Expected %s but got %s", e.Expected, e.Actual)
+ e.DefaultErrString = fmt.Sprintf("Expected %s but got %s", e.Expected, e.Actual)
+ return e.choseErrString()
}
diff --git a/openstack/identity/v2/tokens/requests.go b/openstack/identity/v2/tokens/requests.go
index a2a0685..12c0f17 100644
--- a/openstack/identity/v2/tokens/requests.go
+++ b/openstack/identity/v2/tokens/requests.go
@@ -13,24 +13,20 @@
// If successful, the CreateResult
// Generally, rather than interact with this call directly, end users should call openstack.AuthenticatedClient(),
// which abstracts all of the gory details about navigating service catalogs and such.
-func Create(client *gophercloud.ServiceClient, auth AuthOptionsBuilder) CreateResult {
- var r CreateResult
+func Create(client *gophercloud.ServiceClient, auth AuthOptionsBuilder) (r CreateResult) {
b, err := auth.ToTokenV2CreateMap()
if err != nil {
r.Err = err
- return r
+ return
}
_, r.Err = client.Post(CreateURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 203},
})
- return r
}
// Get validates and retrieves information for user's token.
-func Get(client *gophercloud.ServiceClient, token string) GetResult {
- var r GetResult
+func Get(client *gophercloud.ServiceClient, token string) (r GetResult) {
_, r.Err = client.Get(GetURL(client, token), &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 203},
})
- return r
}
diff --git a/openstack/identity/v3/tokens/requests.go b/openstack/identity/v3/tokens/requests.go
index e7320fd..6978186 100644
--- a/openstack/identity/v3/tokens/requests.go
+++ b/openstack/identity/v3/tokens/requests.go
@@ -20,24 +20,21 @@
}
// Create authenticates and either generates a new token, or changes the Scope of an existing token.
-func Create(c *gophercloud.ServiceClient, opts AuthOptionsBuilder, scopeOpts *gophercloud.ScopeOptsV3) CreateResult {
- var r CreateResult
+func Create(c *gophercloud.ServiceClient, opts AuthOptionsBuilder, scopeOpts *gophercloud.ScopeOptsV3) (r CreateResult) {
b, err := opts.ToTokenV3CreateMap(scopeOpts)
if err != nil {
r.Err = err
- return r
+ return
}
var resp *http.Response
resp, r.Err = c.Post(tokenURL(c), b, &r.Body, nil)
if resp != nil {
r.Header = resp.Header
}
- return r
}
// Get validates and retrieves information about another token.
-func Get(c *gophercloud.ServiceClient, token string) GetResult {
- var r GetResult
+func Get(c *gophercloud.ServiceClient, token string) (r GetResult) {
var resp *http.Response
resp, r.Err = c.Get(tokenURL(c), &r.Body, &gophercloud.RequestOpts{
MoreHeaders: subjectTokenHeaders(c, token),
@@ -46,7 +43,6 @@
if resp != nil {
r.Header = resp.Header
}
- return r
}
// Validate determines if a specified token is valid or not.
@@ -63,10 +59,8 @@
}
// Revoke immediately makes specified token invalid.
-func Revoke(c *gophercloud.ServiceClient, token string) RevokeResult {
- var r RevokeResult
+func Revoke(c *gophercloud.ServiceClient, token string) (r RevokeResult) {
_, r.Err = c.Delete(tokenURL(c), &gophercloud.RequestOpts{
MoreHeaders: subjectTokenHeaders(c, token),
})
- return r
}
diff --git a/pagination/http.go b/pagination/http.go
index 9ac2372..db31b55 100644
--- a/pagination/http.go
+++ b/pagination/http.go
@@ -53,7 +53,7 @@
// Request performs an HTTP request and extracts the http.Response from the result.
func Request(client *gophercloud.ServiceClient, headers map[string]string, url string) (*http.Response, error) {
- return client.Request("GET", url, &gophercloud.RequestOpts{
+ return client.Request("GET", url, gophercloud.RequestOpts{
MoreHeaders: headers,
OkCodes: []int{200, 204},
})
diff --git a/pagination/null.go b/pagination/null.go
deleted file mode 100644
index ae57e18..0000000
--- a/pagination/null.go
+++ /dev/null
@@ -1,20 +0,0 @@
-package pagination
-
-// nullPage is an always-empty page that trivially satisfies all Page interfacts.
-// It's useful to be returned along with an error.
-type nullPage struct{}
-
-// NextPageURL always returns "" to indicate that there are no more pages to return.
-func (p nullPage) NextPageURL() (string, error) {
- return "", nil
-}
-
-// IsEmpty always returns true to prevent iteration over nullPages.
-func (p nullPage) IsEmpty() (bool, error) {
- return true, nil
-}
-
-// LastMark always returns "" because the nullPage contains no items to have a mark.
-func (p nullPage) LastMark() (string, error) {
- return "", nil
-}
diff --git a/pagination/pager.go b/pagination/pager.go
index 415442f..9fa1f93 100644
--- a/pagination/pager.go
+++ b/pagination/pager.go
@@ -145,7 +145,7 @@
// key is the map key for the page body if the body type is `map[string]interface{}`.
var key string
// Iterate over the pages to concatenate the bodies.
- err := p.EachPage(func(page Page) (bool, error) {
+ err = p.EachPage(func(page Page) (bool, error) {
b := page.GetBody().(map[string]interface{})
for k := range b {
// If it's a linked page, we don't want the `links`, we want the other one.
@@ -164,7 +164,7 @@
body.SetMapIndex(reflect.ValueOf(key), reflect.ValueOf(pagesSlice))
case []byte:
// Iterate over the pages to concatenate the bodies.
- err := p.EachPage(func(page Page) (bool, error) {
+ err = p.EachPage(func(page Page) (bool, error) {
b := page.GetBody().([]byte)
pagesSlice = append(pagesSlice, b)
// seperate pages with a comma
@@ -188,7 +188,7 @@
body.SetBytes(b)
case []interface{}:
// Iterate over the pages to concatenate the bodies.
- err := p.EachPage(func(page Page) (bool, error) {
+ err = p.EachPage(func(page Page) (bool, error) {
b := page.GetBody().([]interface{})
pagesSlice = append(pagesSlice, b...)
return true, nil
@@ -202,7 +202,7 @@
body.Index(i).Set(reflect.ValueOf(s))
}
default:
- err := gophercloud.ErrUnexpectedType{}
+ err = gophercloud.ErrUnexpectedType{}
err.Expected = "map[string]interface{}/[]byte/[]interface{}"
err.Actual = fmt.Sprintf("%v", reflect.TypeOf(testPage.GetBody()))
return nil, err
diff --git a/params.go b/params.go
index 14b3e28..48a48ee 100644
--- a/params.go
+++ b/params.go
@@ -33,21 +33,14 @@
f := optsType.Field(i)
if f.Name != strings.Title(f.Name) {
- fmt.Printf("Skipping field: %s...\n", f.Name)
+ //fmt.Printf("Skipping field: %s...\n", f.Name)
continue
}
- fmt.Printf("Starting on field: %s...\n", f.Name)
+ //fmt.Printf("Starting on field: %s...\n", f.Name)
zero := isZero(v)
- fmt.Printf("v is zero?: %v\n", zero)
-
- // if there are 0 tags or if there is only 1 and it's the json tag,
- // we don't need to do anything for this field
- //if len(strings.Split(string(f.Tag), " ")) < 2 && f.Tag.Get("json") != "" && zero {
- // fmt.Printf("skipping field: %s with tag: %+v\n", f.Name, f.Tag)
- // continue
- //}
+ //fmt.Printf("v is zero?: %v\n", zero)
// if the field has a required tag that's set to "true"
if requiredTag := f.Tag.Get("required"); requiredTag == "true" {