-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
endpoints_context.py
95 lines (85 loc) · 3.09 KB
/
endpoints_context.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Display of the Endpoints of a SAM stack
"""
import logging
from typing import Optional
from samcli.commands.list.cli_common.list_common_context import ListContext
from samcli.lib.list.endpoints.endpoints_producer import EndpointsProducer
from samcli.lib.list.list_interfaces import ProducersEnum
from samcli.lib.list.mapper_consumer_factory import MapperConsumerFactory
LOG = logging.getLogger(__name__)
class EndpointsContext(ListContext):
"""
Context class for sam list endpoints
"""
def __init__(
self,
stack_name: str,
output: str,
region: Optional[str],
profile: Optional[str],
template_file: Optional[str],
parameter_overrides: Optional[dict] = None,
):
"""
Parameters
----------
stack_name: str
The name of the stack
output: str
The format of the output, either json or table
region: Optional[str]
The region of the stack
profile: Optional[str]
Optional profile to be used
template_file: Optional[str]
The location of the template file. If one is not specified, the default will be "template.yaml" in the CWD
parameter_overrides: Optional[dict]
Dictionary of parameters to override in the template
"""
super().__init__()
self.parameter_overrides = parameter_overrides
self.stack_name = stack_name
self.output = output
self.region = region
self.profile = profile
self.template_file = template_file
self.iam_client = None
self.cloudcontrol_client = None
self.apigateway_client = None
self.apigatewayv2_client = None
def __enter__(self):
self.init_clients()
return self
def __exit__(self, *args):
pass
def init_clients(self) -> None:
"""
Initialize the clients being used by sam list.
"""
super().init_clients()
self.iam_client = self.client_provider("iam")
self.cloudcontrol_client = self.client_provider("cloudcontrol")
self.apigateway_client = self.client_provider("apigateway")
self.apigatewayv2_client = self.client_provider("apigatewayv2")
def run(self) -> None:
"""
Get the resources for a stack
"""
factory = MapperConsumerFactory()
container = factory.create(producer=ProducersEnum.ENDPOINTS_PRODUCER, output=self.output)
endpoints_producer = EndpointsProducer(
stack_name=self.stack_name,
region=self.region,
profile=self.profile,
template_file=self.template_file,
cloudformation_client=self.cloudformation_client,
iam_client=self.iam_client,
cloudcontrol_client=self.cloudcontrol_client,
apigateway_client=self.apigateway_client,
apigatewayv2_client=self.apigatewayv2_client,
mapper=container.mapper,
consumer=container.consumer,
parameter_overrides=self.parameter_overrides,
)
endpoints_producer.produce()