Skip to content

Commit

Permalink
Add Route Selector for Rate Limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Smolar committed Jan 8, 2024
1 parent 8faf70c commit 4709c66
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions testsuite/policy/rate_limit_policy.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"""
Expand All @@ -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 = {
Expand Down

0 comments on commit 4709c66

Please sign in to comment.