Skip to content

Commit

Permalink
Merge 1ec1243 into 23acb91
Browse files Browse the repository at this point in the history
  • Loading branch information
calumabarnett committed Jul 7, 2020
2 parents 23acb91 + 1ec1243 commit 5ae9e30
Show file tree
Hide file tree
Showing 6 changed files with 971 additions and 137 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,6 @@ API
Training
Blog
About

# VSCode
.vscode/
101 changes: 101 additions & 0 deletions dataengineeringutils3/pulumi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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",
application: str = "Data Engineering",
owner: str = "Data Engineering:dataengineering@digital.justice.gov.uk",
**kwargs
):
"""
Provides a Tagger resource.
Parameters
----------
environment_name : str
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".
By default "Platforms".
application : str, optional
The application in which the resources are used.
By default "Data Engineering".
owner : str, optional
The owner of the resources. This should be of the form
<team-name>:<team-email>.
By default "Data Engineering:dataengineering@digital.justice.gov.uk".
"""
check_business_unit(business_unit)
if "is_production" in kwargs:
raise KeyError("is_production is not an allowed argument")

self._global_tags = {
"environment_name": environment_name,
"business_unit": business_unit,
"application": application,
"owner": owner,
}
self._global_tags.update(kwargs)

def create_tags(self, resource_name: str, **kwargs) -> dict:
"""
Creates a dictionary of mandatory and custom tags that can be passed to the tags
argument of a Pulumi resource.
Parameters
----------
resource_name : str
The name of the resource for which the tags will be created. This should be
the same as the resource_name of the Pulumi resource to which you are
adding the tags.
Returns
-------
dict
A dictionary of mandatory and custom tags that can be passed to the tags
argument of a Pulumi resource.
"""
init_tags = self._global_tags
init_tags.update(kwargs)
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")
tags[key.replace("_", "-").lower()] = value
tags["is-production"] = tags["environment-name"] in ["alpha", "prod"]
tags["Name"] = resource_name
return tags
Loading

0 comments on commit 5ae9e30

Please sign in to comment.