Skip to content

Commit

Permalink
Implicit support for partitions as per #792
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-mcgrath committed Jun 26, 2020
1 parent a83b7ee commit 663e95c
Show file tree
Hide file tree
Showing 33 changed files with 1,531 additions and 485 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=compat.py
ignore=compat.py,regions.py

# Pickle collected data for later comparisons.
persistent=yes
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ TESTS=tests/unit tests/functional tests/integration
check:
###### FLAKE8 #####
# No unused imports, no undefined vars,
flake8 --ignore=E731,W503,W504 --exclude chalice/__init__.py,chalice/compat.py --max-complexity 10 chalice/
flake8 --ignore=E731,W503,W504 --exclude chalice/__init__.py,chalice/compat.py,chalice/vendored/botocore/regions.py --max-complexity 10 chalice/
flake8 --ignore=E731,W503,W504,F401 --max-complexity 10 chalice/compat.py
flake8 tests/unit/ tests/functional/ tests/integration tests/aws
#
# Proper docstring conventions according to pep257
#
#
pydocstyle --add-ignore=D100,D101,D102,D103,D104,D105,D204,D301 chalice/
pydocstyle --add-ignore=D100,D101,D102,D103,D104,D105,D204,D301 --match='(?!(test_|regions)).*\.py' chalice/

pylint:
###### PYLINT ######
Expand Down
282 changes: 215 additions & 67 deletions chalice/awsclient.py

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions chalice/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,19 @@ def generate_models(ctx, stage):
type=click.Choice(['json', 'yaml'], case_sensitive=False),
help=('Specify if the generated template should be serialized '
'as either JSON or YAML. CloudFormation only.'))
@click.option('--profile', help='Override profile at packaging time.')
@click.argument('out')
@click.pass_context
def package(ctx, single_file, stage, merge_template,
out, pkg_format, template_format):
# type: (click.Context, bool, str, str, str, str, str) -> None
out, pkg_format, template_format, profile):
# type: (click.Context, bool, str, str, str, str, str, str) -> None
factory = ctx.obj['factory'] # type: CLIFactory
factory.profile = profile
config = factory.create_config_obj(stage)
packager = factory.create_app_packager(config, pkg_format, template_format,
options = factory.create_package_options()
packager = factory.create_app_packager(config, options,
pkg_format,
template_format,
merge_template)
if pkg_format == 'terraform' and (merge_template or
single_file or
Expand Down
47 changes: 27 additions & 20 deletions chalice/cli/factory.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
import sys
import os
import json
import functools
import importlib
import json
import logging
import functools
import os
import sys
from typing import Any, Optional, Dict, MutableMapping, cast # noqa

import click
from botocore.config import Config as BotocoreConfig
from botocore.session import Session
from typing import Any, Optional, Dict, MutableMapping, cast # noqa

from chalice import __version__ as chalice_version
from chalice.awsclient import TypedAWSClient
from chalice import local
from chalice.app import Chalice # noqa
from chalice.awsclient import TypedAWSClient
from chalice.config import Config
from chalice.config import DeployedResources # noqa
from chalice.package import create_app_packager
from chalice.package import AppPackager # noqa
from chalice.constants import DEFAULT_STAGE_NAME
from chalice.constants import DEFAULT_APIGATEWAY_STAGE_NAME
from chalice.constants import DEFAULT_ENDPOINT_TYPE
from chalice.logs import LogRetriever, LogEventGenerator
from chalice.logs import FollowLogEventGenerator
from chalice.logs import BaseLogEventGenerator
from chalice import local
from chalice.utils import UI # noqa
from chalice.utils import PipeReader # noqa
from chalice.constants import DEFAULT_STAGE_NAME
from chalice.deploy import deployer # noqa
from chalice.deploy import validate
from chalice.invoke import LambdaInvokeHandler
from chalice.invoke import LambdaInvoker
from chalice.invoke import LambdaResponseFormatter

from chalice.logs import BaseLogEventGenerator
from chalice.logs import FollowLogEventGenerator
from chalice.logs import LogRetriever, LogEventGenerator
from chalice.package import AppPackager # noqa
from chalice.package import create_app_packager, PackageOptions
from chalice.utils import PipeReader # noqa
from chalice.utils import UI # noqa

OptStr = Optional[str]
OptInt = Optional[int]
Expand Down Expand Up @@ -75,6 +74,7 @@ def _inject_large_request_body_filter():

class NoSuchFunctionError(Exception):
"""The specified function could not be found."""

def __init__(self, name):
# type: (str) -> None
self.name = name
Expand Down Expand Up @@ -185,11 +185,11 @@ def _validate_config_from_disk(self, config):
except ValueError:
raise UnknownConfigFileVersion(string_version)

def create_app_packager(self, config, package_format, template_format,
merge_template=None):
# type: (Config, str, str, OptStr) -> AppPackager
def create_app_packager(self, config, options, package_format,
template_format, merge_template=None):
# type: (Config, PackageOptions, str, str, OptStr) -> AppPackager
return create_app_packager(
config, package_format, template_format,
config, options, package_format, template_format,
merge_template=merge_template)

def create_log_retriever(self, session, lambda_arn, follow_logs):
Expand Down Expand Up @@ -298,3 +298,10 @@ def load_project_config(self):
def create_local_server(self, app_obj, config, host, port):
# type: (Chalice, Config, str, int) -> local.LocalDevServer
return local.create_local_server(app_obj, config, host, port)

def create_package_options(self):
# type: () -> PackageOptions
"""Create the package options that are required to target regions."""
s = Session(profile=self.profile)
client = TypedAWSClient(session=s)
return PackageOptions(client)
6 changes: 3 additions & 3 deletions chalice/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def index():
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
"Resource": "arn:*:logs:*:*:*"
}


Expand Down Expand Up @@ -113,7 +113,7 @@ def index():
"s3:GetObjectVersion",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::*",
"Resource": "arn:*:s3:::*",
"Effect": "Allow"
}
]
Expand Down Expand Up @@ -247,5 +247,5 @@ def index():
"Action": [
"execute-api:ManageConnections"
],
"Resource": "arn:aws:execute-api:*:*:*/@connections/*"
"Resource": "arn:*:execute-api:*:*:*/@connections/*"
}
2 changes: 1 addition & 1 deletion chalice/deploy/appgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _get_default_private_api_policy(self, config):
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:*:*:*",
"Resource": "arn:*:execute-api:*:*:*",
"Condition": {
"StringEquals": {
"aws:SourceVpce": config.api_gateway_endpoint_vpce
Expand Down
32 changes: 28 additions & 4 deletions chalice/deploy/executor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import re
import pprint
import re
from typing import Dict, List, Any # noqa

import jmespath
from attr import asdict
from typing import Dict, List, Any # noqa

from chalice.awsclient import TypedAWSClient # noqa
from chalice.deploy import models
from chalice.deploy.planner import Variable, StringFormat
from chalice.awsclient import TypedAWSClient # noqa
from chalice.utils import UI # noqa


Expand Down Expand Up @@ -114,9 +114,34 @@ def _do_builtinfunction(self, instruction):
value = resolved_args[0]
parts = value.split(':')
result = {
'partition': parts[1],
'service': parts[2],
'region': parts[3],
'account_id': parts[4],
'dns_suffix': self._client.endpoint_dns_suffix(parts[2],
parts[3])
}
self.variables[instruction.output_var] = result
elif instruction.function_name == 'interrogate_profile':
region = self._client.region_name
result = {
'partition': self._client.partition_name,
'region': region,
'dns_suffix': self._client.endpoint_dns_suffix('apigateway',
region)
}
self.variables[instruction.output_var] = result
elif instruction.function_name == 'service_principal':
resolved_args = self._variable_resolver.resolve_variables(
instruction.args, self.variables)
service_name = resolved_args[0]
region_name = self._client.region_name
dns_suffix = self._client.endpoint_dns_suffix(service_name,
region_name)
result = {
'principal': self._client.service_principal(service_name,
region_name,
dns_suffix)
}
self.variables[instruction.output_var] = result
else:
Expand Down Expand Up @@ -167,7 +192,6 @@ def resolve_variables(self, value, variables):
# The dev commands don't have any backwards compatibility guarantees
# so we can alter this output as needed.
class DisplayOnlyExecutor(BaseExecutor):

# Max length of bytes object before we truncate with '<bytes>'
_MAX_BYTE_LENGTH = 30
_LINE_VERTICAL = u'\u2502'
Expand Down
Loading

0 comments on commit 663e95c

Please sign in to comment.