blob: 9cc1d59cad51a7f362ead95efcd544e12c9744d5 [file] [log] [blame]
Ash Wilson2a325802014-08-28 14:23:00 -04001package tokens
2
3import (
Ash Wilson2a325802014-08-28 14:23:00 -04004 "fmt"
jrperritt29ae6b32016-04-13 12:59:37 -05005
6 "github.com/gophercloud/gophercloud"
Ash Wilson2a325802014-08-28 14:23:00 -04007)
8
jrperritt29ae6b32016-04-13 12:59:37 -05009func unacceptedAttributeErr(attribute string) string {
10 return fmt.Sprintf("The base Identity V3 API does not accept authentication by %s", attribute)
Ash Wilson2a325802014-08-28 14:23:00 -040011}
12
jrperritt29ae6b32016-04-13 12:59:37 -050013func redundantWithTokenErr(attribute string) string {
14 return fmt.Sprintf("%s may not be provided when authenticating with a TokenID", attribute)
Ash Wilson2a325802014-08-28 14:23:00 -040015}
16
jrperritt29ae6b32016-04-13 12:59:37 -050017func redundantWithUserID(attribute string) string {
18 return fmt.Sprintf("%s may not be provided when authenticating with a UserID", attribute)
Ash Wilson2a325802014-08-28 14:23:00 -040019}
20
jrperritt29ae6b32016-04-13 12:59:37 -050021// ErrAPIKeyProvided indicates that an APIKey was provided but can't be used.
22type ErrAPIKeyProvided struct{ gophercloud.BaseError }
Ash Wilson2a325802014-08-28 14:23:00 -040023
jrperritt29ae6b32016-04-13 12:59:37 -050024func (e ErrAPIKeyProvided) Error() string {
25 return unacceptedAttributeErr("APIKey")
26}
Ash Wilson2a325802014-08-28 14:23:00 -040027
jrperritt29ae6b32016-04-13 12:59:37 -050028// ErrTenantIDProvided indicates that a TenantID was provided but can't be used.
29type ErrTenantIDProvided struct{ gophercloud.BaseError }
Ash Wilson2a325802014-08-28 14:23:00 -040030
jrperritt29ae6b32016-04-13 12:59:37 -050031func (e ErrTenantIDProvided) Error() string {
32 return unacceptedAttributeErr("TenantID")
33}
Ash Wilson2a325802014-08-28 14:23:00 -040034
jrperritt29ae6b32016-04-13 12:59:37 -050035// ErrTenantNameProvided indicates that a TenantName was provided but can't be used.
36type ErrTenantNameProvided struct{ gophercloud.BaseError }
Ash Wilson2a325802014-08-28 14:23:00 -040037
jrperritt29ae6b32016-04-13 12:59:37 -050038func (e ErrTenantNameProvided) Error() string {
39 return unacceptedAttributeErr("TenantName")
40}
Ash Wilson2a325802014-08-28 14:23:00 -040041
jrperritt29ae6b32016-04-13 12:59:37 -050042// ErrUsernameWithToken indicates that a Username was provided, but token authentication is being used instead.
43type ErrUsernameWithToken struct{ gophercloud.BaseError }
Ash Wilson2a325802014-08-28 14:23:00 -040044
jrperritt29ae6b32016-04-13 12:59:37 -050045func (e ErrUsernameWithToken) Error() string {
46 return redundantWithTokenErr("Username")
47}
Ash Wilson2a325802014-08-28 14:23:00 -040048
jrperritt29ae6b32016-04-13 12:59:37 -050049// ErrUserIDWithToken indicates that a UserID was provided, but token authentication is being used instead.
50type ErrUserIDWithToken struct{ gophercloud.BaseError }
Ash Wilson2a325802014-08-28 14:23:00 -040051
jrperritt29ae6b32016-04-13 12:59:37 -050052func (e ErrUserIDWithToken) Error() string {
53 return redundantWithTokenErr("UserID")
54}
Ash Wilson2a325802014-08-28 14:23:00 -040055
jrperritt29ae6b32016-04-13 12:59:37 -050056// ErrDomainIDWithToken indicates that a DomainID was provided, but token authentication is being used instead.
57type ErrDomainIDWithToken struct{ gophercloud.BaseError }
Ash Wilson2a325802014-08-28 14:23:00 -040058
jrperritt29ae6b32016-04-13 12:59:37 -050059func (e ErrDomainIDWithToken) Error() string {
60 return redundantWithTokenErr("DomainID")
61}
Ash Wilson2a325802014-08-28 14:23:00 -040062
jrperritt29ae6b32016-04-13 12:59:37 -050063// ErrDomainNameWithToken indicates that a DomainName was provided, but token authentication is being used instead.s
64type ErrDomainNameWithToken struct{ gophercloud.BaseError }
Ash Wilson2a325802014-08-28 14:23:00 -040065
jrperritt29ae6b32016-04-13 12:59:37 -050066func (e ErrDomainNameWithToken) Error() string {
67 return redundantWithTokenErr("DomainName")
68}
Ash Wilson2a325802014-08-28 14:23:00 -040069
jrperritt29ae6b32016-04-13 12:59:37 -050070// ErrUsernameOrUserID indicates that neither username nor userID are specified, or both are at once.
71type ErrUsernameOrUserID struct{ gophercloud.BaseError }
Ash Wilson2a325802014-08-28 14:23:00 -040072
jrperritt29ae6b32016-04-13 12:59:37 -050073func (e ErrUsernameOrUserID) Error() string {
74 return "Exactly one of Username and UserID must be provided for password authentication"
75}
Ash Wilson2a325802014-08-28 14:23:00 -040076
jrperritt29ae6b32016-04-13 12:59:37 -050077// ErrDomainIDWithUserID indicates that a DomainID was provided, but unnecessary because a UserID is being used.
78type ErrDomainIDWithUserID struct{ gophercloud.BaseError }
79
80func (e ErrDomainIDWithUserID) Error() string {
81 return redundantWithUserID("DomainID")
82}
83
84// ErrDomainNameWithUserID indicates that a DomainName was provided, but unnecessary because a UserID is being used.
85type ErrDomainNameWithUserID struct{ gophercloud.BaseError }
86
87func (e ErrDomainNameWithUserID) Error() string {
88 return redundantWithUserID("DomainName")
89}
90
91// ErrDomainIDOrDomainName indicates that a username was provided, but no domain to scope it.
92// It may also indicate that both a DomainID and a DomainName were provided at once.
93type ErrDomainIDOrDomainName struct{ gophercloud.BaseError }
94
95func (e ErrDomainIDOrDomainName) Error() string {
96 return "You must provide exactly one of DomainID or DomainName to authenticate by Username"
97}
98
99// ErrMissingPassword indicates that no password was provided and no token is available.
100type ErrMissingPassword struct{ gophercloud.BaseError }
101
102func (e ErrMissingPassword) Error() string {
103 return "You must provide a password to authenticate"
104}
105
106// ErrScopeDomainIDOrDomainName indicates that a domain ID or Name was required in a Scope, but not present.
107type ErrScopeDomainIDOrDomainName struct{ gophercloud.BaseError }
108
109func (e ErrScopeDomainIDOrDomainName) Error() string {
110 return "You must provide exactly one of DomainID or DomainName in a Scope with ProjectName"
111}
112
113// ErrScopeProjectIDOrProjectName indicates that both a ProjectID and a ProjectName were provided in a Scope.
114type ErrScopeProjectIDOrProjectName struct{ gophercloud.BaseError }
115
116func (e ErrScopeProjectIDOrProjectName) Error() string {
117 return "You must provide at most one of ProjectID or ProjectName in a Scope"
118}
119
120// ErrScopeProjectIDAlone indicates that a ProjectID was provided with other constraints in a Scope.
121type ErrScopeProjectIDAlone struct{ gophercloud.BaseError }
122
123func (e ErrScopeProjectIDAlone) Error() string {
124 return "ProjectID must be supplied alone in a Scope"
125}
126
127// ErrScopeDomainName indicates that a DomainName was provided alone in a Scope.
128type ErrScopeDomainName struct{ gophercloud.BaseError }
129
130func (e ErrScopeDomainName) Error() string {
131 return "DomainName must be supplied with a ProjectName or ProjectID in a Scope"
132}
133
134// ErrScopeEmpty indicates that no credentials were provided in a Scope.
135type ErrScopeEmpty struct{ gophercloud.BaseError }
136
137func (e ErrScopeEmpty) Error() string {
138 return "You must provide either a Project or Domain in a Scope"
139}