github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/cbr/v3/policies/results.go (about)

     1  package policies
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/huaweicloud/golangsdk"
     7  	"github.com/huaweicloud/golangsdk/pagination"
     8  )
     9  
    10  type commonResult struct {
    11  	golangsdk.Result
    12  }
    13  
    14  type CreateResult struct {
    15  	commonResult
    16  }
    17  
    18  type GetResult struct {
    19  	commonResult
    20  }
    21  
    22  type UpdateResult struct {
    23  	commonResult
    24  }
    25  
    26  type DeleteResult struct {
    27  	golangsdk.ErrResult
    28  }
    29  
    30  type Policy struct {
    31  	ID                  string                 `json:"id"`
    32  	Name                string                 `json:"name"`
    33  	Enabled             bool                   `json:"enabled"`
    34  	OperationDefinition *PolicyODCreate        `json:"operation_definition"`
    35  	OperationType       string                 `json:"operation_type"`
    36  	Trigger             *PolicyTriggerResp     `json:"trigger"`
    37  	AssociatedVaults    []PolicyAssociateVault `json:"associated_vaults"`
    38  }
    39  
    40  type PolicyTriggerResp struct {
    41  	TriggerID  string                      `json:"id"`
    42  	Name       string                      `json:"name"`
    43  	Type       string                      `json:"type"`
    44  	Properties PolicyTriggerPropertiesResp `json:"properties"`
    45  }
    46  
    47  type PolicyTriggerPropertiesResp struct {
    48  	Pattern   []string `json:"pattern"`
    49  	StartTime string   `json:"start_time"`
    50  }
    51  
    52  type PolicyAssociateVault struct {
    53  	VaultID            string `json:"vault_id"`
    54  	DestinationVaultID string `json:"destination_vault_id"`
    55  }
    56  
    57  func (r commonResult) Extract() (*Policy, error) {
    58  	var s struct {
    59  		Policy *Policy `json:"policy"`
    60  	}
    61  	if r.Err != nil {
    62  		return nil, r.Err
    63  	}
    64  	err := r.ExtractInto(&s)
    65  	if err != nil {
    66  		return nil, fmt.Errorf("error extracting policy from create response: %s", err)
    67  	}
    68  	return s.Policy, err
    69  }
    70  
    71  type PolicyPage struct {
    72  	pagination.SinglePageBase
    73  }
    74  
    75  func ExtractPolicies(r pagination.Page) ([]Policy, error) {
    76  	var s []Policy
    77  	err := r.(PolicyPage).Result.ExtractIntoSlicePtr(&s, "policies")
    78  	if err != nil {
    79  		return nil, err
    80  	}
    81  	return s, nil
    82  }