github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/elb/v3/l7policies/results.go (about)

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