swift-ambulance-7102
01/15/2022, 8:59 PMfreezing-van-87649
01/15/2022, 9:03 PMswift-ambulance-7102
01/15/2022, 9:14 PMfreezing-van-87649
01/15/2022, 9:31 PMclass WorkloadRegistry:
workloads: Dict[str, WorkloadConfig] = {}
@staticmethod
def register(workload: WorkloadConfig):
if workload.name in WorkloadRegistry.workloads:
raise ValueError(f"Workload '{workload.name}' already registered")
WorkloadRegistry.workloads[workload.name] = workload
@staticmethod
def get(workload_name: str) -> WorkloadConfig:
if workload_name not in WorkloadRegistry.workloads:
raise ValueError(f"Workload '{workload_name} has not been registered")
return WorkloadRegistry.workloads[workload_name]
Workload definitions look like this:
@dataclass
class Environment:
name: str
"""The name of the environment."""
domains: List[str] = field(default_factory=lambda: [])
"""The list of domains associated with the account."""
@dataclass
class WorkloadConfig:
name: str
"""The name of the workload."""
gitlab_notifications_slack_channel: Optional[str]
"""
The name of the slack channel that gitlab slack notifications should be routed to.
Requires that @gitlab-notifications has been added to the channel.
"""
protected_branches: List[str]
"""The list of branches to protect for the workload."""
projects: List[str]
"""A list of GitLab project to create for the workload."""
admins: List[str] = field(default_factory=lambda: [])
"""
A list of users who are privileged users within the workload to add new developers/owners.
"""
admin_permission_sets: List[str] = field(
default_factory=lambda: ["xxx"]
)
"""
A list of permission sets that workload privileged users are given.
"""
developers: List[str] = field(default_factory=lambda: [])
"""
A list <first name>.<last name> of developers to grant access for the workload.
"""
prod_environments: List[Environment] = field(
default_factory=lambda: [Environment("production")]
)
dev_environments: List[Environment] = field(
default_factory=lambda: [Environment("development")]
)
And then we define the config objects and add them to the registry
WorkloadRegistry.register(
WorkloadConfig(
"sample-workload",
gitlab_notifications_slack_channel="#team-sample-workload",
projects=["sample-workload-app", "sample-workload-iac"],
protected_branches=[
"development",
"production",
],
dev_environments=[
Environment(
"development",
domains=[
"<http://dev.whatever.com|dev.whatever.com>",
],
),
Environment("demo", domains=["<http://demo.whatever.com|demo.whatever.com>"]),
],
prod_environments=[
Environment("production", domains=["<http://prod.whatever.com|prod.whatever.com>"]),
],
developers=[
"andrew.fitzgerald",
],
)
)
swift-ambulance-7102
01/15/2022, 9:34 PMfreezing-van-87649
01/15/2022, 9:39 PMbillowy-army-68599
01/15/2022, 11:52 PMfreezing-van-87649
01/15/2022, 11:53 PMswift-ambulance-7102
01/16/2022, 2:24 PMbored-table-20691
01/21/2022, 5:55 PMbillowy-army-68599
01/21/2022, 8:31 PMbored-table-20691
01/21/2022, 8:37 PMadamant-action-13876
02/16/2022, 8:20 PM