github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/rms/v1/policyassignments/results.go (about)

     1  package policyassignments
     2  
     3  import "github.com/chnsz/golangsdk/pagination"
     4  
     5  // Assignment is the structure that represents the detail of the policy assignment.
     6  type Assignment struct {
     7  	// The type of the policy assignment.
     8  	Type string `json:"policy_assignment_type"`
     9  	// The ID of the policy assignment.
    10  	ID string `json:"id"`
    11  	// The name of the policy assignment.
    12  	Name string `json:"name"`
    13  	// The description of the policy assignment.
    14  	Description string `json:"description"`
    15  	// The configuration used to filter resources.
    16  	PolicyFilter PolicyFilter `json:"policy_filter"`
    17  	// The period of the policy rule check.
    18  	Period string `json:"period"`
    19  	// The status of the policy assignment.
    20  	Status string `json:"state"`
    21  	// The ID of the policy definition.
    22  	PolicyDefinitionId string `json:"policy_definition_id"`
    23  	// The configuration of the custom policy.
    24  	CustomPolicy CustomPolicy `json:"custom_policy"`
    25  	// The rule definition of the policy assignment.
    26  	Parameters map[string]PolicyParameterValue `json:"parameters"`
    27  	// The creation time of the policy assignment.
    28  	CreatedAt string `json:"created"`
    29  	// The latest update time of the policy assignment.
    30  	UpdatedAt string `json:"updated"`
    31  }
    32  
    33  // listDefinitionResp is the structure that represents the page details of the built-in policy definitions.
    34  type listDefinitionResp struct {
    35  	Definitions []PolicyDefinition `json:"value"`
    36  	// The information of the current query page.
    37  	PageInfo pageInfo `json:"page_info"`
    38  }
    39  
    40  // PolicyDefinition is the structure that represents the details of the built-in policy definition.
    41  type PolicyDefinition struct {
    42  	// The ID of the policy definition.
    43  	ID string `json:"id"`
    44  	// The name of the policy definition.
    45  	Name string `json:"name"`
    46  	// The policy type of the policy definition.
    47  	PolicyType string `json:"policy_type"`
    48  	// The description of the policy definition.
    49  	Description string `json:"description"`
    50  	// The rule type of the policy definition.
    51  	PolicyRuleType string `json:"policy_rule_type"`
    52  	// The rule details of the policy definition.
    53  	PolicyRule interface{} `json:"policy_rule"`
    54  	// The trigger type of the policy definition.
    55  	TriggerType string `json:"trigger_type"`
    56  	// The keywords that policy definition has.
    57  	Keywords []string `json:"keywords"`
    58  	// The parameters of the policy definition.
    59  	Parameters map[string]PolicyParameterDefinition `json:"parameters"`
    60  }
    61  
    62  // PolicyParameterDefinition is the structure that represents the parameter configuration.
    63  type PolicyParameterDefinition struct {
    64  	// The name of the parameter definition.
    65  	Name string `json:"name"`
    66  	// The description of the parameter definition.
    67  	Description string `json:"description"`
    68  	// The allow value list of the parameter definition.
    69  	AllowedValues []interface{} `json:"allowed_values"`
    70  	// The default value of the parameter definition.m
    71  	DefaultValue string `json:"default_value"`
    72  	// The type of the parameter definition.
    73  	Type string `json:"type"`
    74  }
    75  
    76  // pageInfo is the structure that represents the information of the policy definition page.
    77  type pageInfo struct {
    78  	// The policy definition count of the current page.
    79  	CurrentCount int `json:"current_count"`
    80  	// The next marker of the policy definition page.
    81  	NextMarker string `json:"next_marker"`
    82  }
    83  
    84  // DefinitionPage represents the response pages of the List method.
    85  type DefinitionPage struct {
    86  	pagination.MarkerPageBase
    87  }
    88  
    89  // IsEmpty returns true if a query result no policy definition.
    90  func (r DefinitionPage) IsEmpty() (bool, error) {
    91  	resp, err := extractDefinitions(r)
    92  	return len(resp) == 0, err
    93  }
    94  
    95  // LastMarker returns the last marker index in a query result.
    96  func (r DefinitionPage) LastMarker() (string, error) {
    97  	resp, err := extractPageInfo(r)
    98  	if err != nil {
    99  		return "", err
   100  	}
   101  	if resp.NextMarker != "" {
   102  		return "", nil
   103  	}
   104  	return resp.NextMarker, nil
   105  }
   106  
   107  // extractPageInfo is a method which to extract the response of the page information.
   108  func extractPageInfo(r pagination.Page) (*pageInfo, error) {
   109  	var s listDefinitionResp
   110  	err := r.(DefinitionPage).Result.ExtractInto(&s)
   111  	return &s.PageInfo, err
   112  }
   113  
   114  // extractDefinitions is a method which to extract the response to a policy definition list.
   115  func extractDefinitions(r pagination.Page) ([]PolicyDefinition, error) {
   116  	var s listDefinitionResp
   117  	err := r.(DefinitionPage).Result.ExtractInto(&s)
   118  	return s.Definitions, err
   119  }