File: results.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.0~git20180917.45f1c769-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,768 kB
  • sloc: sh: 98; makefile: 14
file content (98 lines) | stat: -rw-r--r-- 2,993 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
package rbacpolicies

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

type commonResult struct {
	gophercloud.Result
}

// Extract is a function that accepts a result and extracts RBAC Policy resource.
func (r commonResult) Extract() (*RBACPolicy, error) {
	var s RBACPolicy
	err := r.ExtractInto(&s)
	return &s, err
}

func (r commonResult) ExtractInto(v interface{}) error {
	return r.Result.ExtractIntoStructPtr(v, "rbac_policy")
}

// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a RBAC Policy.
type CreateResult struct {
	commonResult
}

// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a RBAC Policy.
type GetResult struct {
	commonResult
}

// DeleteResult represents the result of a delete operation. Call its
// ExtractErr method to determine if the request succeeded or failed.
type DeleteResult struct {
	gophercloud.ErrResult
}

// UpdateResult represents the result of an update operation. Call its Extract
// method to interpret it as a RBAC Policy.
type UpdateResult struct {
	commonResult
}

// RBACPolicy represents a RBAC policy.
type RBACPolicy struct {
	// UUID of the RBAC policy.
	ID string `json:"id"`

	// Action for the RBAC policy which is access_as_external or access_as_shared.
	Action PolicyAction `json:"action"`

	// ObjectID is the ID of the object_type resource.
	// An object_type of network returns a network ID and
	// object_type of qos-policy returns a QoS ID.
	ObjectID string `json:"object_id"`

	// ObjectType is the type of the object that the RBAC policy affects.
	// Types include qos-policy or network.
	ObjectType string `json:"object_type"`

	// TenantID is the ID of the project that owns the resource.
	TenantID string `json:"tenant_id"`

	// TargetTenant is the ID of the tenant to which the RBAC policy will be enforced.
	TargetTenant string `json:"target_tenant"`

	// ProjectID is the ID of the project.
	ProjectID string `json:"project_id"`
}

// RBACPolicyPage is the page returned by a pager when traversing over a
// collection of rbac policies.
type RBACPolicyPage struct {
	pagination.LinkedPageBase
}

// IsEmpty checks whether a RBACPolicyPage struct is empty.
func (r RBACPolicyPage) IsEmpty() (bool, error) {
	is, err := ExtractRBACPolicies(r)
	return len(is) == 0, err
}

// ExtractRBACPolicies accepts a Page struct, specifically a RBAC Policy struct,
// and extracts the elements into a slice of RBAC Policy structs. In other words,
// a generic collection is mapped into a relevant slice.
func ExtractRBACPolicies(r pagination.Page) ([]RBACPolicy, error) {
	var s []RBACPolicy
	err := ExtractRBACPolicesInto(r, &s)
	return s, err
}

// ExtractRBACPolicesInto extracts the elements into a slice of RBAC Policy structs.
func ExtractRBACPolicesInto(r pagination.Page, v interface{}) error {
	return r.(RBACPolicyPage).Result.ExtractIntoSlicePtr(v, "rbac_policies")
}