File: results.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports
  • size: 10,224 kB
  • sloc: sh: 125; makefile: 21
file content (155 lines) | stat: -rw-r--r-- 4,024 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package trusts

import (
	"time"

	"github.com/gophercloud/gophercloud"
	"github.com/gophercloud/gophercloud/pagination"
)

type trustResult struct {
	gophercloud.Result
}

// CreateResult is the response from a Create operation. Call its Extract method
// to interpret it as a Trust.
type CreateResult struct {
	trustResult
}

// DeleteResult is the response from a Delete operation. Call its ExtractErr to
// determine if the request succeeded or failed.
type DeleteResult struct {
	gophercloud.ErrResult
}

// TrustPage is a single page of Region results.
type TrustPage struct {
	pagination.LinkedPageBase
}

// GetResult is the response from a Get operation. Call its Extract method
// to interpret it as a Trust.
type GetResult struct {
	trustResult
}

// IsEmpty determines whether or not a page of Trusts contains any results.
func (t TrustPage) IsEmpty() (bool, error) {
	roles, err := ExtractTrusts(t)
	return len(roles) == 0, err
}

// NextPageURL extracts the "next" link from the links section of the result.
func (t TrustPage) NextPageURL() (string, error) {
	var s struct {
		Links struct {
			Next     string `json:"next"`
			Previous string `json:"previous"`
		} `json:"links"`
	}
	err := t.ExtractInto(&s)
	if err != nil {
		return "", err
	}
	return s.Links.Next, err
}

// ExtractProjects returns a slice of Trusts contained in a single page of
// results.
func ExtractTrusts(r pagination.Page) ([]Trust, error) {
	var s struct {
		Trusts []Trust `json:"trusts"`
	}
	err := (r.(TrustPage)).ExtractInto(&s)
	return s.Trusts, err
}

// Extract interprets any trust result as a Trust.
func (t trustResult) Extract() (*Trust, error) {
	var s struct {
		Trust *Trust `json:"trust"`
	}
	err := t.ExtractInto(&s)
	return s.Trust, err
}

// Trust represents a delegated authorization request between two
// identities.
type Trust struct {
	ID                 string    `json:"id"`
	Impersonation      bool      `json:"impersonation"`
	TrusteeUserID      string    `json:"trustee_user_id"`
	TrustorUserID      string    `json:"trustor_user_id"`
	RedelegatedTrustID string    `json:"redelegated_trust_id"`
	RedelegationCount  int       `json:"redelegation_count,omitempty"`
	AllowRedelegation  bool      `json:"allow_redelegation,omitempty"`
	ProjectID          string    `json:"project_id,omitempty"`
	RemainingUses      int       `json:"remaining_uses,omitempty"`
	Roles              []Role    `json:"roles,omitempty"`
	DeletedAt          time.Time `json:"deleted_at"`
	ExpiresAt          time.Time `json:"expires_at"`
}

// Role specifies a single role that is granted to a trustee.
type Role struct {
	ID   string `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
}

// TokenExt represents an extension of the base token result.
type TokenExt struct {
	Trust Trust `json:"OS-TRUST:trust"`
}

// RolesPage is a single page of Trust roles results.
type RolesPage struct {
	pagination.LinkedPageBase
}

// IsEmpty determines whether or not a a Page contains any results.
func (r RolesPage) IsEmpty() (bool, error) {
	accessTokenRoles, err := ExtractRoles(r)
	return len(accessTokenRoles) == 0, err
}

// NextPageURL extracts the "next" link from the links section of the result.
func (r RolesPage) NextPageURL() (string, error) {
	var s struct {
		Links struct {
			Next     string `json:"next"`
			Previous string `json:"previous"`
		} `json:"links"`
	}
	err := r.ExtractInto(&s)
	if err != nil {
		return "", err
	}
	return s.Links.Next, err
}

// ExtractRoles returns a slice of Role contained in a single page of results.
func ExtractRoles(r pagination.Page) ([]Role, error) {
	var s struct {
		Roles []Role `json:"roles"`
	}
	err := (r.(RolesPage)).ExtractInto(&s)
	return s.Roles, err
}

type GetRoleResult struct {
	gophercloud.Result
}

// Extract interprets any GetRoleResult result as an Role.
func (r GetRoleResult) Extract() (*Role, error) {
	var s struct {
		Role *Role `json:"role"`
	}
	err := r.ExtractInto(&s)
	return s.Role, err
}

type CheckRoleResult struct {
	gophercloud.ErrResult
}