2024-09-02 16:22:59 +00:00
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
|
|
from frostfs_testlib.steps.cli.container import DEFAULT_PLACEMENT_RULE
|
|
|
|
from frostfs_testlib.storage.cluster import Cluster
|
2024-11-12 13:19:40 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses import ape
|
|
|
|
|
|
|
|
APE_PUBLIC_READ_WRITE = [ape.Rule(ape.Verb.ALLOW, ape.ObjectOperations.WILDCARD_ALL)]
|
2024-09-02 16:22:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class ContainerSpec:
|
|
|
|
rule: str = DEFAULT_PLACEMENT_RULE
|
2024-11-12 13:19:40 +00:00
|
|
|
# TODO: Deprecated
|
2024-09-02 16:22:59 +00:00
|
|
|
basic_acl: str = None
|
2024-11-12 13:19:40 +00:00
|
|
|
# TODO: Deprecated
|
2024-09-02 16:22:59 +00:00
|
|
|
allow_owner_via_ape: bool = False
|
2024-11-12 13:19:40 +00:00
|
|
|
ape_rules: list[ape.Rule] = None
|
|
|
|
|
|
|
|
def __post_init__(self):
|
|
|
|
if self.ape_rules is None:
|
|
|
|
self.ape_rules = []
|
2024-09-02 16:22:59 +00:00
|
|
|
|
|
|
|
def parsed_rule(self, cluster: Cluster):
|
|
|
|
if self.rule is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
substitutions = {"%NODE_COUNT%": str(len(cluster.cluster_nodes))}
|
|
|
|
|
|
|
|
parsed_rule = self.rule
|
|
|
|
for sub, replacement in substitutions.items():
|
|
|
|
parsed_rule = parsed_rule.replace(sub, replacement)
|
|
|
|
|
|
|
|
return parsed_rule
|
2024-11-12 13:19:40 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
spec_info: list[str] = []
|
|
|
|
|
|
|
|
if self.rule:
|
|
|
|
spec_info.append(f"rule='{self.rule}'")
|
|
|
|
if self.ape_rules:
|
|
|
|
ape_rules_list = ", ".join([f"'{rule.as_string()}'" for rule in self.ape_rules])
|
|
|
|
spec_info.append(f"ape_rules=[{ape_rules_list}]")
|
|
|
|
|
|
|
|
return f"ContainerSpec({', '.join(spec_info)})"
|
2024-11-13 14:50:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ContainerSpecs:
|
|
|
|
PublicReadWrite = ContainerSpec(ape_rules=APE_PUBLIC_READ_WRITE)
|