Skip to content

Commit

Permalink
Merge 16a7463 into 0155d21
Browse files Browse the repository at this point in the history
  • Loading branch information
calumabarnett committed Jul 8, 2020
2 parents 0155d21 + 16a7463 commit 0fa3dff
Showing 1 changed file with 41 additions and 36 deletions.
77 changes: 41 additions & 36 deletions dataengineeringutils3/pulumi.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
def check_business_unit(business_unit: str):
"""Checks if business_unit is valid.
Parameters
----------
business_unit : str
The business unit of the team that owns the resources. This should be one of
"HQ", "HMPPS", "OPG", "LAA", "HMCTS", "CICA", "Platforms".
Raises
------
ValueError
If the value of business_unit is valid a ValueError will be raised.
"""
if business_unit not in [
"HQ",
"HMPPS",
"OPG",
"LAA",
"HMCTS",
"CICA",
"Platforms",
]:
raise ValueError(
"business_unit must be one of HQ, HMPPS, OPG, LAA, HMCTS, CICA, or "
"Platforms"
)


class Tagger:
def __init__(
self,
environment_name: str,
business_unit: str = "Platforms",
allowed_business_units: list = [
"HQ",
"HMPPS",
"OPG",
"LAA",
"HMCTS",
"CICA",
"Platforms",
],
application: str = "Data Engineering",
owner: str = "Data Engineering:dataengineering@digital.justice.gov.uk",
**kwargs
**kwargs,
):
"""
Provides a Tagger resource.
Expand All @@ -45,9 +25,12 @@ def __init__(
The name of the environment in which resources are deployed, for example,
"alpha", "prod" or "dev".
business_unit : str, optional
The business unit of the team that owns the resources. This should be one of
"HQ", "HMPPS", "OPG", "LAA", "HMCTS", "CICA", "Platforms".
The business unit of the team that owns the resources. Should be one of
allowed_business_units.
By default "Platforms".
allowed_business_units : list, optional
A list of allowed business units.
By default, ["HQ", "HMPPS", "OPG", "LAA", "HMCTS", "CICA", "Platforms"].
application : str, optional
The application in which the resources are used.
By default "Data Engineering".
Expand All @@ -57,7 +40,8 @@ def __init__(
By default "Data Engineering:dataengineering@digital.justice.gov.uk".
"""
check_business_unit(business_unit)
self._allowed_business_units = allowed_business_units
self._check_business_unit(business_unit, self._allowed_business_units)
if "is_production" in kwargs:
raise KeyError("is_production is not an allowed argument")

Expand All @@ -69,6 +53,27 @@ def __init__(
}
self._global_tags.update(kwargs)

def _check_business_unit(self, business_unit: str, allowed_business_units: list):
"""Checks if business_unit is an allowed value
Parameters
----------
business_unit : str
The business unit of the team that owns the resources. This should be one of
allowed_business_units.
allowed_business_units : list
A list of allowed business units.
Raises
------
ValueError
If the value of business_unit is not allowed a ValueError will be raised.
"""
if business_unit not in allowed_business_units:
raise ValueError(
f"business_unit must be one of {', '.join(allowed_business_units)}"
)

def create_tags(self, resource_name: str, **kwargs) -> dict:
"""
Creates a dictionary of mandatory and custom tags that can be passed to the tags
Expand All @@ -92,9 +97,9 @@ def create_tags(self, resource_name: str, **kwargs) -> dict:
tags = {}
for key, value in init_tags.items():
if key == "business_unit":
check_business_unit(value)
if key == "is_production":
raise KeyError("is_production is not an allowed argument")
self._check_business_unit(value, self._allowed_business_units)
if key in ["is_production"]:
raise KeyError(f"{key} is not an allowed argument")
tags[key.replace("_", "-").lower()] = value
tags["is-production"] = tags["environment-name"] in ["alpha", "prod"]
tags["Name"] = resource_name
Expand Down

0 comments on commit 0fa3dff

Please sign in to comment.