github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/loadbalancer/v2/l7policies/results.go (about)

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