identity v2 error types
diff --git a/openstack/identity/v2/tokens/errors.go b/openstack/identity/v2/tokens/errors.go
index 3dfdc08..12570f5 100644
--- a/openstack/identity/v2/tokens/errors.go
+++ b/openstack/identity/v2/tokens/errors.go
@@ -1,9 +1,6 @@
package tokens
-import (
- "errors"
- "fmt"
-)
+import "fmt"
var (
// ErrUserIDProvided is returned if you attempt to authenticate with a UserID.
@@ -17,12 +14,6 @@
// ErrDomainNameProvided is returned if you attempt to authenticate with a DomainName.
ErrDomainNameProvided = unacceptedAttributeErr("DomainName")
-
- // ErrUsernameRequired is returned if you attempt to authenticate without a Username.
- ErrUsernameRequired = errors.New("You must supply a Username in your AuthOptions.")
-
- // ErrPasswordRequired is returned if you don't provide a password.
- ErrPasswordRequired = errors.New("Please supply a Password in your AuthOptions.")
)
func unacceptedAttributeErr(attribute string) error {
diff --git a/openstack/identity/v2/tokens/requests.go b/openstack/identity/v2/tokens/requests.go
index 91cadfd..6064bc7 100644
--- a/openstack/identity/v2/tokens/requests.go
+++ b/openstack/identity/v2/tokens/requests.go
@@ -1,10 +1,6 @@
package tokens
-import (
- "fmt"
-
- "github.com/gophercloud/gophercloud"
-)
+import "github.com/gophercloud/gophercloud"
// AuthOptionsBuilder describes any argument that may be passed to the Create call.
type AuthOptionsBuilder interface {
@@ -46,20 +42,26 @@
authMap := make(map[string]interface{})
if auth.Username != "" {
- if auth.Password != "" {
- authMap["passwordCredentials"] = map[string]interface{}{
- "username": auth.Username,
- "password": auth.Password,
- }
- } else {
- return nil, ErrPasswordRequired
+ if auth.Password == "" {
+ err := gophercloud.ErrMissingInput{}
+ err.Function = "tokens.ToTokenCreateMap"
+ err.Argument = "tokens.AuthOptions.Password"
+ return nil, err
+ }
+ authMap["passwordCredentials"] = map[string]interface{}{
+ "username": auth.Username,
+ "password": auth.Password,
}
} else if auth.TokenID != "" {
authMap["token"] = map[string]interface{}{
"id": auth.TokenID,
}
} else {
- return nil, fmt.Errorf("You must provide either username/password or tenantID/token values.")
+ err := gophercloud.ErrMissingInput{}
+ err.Function = "tokens.ToTokenCreateMap"
+ err.Argument = "tokens.AuthOptions.Username/tokens.AuthOptions.TokenID"
+ err.Info = "You must provide either username/password or tenantID/token values."
+ return nil, err
}
if auth.TenantID != "" {
@@ -89,7 +91,7 @@
return result
}
-// Validates and retrieves information for user's token.
+// Get validates and retrieves information for user's token.
func Get(client *gophercloud.ServiceClient, token string) GetResult {
var result GetResult
_, result.Err = client.Get(GetURL(client, token), &result.Body, &gophercloud.RequestOpts{
diff --git a/openstack/identity/v2/tokens/requests_test.go b/openstack/identity/v2/tokens/requests_test.go
index 307f367..9b3273e 100644
--- a/openstack/identity/v2/tokens/requests_test.go
+++ b/openstack/identity/v2/tokens/requests_test.go
@@ -1,7 +1,6 @@
package tokens
import (
- "fmt"
"testing"
"github.com/gophercloud/gophercloud"
@@ -128,23 +127,28 @@
options := gophercloud.AuthOptions{
Password: "thing",
}
-
- tokenPostErr(t, options, fmt.Errorf("You must provide either username/password or tenantID/token values."))
+ expected := gophercloud.ErrMissingInput{}
+ expected.Function = "tokens.ToTokenCreateMap"
+ expected.Argument = "tokens.AuthOptions.Username/tokens.AuthOptions.TokenID"
+ expected.Info = "You must provide either username/password or tenantID/token values."
+ tokenPostErr(t, options, expected)
}
func TestRequirePassword(t *testing.T) {
options := gophercloud.AuthOptions{
Username: "me",
}
-
- tokenPostErr(t, options, ErrPasswordRequired)
+ expected := gophercloud.ErrMissingInput{}
+ expected.Function = "tokens.ToTokenCreateMap"
+ expected.Argument = "tokens.AuthOptions.Password"
+ tokenPostErr(t, options, expected)
}
-func tokenGet(t *testing.T, tokenId string) GetResult {
+func tokenGet(t *testing.T, tokenID string) GetResult {
th.SetupHTTP()
defer th.TeardownHTTP()
- HandleTokenGet(t, tokenId)
- return Get(client.ServiceClient(), tokenId)
+ HandleTokenGet(t, tokenID)
+ return Get(client.ServiceClient(), tokenID)
}
func TestGetWithToken(t *testing.T) {