github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/rbacpolicies/results.go (about)

     1  package rbacpolicies
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  type commonResult struct {
     9  	gophercloud.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  	gophercloud.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  	// Tags optionally set via extensions/attributestags
    74  	Tags []string `json:"tags"`
    75  }
    76  
    77  // RBACPolicyPage is the page returned by a pager when traversing over a
    78  // collection of rbac policies.
    79  type RBACPolicyPage struct {
    80  	pagination.LinkedPageBase
    81  }
    82  
    83  // IsEmpty checks whether a RBACPolicyPage struct is empty.
    84  func (r RBACPolicyPage) IsEmpty() (bool, error) {
    85  	if r.StatusCode == 204 {
    86  		return true, nil
    87  	}
    88  
    89  	is, err := ExtractRBACPolicies(r)
    90  	return len(is) == 0, err
    91  }
    92  
    93  // ExtractRBACPolicies accepts a Page struct, specifically a RBAC Policy struct,
    94  // and extracts the elements into a slice of RBAC Policy structs. In other words,
    95  // a generic collection is mapped into a relevant slice.
    96  func ExtractRBACPolicies(r pagination.Page) ([]RBACPolicy, error) {
    97  	var s []RBACPolicy
    98  	err := ExtractRBACPolicesInto(r, &s)
    99  	return s, err
   100  }
   101  
   102  // ExtractRBACPolicesInto extracts the elements into a slice of RBAC Policy structs.
   103  func ExtractRBACPolicesInto(r pagination.Page, v interface{}) error {
   104  	return r.(RBACPolicyPage).Result.ExtractIntoSlicePtr(v, "rbac_policies")
   105  }