tokens

package
v1.0.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package tokens provides information and interaction with the token API resource for the OpenStack Identity service.

For more information, see: http://developer.openstack.org/api-ref-identity-v2.html#identity-auth-v2

Example to Create an Unscoped Token from a Password

authOpts := gophercloud.AuthOptions{
	Username: "user",
	Password: "pass"
}

token, err := tokens.Create(identityClient, authOpts).ExtractToken()
if err != nil {
	panic(err)
}

Example to Create a Token from a Tenant ID and Password

authOpts := gophercloud.AuthOptions{
	Username: "user",
	Password: "password",
	TenantID: "fc394f2ab2df4114bde39905f800dc57"
}

token, err := tokens.Create(identityClient, authOpts).ExtractToken()
if err != nil {
	panic(err)
}

Example to Create a Token from a Tenant Name and Password

authOpts := gophercloud.AuthOptions{
	Username:   "user",
	Password:   "password",
	TenantName: "tenantname"
}

token, err := tokens.Create(identityClient, authOpts).ExtractToken()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateURL

func CreateURL(client *gophercloud.ServiceClient) string

CreateURL generates the URL used to create new Tokens.

func GetURL

func GetURL(client *gophercloud.ServiceClient, token string) string

GetURL generates the URL used to Validate Tokens.

Types

type AuthOptions

type AuthOptions struct {
	IdentityEndpoint string `json:"-"`
	Username         string `json:"username,omitempty"`
	Password         string `json:"password,omitempty"`
	TenantID         string `json:"tenantId,omitempty"`
	TenantName       string `json:"tenantName,omitempty"`
	AllowReauth      bool   `json:"-"`
	TokenID          string
}

AuthOptions are the valid options for Openstack Identity v2 authentication. For field descriptions, see gophercloud.AuthOptions.

func (AuthOptions) ToTokenV2CreateMap

func (opts AuthOptions) ToTokenV2CreateMap() (map[string]interface{}, error)

ToTokenV2CreateMap builds a token request body from the given AuthOptions.

type AuthOptionsBuilder

type AuthOptionsBuilder interface {
	// ToTokenCreateMap assembles the Create request body, returning an error
	// if parameters are missing or inconsistent.
	ToTokenV2CreateMap() (map[string]interface{}, error)
}

AuthOptionsBuilder allows extensions to add additional parameters to the token create request.

type AuthOptionsV2

type AuthOptionsV2 struct {
	PasswordCredentials *PasswordCredentialsV2 `json:"passwordCredentials,omitempty" xor:"TokenCredentials"`

	// 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.
	TenantID   string `json:"tenantId,omitempty"`
	TenantName string `json:"tenantName,omitempty"`

	// TokenCredentials allows users to authenticate (possibly as another user)
	// with an authentication token ID.
	TokenCredentials *TokenCredentialsV2 `json:"token,omitempty" xor:"PasswordCredentials"`
}

AuthOptionsV2 wraps a gophercloud AuthOptions in order to adhere to the AuthOptionsBuilder interface.

type CatalogEntry

type CatalogEntry struct {
	// Name will contain the provider-specified name for the service.
	Name string `json:"name"`

	// Type will contain a type string if OpenStack defines a type for the
	// service. Otherwise, for provider-specific services, the provider may assign
	// their own type strings.
	Type string `json:"type"`

	// Endpoints will let the caller iterate over all the different endpoints that
	// may exist for the service.
	Endpoints []Endpoint `json:"endpoints"`
}

CatalogEntry provides a type-safe interface to an Identity API V2 service catalog listing.

Each class of service, such as cloud DNS or block storage services, will have a single CatalogEntry representing it.

Note: when looking for the desired service, try, whenever possible, to key off the type field. Otherwise, you'll tie the representation of the service to a specific provider.

type CreateResult

type CreateResult struct {
	gophercloud.Result
}

CreateResult is the response from a Create request. Use ExtractToken() to interpret it as a Token, or ExtractServiceCatalog() to interpret it as a service catalog.

func Create

func Create(client *gophercloud.ServiceClient, auth AuthOptionsBuilder) (r CreateResult)

Create authenticates to the identity service and attempts to acquire a Token. 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 (CreateResult) ExtractServiceCatalog

func (r CreateResult) ExtractServiceCatalog() (*ServiceCatalog, error)

ExtractServiceCatalog returns the ServiceCatalog that was generated along with the user's Token.

func (CreateResult) ExtractToken

func (r CreateResult) ExtractToken() (*Token, error)

ExtractToken returns the just-created Token from a CreateResult.

type Endpoint

type Endpoint struct {
	TenantID    string `json:"tenantId"`
	PublicURL   string `json:"publicURL"`
	InternalURL string `json:"internalURL"`
	AdminURL    string `json:"adminURL"`
	Region      string `json:"region"`
	VersionID   string `json:"versionId"`
	VersionInfo string `json:"versionInfo"`
	VersionList string `json:"versionList"`
}

Endpoint represents a single API endpoint offered by a service. It provides the public and internal URLs, if supported, along with a region specifier, again if provided.

The significance of the Region field will depend upon your provider.

In addition, the interface offered by the service will have version information associated with it through the VersionId, VersionInfo, and VersionList fields, if provided or supported.

In all cases, fields which aren't supported by the provider and service combined will assume a zero-value ("").

type GetResult

type GetResult struct {
	CreateResult
}

GetResult is the deferred response from a Get call, which is the same with a Created token. Use ExtractUser() to interpret it as a User.

func Get

func Get(client *gophercloud.ServiceClient, token string) (r GetResult)

Get validates and retrieves information for user's token.

func (GetResult) ExtractUser

func (r GetResult) ExtractUser() (*User, error)

ExtractUser returns the User from a GetResult.

type PasswordCredentialsV2

type PasswordCredentialsV2 struct {
	Username string `json:"username" required:"true"`
	Password string `json:"password" required:"true"`
}

PasswordCredentialsV2 represents the required options to authenticate with a username and password.

type Role

type Role struct {
	Name string `json:"name"`
}

Role is a role for a user.

type ServiceCatalog

type ServiceCatalog struct {
	Entries []CatalogEntry
}

ServiceCatalog provides a view into the service catalog from a previous, successful authentication.

type Token

type Token struct {
	// ID provides the primary means of identifying a user to the OpenStack API.
	// OpenStack defines this field as an opaque value, so do not depend on its
	// content. It is safe, however, to compare for equality.
	ID string

	// ExpiresAt provides a timestamp in ISO 8601 format, indicating when the
	// authentication token becomes invalid. After this point in time, future
	// API requests made using this  authentication token will respond with
	// errors. Either the caller will need to reauthenticate manually, or more
	// preferably, the caller should exploit automatic re-authentication.
	// See the AuthOptions structure for more details.
	ExpiresAt time.Time

	// Tenant provides information about the tenant to which this token grants
	// access.
	Tenant tenants.Tenant
}

Token provides only the most basic information related to an authentication token.

type TokenCredentialsV2

type TokenCredentialsV2 struct {
	ID string `json:"id,omitempty" required:"true"`
}

TokenCredentialsV2 represents the required options to authenticate with a token.

type User

type User struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	UserName string `json:"username"`
	Roles    []Role `json:"roles"`
}

User is an OpenStack user.

Directories

Path Synopsis
tokens unit tests
tokens unit tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL