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