Skip to content

Commit

Permalink
feat: add gateways property
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis-Henrique committed Nov 30, 2023
1 parent a08c6b5 commit 102a75b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@ def find_nodes(tree: Dict[str, Any], node_type: NodeType) -> List[Dict[str, Any]
class Template:
def __init__(self, template: Optional[str] = None) -> None:
self._template = self.load(template)
self._gateways = None

@property
def template(self):
return self._template

@property
def gateways(self):
if not self._gateways:
self._gateways = find_nodes(self._template["Resources"], NodeType.API_GATEWAY)
return self._gateways

def load(self, template: Optional[str] = None) -> Dict[str, Any]:
path: Optional[Path] = None

Expand Down
17 changes: 17 additions & 0 deletions tests/test_cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,20 @@ def test_load_raises_exception(self):

with self.assertRaisesRegex(cf.CFTemplateNotFound, regex):
Template(template)

def test_list_gateways(self):
cloudformation = Template("tests/fixtures/templates/example2.yml")

expected_gateway = [
{
"ApiGateway": {
"Type": "AWS::Serverless::Api",
"Properties": {
"Name": "sam-api",
"StageName": "v1",
},
},
},
]

self.assertEqual(cloudformation.gateways, expected_gateway)

0 comments on commit 102a75b

Please sign in to comment.