本文整理匯總了Golang中github.com/rackspace/gophercloud.ServiceClient.TokenID方法的典型用法代碼示例。如果您正苦於以下問題:Golang ServiceClient.TokenID方法的具體用法?Golang ServiceClient.TokenID怎麽用?Golang ServiceClient.TokenID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rackspace/gophercloud.ServiceClient
的用法示例。
在下文中一共展示了ServiceClient.TokenID方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: authTokenPostErr
func authTokenPostErr(t *testing.T, options gophercloud.AuthOptions, scope *tokens.Scope, includeToken bool, expectedErr error) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
client := gophercloud.ServiceClient{
ProviderClient: &gophercloud.ProviderClient{},
Endpoint: testhelper.Endpoint(),
}
if includeToken {
client.TokenID = "abcdef123456"
}
_, err := tokens.Create(&client, AuthOptionsExt{AuthOptions: tokens.AuthOptions{options}, TrustID: "123456"}, scope).Extract()
if err == nil {
t.Errorf("Create did NOT return an error")
}
if err != expectedErr {
t.Errorf("Create returned an unexpected error: wanted %v, got %v", expectedErr, err)
}
}
示例2: ToAuthOptionsV3Map
func (options AuthOptions) ToAuthOptionsV3Map(c *gophercloud.ServiceClient, scope *Scope) (map[string]interface{}, error) {
// tokens3.Create logic
// Populate the request structure based on the provided arguments. Create and return an error
// if insufficient or incompatible information is present.
authMap := make(map[string]interface{})
// Test first for unrecognized arguments.
if options.APIKey != "" {
return nil, ErrAPIKeyProvided
}
if options.TenantID != "" {
return nil, ErrTenantIDProvided
}
if options.TenantName != "" {
return nil, ErrTenantNameProvided
}
if options.Password == "" {
if options.TokenID != "" {
c.TokenID = options.TokenID
}
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 nil, ErrUsernameWithToken
}
if options.UserID != "" {
return nil, ErrUserIDWithToken
}
// Configure the request for Token authentication.
authMap["identity"] = map[string]interface{}{
"methods": []string{"token"},
"token": map[string]interface{}{
"id": c.TokenID,
},
}
} else {
// If no password or token ID are available, authentication can't continue.
return nil, ErrMissingPassword
}
} else {
// Password authentication.
// At least one of Username and UserID must be specified.
if options.Username == "" && options.UserID == "" {
return nil, ErrUsernameOrUserID
}
if options.Username != "" {
// If Username is provided, UserID may not be provided.
if options.UserID != "" {
return nil, ErrUsernameOrUserID
}
// Either DomainID or DomainName must also be specified.
if options.DomainID == "" && options.DomainName == "" {
return nil, ErrDomainIDOrDomainName
}
if options.DomainID != "" {
if options.DomainName != "" {
return nil, ErrDomainIDOrDomainName
}
// Configure the request for Username and Password authentication with a DomainID.
authMap["identity"] = map[string]interface{}{
"methods": []string{"password"},
"password": map[string]interface{}{
"user": map[string]interface{}{
"name": &options.Username,
"password": options.Password,
"domain": map[string]interface{}{
"id": &options.DomainID,
},
},
},
}
}
if options.DomainName != "" {
// Configure the request for Username and Password authentication with a DomainName.
authMap["identity"] = map[string]interface{}{
"methods": []string{"password"},
"password": map[string]interface{}{
"user": map[string]interface{}{
"name": &options.Username,
"password": options.Password,
"domain": map[string]interface{}{
"name": &options.DomainName,
},
},
},
}
}
//.........這裏部分代碼省略.........
示例3: Create
// Create authenticates and either generates a new token, or changes the Scope of an existing token.
func Create(c *gophercloud.ServiceClient, options gophercloud.AuthOptions, scope *Scope) CreateResult {
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 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 tokenReq struct {
ID string `json:"id"`
}
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 authReq struct {
Identity identityReq `json:"identity"`
Scope *scopeReq `json:"scope,omitempty"`
}
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
// Test first for unrecognized arguments.
if options.APIKey != "" {
return createErr(ErrAPIKeyProvided)
}
if options.TenantID != "" {
return createErr(ErrTenantIDProvided)
}
if options.TenantName != "" {
return createErr(ErrTenantNameProvided)
}
if options.Password == "" {
if options.TokenID != "" {
c.TokenID = options.TokenID
}
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)
}
// 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)
}
} 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)
}
//.........這裏部分代碼省略.........