github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3/tokens/results.go (about) 1 package tokens 2 3 import ( 4 "time" 5 6 "github.com/huaweicloud/golangsdk" 7 ) 8 9 // Endpoint represents a single API endpoint offered by a service. 10 // It matches either a public, internal or admin URL. 11 // If supported, it contains a region specifier, again if provided. 12 // The significance of the Region field will depend upon your provider. 13 type Endpoint struct { 14 ID string `json:"id"` 15 Region string `json:"region"` 16 Interface string `json:"interface"` 17 URL string `json:"url"` 18 } 19 20 // CatalogEntry provides a type-safe interface to an Identity API V3 service 21 // catalog listing. Each class of service, such as cloud DNS or block storage 22 // services, could have multiple CatalogEntry representing it (one by interface 23 // type, e.g public, admin or internal). 24 // 25 // Note: when looking for the desired service, try, whenever possible, to key 26 // off the type field. Otherwise, you'll tie the representation of the service 27 // to a specific provider. 28 type CatalogEntry struct { 29 // Service ID 30 ID string `json:"id"` 31 32 // Name will contain the provider-specified name for the service. 33 Name string `json:"name"` 34 35 // Type will contain a type string if OpenStack defines a type for the 36 // service. Otherwise, for provider-specific services, the provider may 37 // assign their own type strings. 38 Type string `json:"type"` 39 40 // Endpoints will let the caller iterate over all the different endpoints that 41 // may exist for the service. 42 Endpoints []Endpoint `json:"endpoints"` 43 } 44 45 // ServiceCatalog provides a view into the service catalog from a previous, 46 // successful authentication. 47 type ServiceCatalog struct { 48 Entries []CatalogEntry `json:"catalog"` 49 } 50 51 // Domain provides information about the domain to which this token grants 52 // access. 53 type Domain struct { 54 ID string `json:"id"` 55 Name string `json:"name"` 56 } 57 58 // User represents a user resource that exists in the Identity Service. 59 type User struct { 60 Domain Domain `json:"domain"` 61 ID string `json:"id"` 62 Name string `json:"name"` 63 } 64 65 // Role provides information about roles to which User is authorized. 66 type Role struct { 67 ID string `json:"id"` 68 Name string `json:"name"` 69 } 70 71 // Project provides information about project to which User is authorized. 72 type Project struct { 73 Domain Domain `json:"domain"` 74 ID string `json:"id"` 75 Name string `json:"name"` 76 } 77 78 // commonResult is the response from a request. A commonResult has various 79 // methods which can be used to extract different details about the result. 80 type commonResult struct { 81 golangsdk.Result 82 } 83 84 // Extract is a shortcut for ExtractToken. 85 // This function is deprecated and still present for backward compatibility. 86 func (r commonResult) Extract() (*Token, error) { 87 return r.ExtractToken() 88 } 89 90 // ExtractToken interprets a commonResult as a Token. 91 func (r commonResult) ExtractToken() (*Token, error) { 92 var s Token 93 err := r.ExtractInto(&s) 94 if err != nil { 95 return nil, err 96 } 97 98 // Parse the token itself from the stored headers. 99 s.ID = r.Header.Get("X-Subject-Token") 100 101 return &s, err 102 } 103 104 // ExtractServiceCatalog returns the ServiceCatalog that was generated along 105 // with the user's Token. 106 func (r commonResult) ExtractServiceCatalog() (*ServiceCatalog, error) { 107 var s ServiceCatalog 108 err := r.ExtractInto(&s) 109 return &s, err 110 } 111 112 // ExtractUser returns the User that is the owner of the Token. 113 func (r commonResult) ExtractUser() (*User, error) { 114 var s struct { 115 User *User `json:"user"` 116 } 117 err := r.ExtractInto(&s) 118 return s.User, err 119 } 120 121 // ExtractRoles returns Roles to which User is authorized. 122 func (r commonResult) ExtractRoles() ([]Role, error) { 123 var s struct { 124 Roles []Role `json:"roles"` 125 } 126 err := r.ExtractInto(&s) 127 return s.Roles, err 128 } 129 130 // ExtractProject returns Project to which User is authorized. 131 func (r commonResult) ExtractProject() (*Project, error) { 132 var s struct { 133 Project *Project `json:"project"` 134 } 135 err := r.ExtractInto(&s) 136 return s.Project, err 137 } 138 139 // CreateResult is the response from a Create request. Use ExtractToken() 140 // to interpret it as a Token, or ExtractServiceCatalog() to interpret it 141 // as a service catalog. 142 type CreateResult struct { 143 commonResult 144 } 145 146 // GetResult is the response from a Get request. Use ExtractToken() 147 // to interpret it as a Token, or ExtractServiceCatalog() to interpret it 148 // as a service catalog. 149 type GetResult struct { 150 commonResult 151 } 152 153 // RevokeResult is response from a Revoke request. 154 type RevokeResult struct { 155 commonResult 156 } 157 158 // Token is a string that grants a user access to a controlled set of services 159 // in an OpenStack provider. Each Token is valid for a set length of time. 160 type Token struct { 161 // ID is the issued token. 162 ID string `json:"id"` 163 164 // ExpiresAt is the timestamp at which this token will no longer be accepted. 165 ExpiresAt time.Time `json:"expires_at"` 166 } 167 168 func (r commonResult) ExtractInto(v interface{}) error { 169 return r.ExtractIntoStructPtr(v, "token") 170 }