From 4709c6621099f06ef9ad78e6533a0c4d23151f81 Mon Sep 17 00:00:00 2001 From: Jakub Smolar Date: Mon, 8 Jan 2024 16:41:43 +0100 Subject: [PATCH] Add Route Selector for Rate Limit --- testsuite/policy/rate_limit_policy.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/testsuite/policy/rate_limit_policy.py b/testsuite/policy/rate_limit_policy.py index 9343fa0a..6dfa60a1 100644 --- a/testsuite/policy/rate_limit_policy.py +++ b/testsuite/policy/rate_limit_policy.py @@ -1,13 +1,13 @@ """RateLimitPolicy related objects""" -from dataclasses import dataclass +from dataclasses import dataclass, field from time import sleep -from typing import Iterable, Literal, Optional +from typing import Iterable, Literal, Optional, List import openshift as oc from testsuite.policy.authorization import Rule from testsuite.utils import asdict -from testsuite.gateway import Referencable, HTTPMatcher +from testsuite.gateway import Referencable, RouteMatch from testsuite.openshift.client import OpenShiftClient from testsuite.openshift import OpenShiftObject, modify @@ -22,15 +22,21 @@ class Limit: @dataclass -class RouteSelect: +class RouteSelector: """ - HTRTPPathMatch, HTTPHeaderMatch, HTTPQueryParamMatch, HTTPMethodMatch + RouteSelector is an object composed of a set of HTTPRouteMatch objects (from Gateway API - + HTRTPPathMatch, HTTPHeaderMatch, HTTPQueryParamMatch, HTTPMethodMatch), + and an additional hostnames field. https://docs.kuadrant.io/kuadrant-operator/doc/reference/route-selectors/#routeselector """ - matches: Optional[list[HTTPMatcher]] = None + matches: Optional[list[RouteMatch]] = None hostnames: Optional[list[str]] = None + def __init__(self, *matches: RouteMatch, hostnames: Optional[List[str]] = None): + self.matches = list(matches) if matches else [] + self.hostnames = hostnames + class RateLimitPolicy(OpenShiftObject): """RateLimitPolicy (or RLP for short) object, used for applying rate limiting rules to a Gateway/HTTPRoute""" @@ -57,7 +63,7 @@ def add_limit( limits: Iterable[Limit], when: Iterable[Rule] = None, counters: list[str] = None, - route_selectors: Iterable[RouteSelect] = None, + route_selectors: Iterable[RouteSelector] = None, ): """Add another limit""" limit: dict = {