Skip to content

Commit

Permalink
feat: add gateways property (#34)
Browse files Browse the repository at this point in the history
* feat: add gateways property

* refactor: update dict name
  • Loading branch information
Luis-Henrique authored Nov 30, 2023
1 parent ae2b33a commit 6d82508
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 @@ -63,11 +63,18 @@ def construct_getatt(node: yaml.nodes.Node) -> List[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 = self.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 @@ -89,6 +89,23 @@ 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_gateways = [
{
"ApiGateway": {
"Type": "AWS::Serverless::Api",
"Properties": {
"Name": "sam-api",
"StageName": "v1",
},
},
},
]

self.assertEqual(cloudformation.gateways, expected_gateways)

def test_find_nodes(self):
cloudformation = Template("tests/fixtures/templates/example1.yml")
tree = cloudformation.template
Expand Down

0 comments on commit 6d82508

Please sign in to comment.