github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v3/extensions/trusts/results.go (about) 1 package trusts 2 3 import ( 4 "time" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/pagination" 8 ) 9 10 type trustResult struct { 11 gophercloud.Result 12 } 13 14 // CreateResult is the response from a Create operation. Call its Extract method 15 // to interpret it as a Trust. 16 type CreateResult struct { 17 trustResult 18 } 19 20 // DeleteResult is the response from a Delete operation. Call its ExtractErr to 21 // determine if the request succeeded or failed. 22 type DeleteResult struct { 23 gophercloud.ErrResult 24 } 25 26 // TrustPage is a single page of Region results. 27 type TrustPage struct { 28 pagination.LinkedPageBase 29 } 30 31 // GetResult is the response from a Get operation. Call its Extract method 32 // to interpret it as a Trust. 33 type GetResult struct { 34 trustResult 35 } 36 37 // IsEmpty determines whether or not a page of Trusts contains any results. 38 func (t TrustPage) IsEmpty() (bool, error) { 39 if t.StatusCode == 204 { 40 return true, nil 41 } 42 43 roles, err := ExtractTrusts(t) 44 return len(roles) == 0, err 45 } 46 47 // NextPageURL extracts the "next" link from the links section of the result. 48 func (t TrustPage) NextPageURL() (string, error) { 49 var s struct { 50 Links struct { 51 Next string `json:"next"` 52 Previous string `json:"previous"` 53 } `json:"links"` 54 } 55 err := t.ExtractInto(&s) 56 if err != nil { 57 return "", err 58 } 59 return s.Links.Next, err 60 } 61 62 // ExtractProjects returns a slice of Trusts contained in a single page of 63 // results. 64 func ExtractTrusts(r pagination.Page) ([]Trust, error) { 65 var s struct { 66 Trusts []Trust `json:"trusts"` 67 } 68 err := (r.(TrustPage)).ExtractInto(&s) 69 return s.Trusts, err 70 } 71 72 // Extract interprets any trust result as a Trust. 73 func (t trustResult) Extract() (*Trust, error) { 74 var s struct { 75 Trust *Trust `json:"trust"` 76 } 77 err := t.ExtractInto(&s) 78 return s.Trust, err 79 } 80 81 // Trust represents a delegated authorization request between two 82 // identities. 83 type Trust struct { 84 ID string `json:"id"` 85 Impersonation bool `json:"impersonation"` 86 TrusteeUserID string `json:"trustee_user_id"` 87 TrustorUserID string `json:"trustor_user_id"` 88 RedelegatedTrustID string `json:"redelegated_trust_id"` 89 RedelegationCount int `json:"redelegation_count,omitempty"` 90 AllowRedelegation bool `json:"allow_redelegation,omitempty"` 91 ProjectID string `json:"project_id,omitempty"` 92 RemainingUses int `json:"remaining_uses,omitempty"` 93 Roles []Role `json:"roles,omitempty"` 94 DeletedAt time.Time `json:"deleted_at"` 95 ExpiresAt time.Time `json:"expires_at"` 96 } 97 98 // Role specifies a single role that is granted to a trustee. 99 type Role struct { 100 ID string `json:"id,omitempty"` 101 Name string `json:"name,omitempty"` 102 } 103 104 // TokenExt represents an extension of the base token result. 105 type TokenExt struct { 106 Trust Trust `json:"OS-TRUST:trust"` 107 } 108 109 // RolesPage is a single page of Trust roles results. 110 type RolesPage struct { 111 pagination.LinkedPageBase 112 } 113 114 // IsEmpty determines whether or not a a Page contains any results. 115 func (r RolesPage) IsEmpty() (bool, error) { 116 if r.StatusCode == 204 { 117 return true, nil 118 } 119 120 accessTokenRoles, err := ExtractRoles(r) 121 return len(accessTokenRoles) == 0, err 122 } 123 124 // NextPageURL extracts the "next" link from the links section of the result. 125 func (r RolesPage) NextPageURL() (string, error) { 126 var s struct { 127 Links struct { 128 Next string `json:"next"` 129 Previous string `json:"previous"` 130 } `json:"links"` 131 } 132 err := r.ExtractInto(&s) 133 if err != nil { 134 return "", err 135 } 136 return s.Links.Next, err 137 } 138 139 // ExtractRoles returns a slice of Role contained in a single page of results. 140 func ExtractRoles(r pagination.Page) ([]Role, error) { 141 var s struct { 142 Roles []Role `json:"roles"` 143 } 144 err := (r.(RolesPage)).ExtractInto(&s) 145 return s.Roles, err 146 } 147 148 type GetRoleResult struct { 149 gophercloud.Result 150 } 151 152 // Extract interprets any GetRoleResult result as an Role. 153 func (r GetRoleResult) Extract() (*Role, error) { 154 var s struct { 155 Role *Role `json:"role"` 156 } 157 err := r.ExtractInto(&s) 158 return s.Role, err 159 } 160 161 type CheckRoleResult struct { 162 gophercloud.ErrResult 163 }