github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/rbacpolicies/results.go (about) 1 package rbacpolicies 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 type commonResult struct { 9 golangsdk.Result 10 } 11 12 // Extract is a function that accepts a result and extracts RBAC Policy resource. 13 func (r commonResult) Extract() (*RBACPolicy, error) { 14 var s RBACPolicy 15 err := r.ExtractInto(&s) 16 return &s, err 17 } 18 19 func (r commonResult) ExtractInto(v interface{}) error { 20 return r.Result.ExtractIntoStructPtr(v, "rbac_policy") 21 } 22 23 // CreateResult represents the result of a create operation. Call its Extract 24 // method to interpret it as a RBAC Policy. 25 type CreateResult struct { 26 commonResult 27 } 28 29 // GetResult represents the result of a get operation. Call its Extract 30 // method to interpret it as a RBAC Policy. 31 type GetResult struct { 32 commonResult 33 } 34 35 // DeleteResult represents the result of a delete operation. Call its 36 // ExtractErr method to determine if the request succeeded or failed. 37 type DeleteResult struct { 38 golangsdk.ErrResult 39 } 40 41 // UpdateResult represents the result of an update operation. Call its Extract 42 // method to interpret it as a RBAC Policy. 43 type UpdateResult struct { 44 commonResult 45 } 46 47 // RBACPolicy represents a RBAC policy. 48 type RBACPolicy struct { 49 // UUID of the RBAC policy. 50 ID string `json:"id"` 51 52 // Action for the RBAC policy which is access_as_external or access_as_shared. 53 Action PolicyAction `json:"action"` 54 55 // ObjectID is the ID of the object_type resource. 56 // An object_type of network returns a network ID and 57 // object_type of qos-policy returns a QoS ID. 58 ObjectID string `json:"object_id"` 59 60 // ObjectType is the type of the object that the RBAC policy affects. 61 // Types include qos-policy or network. 62 ObjectType string `json:"object_type"` 63 64 // TenantID is the ID of the project that owns the resource. 65 TenantID string `json:"tenant_id"` 66 67 // TargetTenant is the ID of the tenant to which the RBAC policy will be enforced. 68 TargetTenant string `json:"target_tenant"` 69 70 // ProjectID is the ID of the project. 71 ProjectID string `json:"project_id"` 72 } 73 74 // RBACPolicyPage is the page returned by a pager when traversing over a 75 // collection of rbac policies. 76 type RBACPolicyPage struct { 77 pagination.LinkedPageBase 78 } 79 80 // IsEmpty checks whether a RBACPolicyPage struct is empty. 81 func (r RBACPolicyPage) IsEmpty() (bool, error) { 82 is, err := ExtractRBACPolicies(r) 83 return len(is) == 0, err 84 } 85 86 // ExtractRBACPolicies accepts a Page struct, specifically a RBAC Policy struct, 87 // and extracts the elements into a slice of RBAC Policy structs. In other words, 88 // a generic collection is mapped into a relevant slice. 89 func ExtractRBACPolicies(r pagination.Page) ([]RBACPolicy, error) { 90 var s []RBACPolicy 91 err := ExtractRBACPolicesInto(r, &s) 92 return s, err 93 } 94 95 // ExtractRBACPolicesInto extracts the elements into a slice of RBAC Policy structs. 96 func ExtractRBACPolicesInto(r pagination.Page, v interface{}) error { 97 return r.(RBACPolicyPage).Result.ExtractIntoSlicePtr(v, "rbac_policies") 98 }