Skip to content

Commit

Permalink
Add D&O interface
Browse files Browse the repository at this point in the history
  • Loading branch information
averevki committed Jun 12, 2024
1 parent 669fd89 commit 88a21f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 0 additions & 1 deletion testsuite/policy/authorization/auth_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def create_instance(
"metadata": {"name": name, "namespace": openshift.project, "labels": labels},
"spec": {
"targetRef": target.reference,
"rules": {},
},
}

Expand Down
12 changes: 10 additions & 2 deletions testsuite/policy/authorization/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,18 @@ def section(self):
"""The actual dict section which will be edited"""
return self.obj.auth_section.setdefault(self.section_name, {})

def add_item(self, name: str, value: dict, **common_features):
def add_item(self, name: str, value: dict, *, defaults: bool = False, overrides: bool = False, **common_features):
"""Adds item to the section"""
add_common_features(value, **common_features)
self.section.update({name: value})

if defaults:
section = self.obj.model.spec.setdefault("defaults", {}).setdefault("rules", {})
elif overrides:
section = self.obj.model.spec.setdefault("overrides", {}).setdefault("rules", {})
else:
section = self.section

section.setdefault(self.section_name, {})[name] = value

@modify
def clear_all(self):
Expand Down
13 changes: 11 additions & 2 deletions testsuite/policy/rate_limit_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def create_instance(cls, openshift: OpenShiftClient, name, target: Referencable,
"metadata": {"name": name, "labels": labels},
"spec": {
"targetRef": target.reference,
"limits": {},
},
}

Expand All @@ -66,6 +65,8 @@ def add_limit(
when: Iterable[Rule] = None,
counters: list[str] = None,
route_selectors: Iterable[RouteSelector] = None,
defaults: bool = False,
overrides: bool = False,
):
"""Add another limit"""
limit: dict = {
Expand All @@ -77,7 +78,15 @@ def add_limit(
limit["counters"] = counters
if route_selectors:
limit["routeSelectors"] = [asdict(rule) for rule in route_selectors]
self.model.spec.limits[name] = limit

if defaults:
section = self.model.spec.setdefault("defaults", {})
elif overrides:
section = self.model.spec.setdefault("overrides", {})
else:
section = self.model.spec

section.setdefault("limits", {})[name] = limit

def wait_for_ready(self):
"""Wait for RLP to be enforced"""
Expand Down

0 comments on commit 88a21f8

Please sign in to comment.