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

     1  package l7policies
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // L7Policy is a collection of L7 rules associated with a Listener, and which
     9  // may also have an association to a back-end pool.
    10  type L7Policy struct {
    11  	// The unique ID for the L7 policy.
    12  	ID string `json:"id"`
    13  
    14  	// Name of the L7 policy.
    15  	Name string `json:"name"`
    16  
    17  	// The ID of the listener.
    18  	ListenerID string `json:"listener_id"`
    19  
    20  	// The L7 policy action. One of REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT.
    21  	Action string `json:"action"`
    22  
    23  	// The position of this policy on the listener.
    24  	Position int32 `json:"position"`
    25  
    26  	// A human-readable description for the resource.
    27  	Description string `json:"description"`
    28  
    29  	// TenantID is the UUID of the tenant who owns the L7 policy in octavia.
    30  	// Only administrative users can specify a project UUID other than their own.
    31  	TenantID string `json:"tenant_id"`
    32  
    33  	// Requests matching this policy will be redirected to the pool with this ID.
    34  	// Only valid if action is REDIRECT_TO_POOL.
    35  	RedirectPoolID string `json:"redirect_pool_id"`
    36  
    37  	// Requests matching this policy will be redirected to this Listener.
    38  	// Only valid if action is REDIRECT_TO_LISTENER.
    39  	RedirectListenerID string `json:"redirect_listener_id"`
    40  
    41  	// The administrative state of the L7 policy, which is up (true) or down (false).
    42  	AdminStateUp bool `json:"admin_state_up"`
    43  
    44  	// The provisioning status of the L7 policy.
    45  	// This value is ACTIVE, PENDING_* or ERROR.
    46  	// This field seems to only be returned during a call to a load balancer's /status
    47  	// see: https://github.com/gophercloud/gophercloud/issues/1362
    48  	ProvisioningStatus string `json:"provisioning_status"`
    49  
    50  	// The operating status of the L7 policy.
    51  	// This field seems to only be returned during a call to a load balancer's /status
    52  	// see: https://github.com/gophercloud/gophercloud/issues/1362
    53  	OperatingStatus string `json:"operating_status"`
    54  
    55  	// Rules are List of associated L7 rule IDs.
    56  	Rules []Rule `json:"rules"`
    57  }
    58  
    59  // Rule represents layer 7 load balancing rule.
    60  type Rule struct {
    61  	// The unique ID for the L7 rule.
    62  	ID string `json:"id"`
    63  
    64  	// The L7 rule type. One of COOKIE, FILE_TYPE, HEADER, HOST_NAME, or PATH.
    65  	RuleType string `json:"type"`
    66  
    67  	// The comparison type for the L7 rule. One of CONTAINS, ENDS_WITH, EQUAL_TO, REGEX, or STARTS_WITH.
    68  	CompareType string `json:"compare_type"`
    69  
    70  	// The value to use for the comparison. For example, the file type to compare.
    71  	Value string `json:"value"`
    72  
    73  	// TenantID is the UUID of the tenant who owns the rule in octavia.
    74  	// Only administrative users can specify a project UUID other than their own.
    75  	TenantID string `json:"tenant_id"`
    76  
    77  	// The key to use for the comparison. For example, the name of the cookie to evaluate.
    78  	Key string `json:"key"`
    79  
    80  	// When true the logic of the rule is inverted. For example, with invert true,
    81  	// equal to would become not equal to. Default is false.
    82  	Invert bool `json:"invert"`
    83  
    84  	// The administrative state of the L7 rule, which is up (true) or down (false).
    85  	AdminStateUp bool `json:"admin_state_up"`
    86  
    87  	// The provisioning status of the L7 rule.
    88  	// This value is ACTIVE, PENDING_* or ERROR.
    89  	// This field seems to only be returned during a call to a load balancer's /status
    90  	// see: https://github.com/gophercloud/gophercloud/issues/1362
    91  	ProvisioningStatus string `json:"provisioning_status"`
    92  
    93  	// The operating status of the L7 policy.
    94  	// This field seems to only be returned during a call to a load balancer's /status
    95  	// see: https://github.com/gophercloud/gophercloud/issues/1362
    96  	OperatingStatus string `json:"operating_status"`
    97  }
    98  
    99  type commonResult struct {
   100  	golangsdk.Result
   101  }
   102  
   103  // Extract is a function that accepts a result and extracts a l7policy.
   104  func (r commonResult) Extract() (*L7Policy, error) {
   105  	var s struct {
   106  		L7Policy *L7Policy `json:"l7policy"`
   107  	}
   108  	err := r.ExtractInto(&s)
   109  	return s.L7Policy, err
   110  }
   111  
   112  // CreateResult represents the result of a Create operation. Call its Extract
   113  // method to interpret the result as a L7Policy.
   114  type CreateResult struct {
   115  	commonResult
   116  }
   117  
   118  // L7PolicyPage is the page returned by a pager when traversing over a
   119  // collection of l7policies.
   120  type L7PolicyPage struct {
   121  	pagination.LinkedPageBase
   122  }
   123  
   124  // NextPageURL is invoked when a paginated collection of l7policies has reached
   125  // the end of a page and the pager seeks to traverse over a new one. In order
   126  // to do this, it needs to construct the next page's URL.
   127  func (r L7PolicyPage) NextPageURL() (string, error) {
   128  	var s struct {
   129  		Links []golangsdk.Link `json:"l7policies_links"`
   130  	}
   131  	err := r.ExtractInto(&s)
   132  	if err != nil {
   133  		return "", err
   134  	}
   135  	return golangsdk.ExtractNextURL(s.Links)
   136  }
   137  
   138  // IsEmpty checks whether a L7PolicyPage struct is empty.
   139  func (r L7PolicyPage) IsEmpty() (bool, error) {
   140  	is, err := ExtractL7Policies(r)
   141  	return len(is) == 0, err
   142  }
   143  
   144  // ExtractL7Policies accepts a Page struct, specifically a L7PolicyPage struct,
   145  // and extracts the elements into a slice of L7Policy structs. In other words,
   146  // a generic collection is mapped into a relevant slice.
   147  func ExtractL7Policies(r pagination.Page) ([]L7Policy, error) {
   148  	var s struct {
   149  		L7Policies []L7Policy `json:"l7policies"`
   150  	}
   151  	err := (r.(L7PolicyPage)).ExtractInto(&s)
   152  	return s.L7Policies, err
   153  }
   154  
   155  // GetResult represents the result of a Get operation. Call its Extract
   156  // method to interpret the result as a L7Policy.
   157  type GetResult struct {
   158  	commonResult
   159  }
   160  
   161  // DeleteResult represents the result of a Delete operation. Call its
   162  // ExtractErr method to determine if the request succeeded or failed.
   163  type DeleteResult struct {
   164  	golangsdk.ErrResult
   165  }
   166  
   167  // UpdateResult represents the result of an Update operation. Call its Extract
   168  // method to interpret the result as a L7Policy.
   169  type UpdateResult struct {
   170  	commonResult
   171  }
   172  
   173  type commonRuleResult struct {
   174  	golangsdk.Result
   175  }
   176  
   177  // Extract is a function that accepts a result and extracts a rule.
   178  func (r commonRuleResult) Extract() (*Rule, error) {
   179  	var s struct {
   180  		Rule *Rule `json:"rule"`
   181  	}
   182  	err := r.ExtractInto(&s)
   183  	return s.Rule, err
   184  }
   185  
   186  // CreateRuleResult represents the result of a CreateRule operation.
   187  // Call its Extract method to interpret it as a Rule.
   188  type CreateRuleResult struct {
   189  	commonRuleResult
   190  }
   191  
   192  // RulePage is the page returned by a pager when traversing over a
   193  // collection of Rules in a L7Policy.
   194  type RulePage struct {
   195  	pagination.LinkedPageBase
   196  }
   197  
   198  // NextPageURL is invoked when a paginated collection of rules has reached
   199  // the end of a page and the pager seeks to traverse over a new one. In order
   200  // to do this, it needs to construct the next page's URL.
   201  func (r RulePage) NextPageURL() (string, error) {
   202  	var s struct {
   203  		Links []golangsdk.Link `json:"rules_links"`
   204  	}
   205  	err := r.ExtractInto(&s)
   206  	if err != nil {
   207  		return "", err
   208  	}
   209  	return golangsdk.ExtractNextURL(s.Links)
   210  }
   211  
   212  // IsEmpty checks whether a RulePage struct is empty.
   213  func (r RulePage) IsEmpty() (bool, error) {
   214  	is, err := ExtractRules(r)
   215  	return len(is) == 0, err
   216  }
   217  
   218  // ExtractRules accepts a Page struct, specifically a RulePage struct,
   219  // and extracts the elements into a slice of Rules structs. In other words,
   220  // a generic collection is mapped into a relevant slice.
   221  func ExtractRules(r pagination.Page) ([]Rule, error) {
   222  	var s struct {
   223  		Rules []Rule `json:"rules"`
   224  	}
   225  	err := (r.(RulePage)).ExtractInto(&s)
   226  	return s.Rules, err
   227  }
   228  
   229  // GetRuleResult represents the result of a GetRule operation.
   230  // Call its Extract method to interpret it as a Rule.
   231  type GetRuleResult struct {
   232  	commonRuleResult
   233  }
   234  
   235  // DeleteRuleResult represents the result of a DeleteRule operation.
   236  // Call its ExtractErr method to determine if the request succeeded or failed.
   237  type DeleteRuleResult struct {
   238  	golangsdk.ErrResult
   239  }
   240  
   241  // UpdateRuleResult represents the result of an UpdateRule operation.
   242  // Call its Extract method to interpret it as a Rule.
   243  type UpdateRuleResult struct {
   244  	commonRuleResult
   245  }