6 "github.com/gophercloud/gophercloud"
7 "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants"
10 // Token provides only the most basic information related to an authentication
13 // ID provides the primary means of identifying a user to the OpenStack API.
14 // OpenStack defines this field as an opaque value, so do not depend on its
15 // content. It is safe, however, to compare for equality.
18 // ExpiresAt provides a timestamp in ISO 8601 format, indicating when the
19 // authentication token becomes invalid. After this point in time, future
20 // API requests made using this authentication token will respond with
21 // errors. Either the caller will need to reauthenticate manually, or more
22 // preferably, the caller should exploit automatic re-authentication.
23 // See the AuthOptions structure for more details.
26 // Tenant provides information about the tenant to which this token grants
31 // Role is a role for a user.
33 Name string `json:"name"`
36 // User is an OpenStack user.
39 Name string `json:"name"`
40 UserName string `json:"username"`
41 Roles []Role `json:"roles"`
44 // Endpoint represents a single API endpoint offered by a service.
45 // It provides the public and internal URLs, if supported, along with a region
46 // specifier, again if provided.
48 // The significance of the Region field will depend upon your provider.
50 // In addition, the interface offered by the service will have version
51 // information associated with it through the VersionId, VersionInfo, and
52 // VersionList fields, if provided or supported.
54 // In all cases, fields which aren't supported by the provider and service
55 // combined will assume a zero-value ("").
56 type Endpoint struct {
57 TenantID string `json:"tenantId"`
58 PublicURL string `json:"publicURL"`
59 InternalURL string `json:"internalURL"`
60 AdminURL string `json:"adminURL"`
61 Region string `json:"region"`
62 VersionID string `json:"versionId"`
63 VersionInfo string `json:"versionInfo"`
64 VersionList string `json:"versionList"`
67 // CatalogEntry provides a type-safe interface to an Identity API V2 service
70 // Each class of service, such as cloud DNS or block storage services, will have
71 // a single CatalogEntry representing it.
73 // Note: when looking for the desired service, try, whenever possible, to key
74 // off the type field. Otherwise, you'll tie the representation of the service
75 // to a specific provider.
76 type CatalogEntry struct {
77 // Name will contain the provider-specified name for the service.
78 Name string `json:"name"`
80 // Type will contain a type string if OpenStack defines a type for the
81 // service. Otherwise, for provider-specific services, the provider may assign
82 // their own type strings.
83 Type string `json:"type"`
85 // Endpoints will let the caller iterate over all the different endpoints that
86 // may exist for the service.
87 Endpoints []Endpoint `json:"endpoints"`
90 // ServiceCatalog provides a view into the service catalog from a previous,
91 // successful authentication.
92 type ServiceCatalog struct {
93 Entries []CatalogEntry
96 // CreateResult is the response from a Create request. Use ExtractToken() to
97 // interpret it as a Token, or ExtractServiceCatalog() to interpret it as a
99 type CreateResult struct {
103 // GetResult is the deferred response from a Get call, which is the same with a
104 // Created token. Use ExtractUser() to interpret it as a User.
105 type GetResult struct {
109 // ExtractToken returns the just-created Token from a CreateResult.
110 func (r CreateResult) ExtractToken() (*Token, error) {
114 Expires string `json:"expires"`
115 ID string `json:"id"`
116 Tenant tenants.Tenant `json:"tenant"`
121 err := r.ExtractInto(&s)
126 expiresTs, err := time.Parse(gophercloud.RFC3339Milli, s.Access.Token.Expires)
132 ID: s.Access.Token.ID,
133 ExpiresAt: expiresTs,
134 Tenant: s.Access.Token.Tenant,
138 // ExtractTokenID implements the gophercloud.AuthResult interface. The returned
139 // string is the same as the ID field of the Token struct returned from
141 func (r CreateResult) ExtractTokenID() (string, error) {
145 ID string `json:"id"`
149 err := r.ExtractInto(&s)
150 return s.Access.Token.ID, err
153 // ExtractServiceCatalog returns the ServiceCatalog that was generated along
154 // with the user's Token.
155 func (r CreateResult) ExtractServiceCatalog() (*ServiceCatalog, error) {
158 Entries []CatalogEntry `json:"serviceCatalog"`
161 err := r.ExtractInto(&s)
162 return &ServiceCatalog{Entries: s.Access.Entries}, err
165 // ExtractUser returns the User from a GetResult.
166 func (r GetResult) ExtractUser() (*User, error) {
169 User User `json:"user"`
172 err := r.ExtractInto(&s)
173 return &s.Access.User, err