-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
82 changed files
with
4,380 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
pull_request: | ||
branches: | ||
- develop | ||
- "feat/*" | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
SAM CLI version | ||
""" | ||
|
||
__version__ = "1.71.0" | ||
__version__ = "1.72.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Common context class to inherit from for sam list sub-commands | ||
""" | ||
from samcli.lib.utils.boto_utils import get_boto_client_provider_with_config | ||
|
||
|
||
class ListContext: | ||
def __init__(self): | ||
self.cloudformation_client = None | ||
self.client_provider = None | ||
self.region = None | ||
self.profile = None | ||
|
||
def init_clients(self) -> None: | ||
""" | ||
Initialize the clients being used by sam list. | ||
""" | ||
from boto3 import Session | ||
|
||
if not self.region: | ||
session = Session() | ||
self.region = session.region_name | ||
|
||
client_provider = get_boto_client_provider_with_config(region=self.region, profile=self.profile) | ||
self.client_provider = client_provider | ||
self.cloudformation_client = client_provider("cloudformation") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
Common CLI options shared by various commands | ||
""" | ||
|
||
import click | ||
|
||
|
||
def stack_name_click_option(): | ||
return click.option( | ||
"--stack-name", | ||
help=( | ||
"Name of corresponding deployed stack.(Not including " | ||
"a stack name will only show local resources defined " | ||
"in the template.) " | ||
), | ||
type=click.STRING, | ||
) | ||
|
||
|
||
def stack_name_option(f): | ||
return stack_name_click_option()(f) | ||
|
||
|
||
def output_click_option(): | ||
return click.option( | ||
"--output", | ||
default="table", | ||
help="Output the results from the command in a given " "output format (json or table). ", | ||
type=click.Choice(["json", "table"], case_sensitive=False), | ||
) | ||
|
||
|
||
def output_option(f): | ||
return output_click_option()(f) | ||
|
||
|
||
STACK_NAME_WARNING_MESSAGE = ( | ||
"The --stack-name options was not provided, displaying only local template data. " | ||
"To see data about deployed resources, provide the corresponding stack name." | ||
) | ||
|
||
|
||
def stack_name_not_provided_message(): | ||
click.secho( | ||
fg="yellow", | ||
message=STACK_NAME_WARNING_MESSAGE, | ||
err=True, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Sets up the cli for resources | ||
""" | ||
|
||
import click | ||
|
||
from samcli.commands._utils.command_exception_handler import command_exception_handler | ||
from samcli.commands.list.cli_common.options import stack_name_option, output_option, stack_name_not_provided_message | ||
from samcli.cli.main import pass_context, common_options, aws_creds_options, print_cmdline_args | ||
from samcli.lib.utils.version_checker import check_newer_version | ||
from samcli.lib.telemetry.metric import track_command | ||
from samcli.commands._utils.options import template_option_without_build | ||
from samcli.cli.cli_config_file import configuration_option, TomlProvider | ||
|
||
|
||
HELP_TEXT = """ | ||
Get a summary of the cloud endpoints in the stack.\n | ||
This command will show both the cloud and local endpoints that can | ||
be used with sam local and sam sync. Currently the endpoint resources | ||
are Lambda functions and API Gateway API resources. | ||
""" | ||
|
||
|
||
@click.command(name="endpoints", help=HELP_TEXT) | ||
@configuration_option(provider=TomlProvider(section="parameters")) | ||
@stack_name_option | ||
@output_option | ||
@template_option_without_build | ||
@aws_creds_options | ||
@common_options | ||
@pass_context | ||
@track_command | ||
@check_newer_version | ||
@print_cmdline_args | ||
@command_exception_handler | ||
def cli(self, stack_name, output, template_file, config_file, config_env): | ||
""" | ||
`sam list endpoints` command entry point | ||
""" | ||
do_cli(stack_name=stack_name, output=output, region=self.region, profile=self.profile, template_file=template_file) | ||
|
||
|
||
def do_cli(stack_name, output, region, profile, template_file): | ||
""" | ||
Implementation of the ``cli`` method | ||
""" | ||
from samcli.commands.list.endpoints.endpoints_context import EndpointsContext | ||
|
||
with EndpointsContext( | ||
stack_name=stack_name, output=output, region=region, profile=profile, template_file=template_file | ||
) as endpoints_context: | ||
if not stack_name: | ||
stack_name_not_provided_message() | ||
endpoints_context.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
""" | ||
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.mapper_consumer_factory import MapperConsumerFactory | ||
from samcli.lib.list.list_interfaces import ProducersEnum | ||
|
||
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] | ||
): | ||
""" | ||
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 | ||
""" | ||
super().__init__() | ||
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, | ||
) | ||
endpoints_producer.produce() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
Exceptions for SAM list | ||
""" | ||
|
||
|
||
from samcli.commands.exceptions import UserException | ||
|
||
|
||
class SamListError(UserException): | ||
""" | ||
Base exception for the 'sam list' command | ||
""" | ||
|
||
def __init__(self, msg): | ||
self.msg = msg | ||
|
||
message_fmt = "{msg}" | ||
|
||
super().__init__(message=message_fmt.format(msg=msg)) | ||
|
||
|
||
class SamListUnknownClientError(SamListError): | ||
""" | ||
Used when boto3 API call raises an unexpected ClientError | ||
""" | ||
|
||
|
||
class SamListUnknownBotoCoreError(SamListError): | ||
""" | ||
Used when boto3 API call raises an unexpected BotoCoreError | ||
""" | ||
|
||
|
||
class SamListLocalResourcesNotFoundError(SamListError): | ||
""" | ||
Used when unable to retrieve local resources after performing a transform | ||
""" | ||
|
||
|
||
class NoOutputsForStackError(UserException): | ||
def __init__(self, stack_name, region): | ||
self.stack_name = stack_name | ||
self.region = region | ||
|
||
message_fmt = f"Outputs do not exist for the input stack {stack_name} on Cloudformation in the region {region}" | ||
|
||
super().__init__(message=message_fmt.format(stack_name=self.stack_name, region=self.region)) | ||
|
||
|
||
class StackDoesNotExistInRegionError(UserException): | ||
def __init__(self, stack_name, region): | ||
self.stack_name = stack_name | ||
self.region = region | ||
|
||
message_fmt = f"The input stack {stack_name} does" f" not exist on Cloudformation in the region {region}" | ||
|
||
super().__init__(message=message_fmt.format(stack_name=self.stack_name, region=self.region)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
The json consumer for 'sam list' | ||
""" | ||
import click | ||
from samcli.lib.list.list_interfaces import ListInfoPullerConsumer | ||
|
||
|
||
class StringConsumerJsonOutput(ListInfoPullerConsumer): | ||
""" | ||
Consumes string data and outputs it in json format | ||
""" | ||
|
||
def consume(self, data: str) -> None: | ||
click.echo(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
Command group for "list" suite for commands. | ||
""" | ||
|
||
import click | ||
|
||
from samcli.commands.list.resources.command import cli as resources_cli | ||
from samcli.commands.list.stack_outputs.command import cli as stack_outputs_cli | ||
from samcli.commands.list.endpoints.command import cli as testable_resources_cli | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
""" | ||
Get local and deployed state of serverless application. | ||
""" | ||
|
||
|
||
# Add individual commands under this group | ||
cli.add_command(resources_cli) | ||
cli.add_command(stack_outputs_cli) | ||
cli.add_command(testable_resources_cli) |
Empty file.
Oops, something went wrong.