Skip to content

Commit

Permalink
Merge from aws/aws-sam-cli/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-sam-cli-bot authored Feb 2, 2023
2 parents c681067 + f8b2e60 commit 3748f12
Show file tree
Hide file tree
Showing 82 changed files with 4,380 additions and 56 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- develop
- "feat/*"

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: "CodeQL"

on:
push:
branches: [ "develop", master ]
branches: [ "develop", master, "feat/*" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "develop" ]
branches: [ "develop", "feat/*" ]
schedule:
- cron: '24 18 * * 0'

Expand Down
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ jmespath~=0.10.0
ruamel_yaml==0.17.21
PyYAML>=5.4.1,==5.*
cookiecutter~=2.1.1
aws-sam-translator==1.58.0
aws-sam-translator==1.58.1
#docker minor version updates can include breaking changes. Auto update micro version only.
docker~=4.2.0
dateparser~=1.0
requests==2.25.1
serverlessrepo==0.1.10
aws_lambda_builders==1.24.0
aws_lambda_builders==1.25.0
tomlkit==0.7.2
watchdog==2.1.2
pyopenssl==23.0.0
Expand Down
14 changes: 7 additions & 7 deletions requirements/reproducible-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ attrs==20.3.0 \
# jschema-to-python
# jsonschema
# sarif-om
aws-lambda-builders==1.24.0 \
--hash=sha256:6e46ce9365edb20259acae4a21f41fa46c701aaa58d2fb681022e4f0998de2d1 \
--hash=sha256:fd7277e01a3c280c5a2a5ca5eb7888594ecddbc8355d1f519ea48a1f07f9d2d8
aws-lambda-builders==1.25.0 \
--hash=sha256:4bb736a74457f87883861d57c0f6a859bd4e047b78ee58e09d16703a0c5172f3 \
--hash=sha256:f9d2094f714434b3668377fee5729c883849aede8a64eafe689fff08a530783b
# via aws-sam-cli (setup.py)
aws-sam-translator==1.58.0 \
--hash=sha256:627997303bcfb69209bc752f6b5b28b665b07341cec353d3711b05fc30e21ef8 \
--hash=sha256:74eff244a4923320e5df2f37617d85505356353e6022ae9812c6f0abcfbad5d3 \
--hash=sha256:9aaa3070a205669fdb3821b0c3eccaba1ff7917327c0e7d23dcc16d131d5dc30
aws-sam-translator==1.58.1 \
--hash=sha256:c4e261e450d574572d389edcafab04d1fe337615f867610410390c2435cb1f26 \
--hash=sha256:ca47d6eb04d8cf358bea9160411193da40a80dc3e79bb0c5bace0c21f0e4c888 \
--hash=sha256:cd60a19085d432bc00769b597bc2e6854f546ff9928f8067fc5fbcb5a1ed74ff
# via
# aws-sam-cli (setup.py)
# cfn-lint
Expand Down
2 changes: 1 addition & 1 deletion samcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
SAM CLI version
"""

__version__ = "1.71.0"
__version__ = "1.72.0"
2 changes: 2 additions & 0 deletions samcli/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"samcli.commands.traces",
"samcli.commands.sync",
"samcli.commands.pipeline.pipeline",
"samcli.commands.list.list",
# We intentionally do not expose the `bootstrap` command for now. We might open it up later
# "samcli.commands.bootstrap",
]
Expand All @@ -42,6 +43,7 @@
"traces": "Fetch AWS X-Ray traces",
"sync": "Sync a project to AWS",
"pipeline": "Manage the continuous delivery of the application",
"list": "Fetch the state of your serverless application",
}


Expand Down
Empty file.
Empty file.
26 changes: 26 additions & 0 deletions samcli/commands/list/cli_common/list_common_context.py
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")
48 changes: 48 additions & 0 deletions samcli/commands/list/cli_common/options.py
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.
54 changes: 54 additions & 0 deletions samcli/commands/list/endpoints/command.py
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()
84 changes: 84 additions & 0 deletions samcli/commands/list/endpoints/endpoints_context.py
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()
57 changes: 57 additions & 0 deletions samcli/commands/list/exceptions.py
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))
14 changes: 14 additions & 0 deletions samcli/commands/list/json_consumer.py
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)
22 changes: 22 additions & 0 deletions samcli/commands/list/list.py
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.
Loading

0 comments on commit 3748f12

Please sign in to comment.