Skip to content

Commit a18cb8f

Browse files
authored
Fixed prchecks (#1)
1 parent 4c26a42 commit a18cb8f

File tree

2 files changed

+136
-56
lines changed

2 files changed

+136
-56
lines changed

chalice/package.py

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from chalice.utils import (
1919
OSUtils, UI, serialize_to_json, to_cfn_resource_name
2020
)
21-
from chalice.awsclient import TypedAWSClient # noqa
21+
from chalice.awsclient import TypedAWSClient # noqa
2222
from chalice.config import Config # noqa
2323
from chalice.deploy import models
2424
from chalice.deploy.appgraph import ApplicationGraphBuilder, DependencyBuilder
@@ -101,8 +101,8 @@ def service_principal(self, service):
101101
class ResourceBuilder(object):
102102
def __init__(self,
103103
application_builder, # type: ApplicationGraphBuilder
104-
deps_builder, # type: DependencyBuilder
105-
build_stage, # type: BuildStage
104+
deps_builder, # type: DependencyBuilder
105+
build_stage, # type: BuildStage
106106
):
107107
# type: (...) -> None
108108
self._application_builder = application_builder
@@ -122,7 +122,6 @@ def construct_resources(self, config, chalice_stage_name):
122122

123123

124124
class TemplateGenerator(object):
125-
126125
template_file = None # type: str
127126

128127
def __init__(self, config, options):
@@ -861,7 +860,8 @@ def _generate_managediamrole(self, resource, template):
861860
def _add_websocket_lambda_integration(
862861
self, websocket_api_id, websocket_handler, template):
863862
# type: (str, str, Dict[str, Any]) -> None
864-
websocket_handler_function_name = "${aws_lambda_function.%s.function_name}" % websocket_handler
863+
websocket_handler_function_name = \
864+
"${aws_lambda_function.%s.function_name}" % websocket_handler
865865
resource_definition = {
866866
'api_id': websocket_api_id,
867867
'connection_type': 'INTERNET',
@@ -883,7 +883,8 @@ def _add_websocket_lambda_integration(
883883
def _add_websocket_lambda_invoke_permission(
884884
self, websocket_api_id, websocket_handler, template):
885885
# type: (str, str, Dict[str, Any]) -> None
886-
websocket_handler_function_name = "${aws_lambda_function.%s.function_name}" % websocket_handler
886+
websocket_handler_function_name = \
887+
"${aws_lambda_function.%s.function_name}" % websocket_handler
887888
resource_definition = {
888889
"function_name": websocket_handler_function_name,
889890
"action": "lambda:InvokeFunction",
@@ -902,9 +903,13 @@ def _add_websocket_lambda_invoke_permission(
902903
def _add_websockets_route(self, websocket_api_id, route_key, template):
903904
# type: (str, str, Dict[str, Any]) -> str
904905
integration_target = {
905-
'$connect': 'integrations/${aws_apigatewayv2_integration.websocket_connect_api_integration.id}',
906-
'$disconnect': 'integrations/${aws_apigatewayv2_integration.websocket_disconnect_api_integration.id}',
907-
}.get(route_key, 'integrations/${aws_apigatewayv2_integration.websocket_message_api_integration.id}')
906+
'$connect': 'integrations/${aws_apigatewayv2_integration'
907+
'.websocket_connect_api_integration.id}',
908+
'$disconnect': 'integrations/${aws_apigatewayv2_integration'
909+
'.websocket_disconnect_api_integration.id}',
910+
}.get(route_key,
911+
'integrations/${aws_apigatewayv2_integration'
912+
'.websocket_message_api_integration.id}')
908913

909914
route_resource_name = {
910915
'$connect': 'websocket_connect_route',
@@ -946,33 +951,49 @@ def _add_websocket_domain_name(self, websocket_api_id, resource, template):
946951
'aws_apigatewayv2_api_mapping', {}
947952
)[domain_name.resource_name + '_mapping'] = {
948953
"api_id": websocket_api_id,
949-
"domain_name": "${aws_apigatewayv2_domain_name.%s.id}" % domain_name.resource_name,
954+
"domain_name": "${aws_apigatewayv2_domain_name.%s.id}" %
955+
domain_name.resource_name,
950956
"stage": "${aws_apigatewayv2_stage.websocket_api_stage.id}",
951957
}
952958

953959
def _inject_websocketapi_outputs(self, websocket_api_id, template):
954960
# type: (str, Dict[str, Any]) -> None
955961
aws_lambda_functions = template['resource']['aws_lambda_function']
956-
stage_name = template['resource']['aws_apigatewayv2_stage']['websocket_api_stage']['name']
962+
stage_name = \
963+
template['resource']['aws_apigatewayv2_stage'][
964+
'websocket_api_stage'][
965+
'name']
957966
output = template.setdefault('output', {})
958967
output['WebsocketAPIId'] = {"value": websocket_api_id}
959968

960969
if 'websocket_connect' in aws_lambda_functions:
961-
output['WebsocketConnectHandlerArn'] = {"value": "${aws_lambda_function.websocket_connect.arn}"}
962-
output['WebsocketConnectHandlerName'] = {"value": "${aws_lambda_function.websocket_connect}"}
970+
output['WebsocketConnectHandlerArn'] = {
971+
"value": "${aws_lambda_function.websocket_connect.arn}"}
972+
output['WebsocketConnectHandlerName'] = {
973+
"value": "${aws_lambda_function.websocket_connect}"}
963974
if 'websocket_message' in aws_lambda_functions:
964-
output['WebsocketMessageHandlerArn'] = {"value": "${aws_lambda_function.websocket_message.arn}"}
965-
output['WebsocketMessageHandlerName'] = {"value": "${aws_lambda_function.websocket_message}"}
975+
output['WebsocketMessageHandlerArn'] = {
976+
"value": "${aws_lambda_function.websocket_message.arn}"}
977+
output['WebsocketMessageHandlerName'] = {
978+
"value": "${aws_lambda_function.websocket_message}"}
966979
if 'websocket_disconnect' in aws_lambda_functions:
967-
output['WebsocketDisconnectHandlerArn'] = {"value": "${aws_lambda_function.websocket_disconnect.arn}"}
968-
output['WebsocketDisconnectHandlerName'] = {"value": "${aws_lambda_function.websocket_disconnect}"}
969-
970-
output['WebsocketConnectEndpointURL'] = {"value": (
971-
'wss://%(websocket_api_id)s.execute-api'
972-
# The api_gateway_stage is filled in when
973-
# the template is built.
974-
'.${data.aws_region.chalice.name}.amazonaws.com/%(stage_name)s/'
975-
) % {"stage_name": stage_name, "websocket_api_id": websocket_api_id}}
980+
output['WebsocketDisconnectHandlerArn'] = {
981+
"value": "${aws_lambda_function.websocket_disconnect.arn}"}
982+
output['WebsocketDisconnectHandlerName'] = {
983+
"value": "${aws_lambda_function.websocket_disconnect}"}
984+
985+
output['WebsocketConnectEndpointURL'] = {
986+
"value": (
987+
'wss://%(websocket_api_id)s.execute-api'
988+
# The api_gateway_stage is filled in when
989+
# the template is built.
990+
'.${data.aws_region.chalice.name}'
991+
'.amazonaws.com/%(stage_name)s/'
992+
) % {
993+
"stage_name": stage_name,
994+
"websocket_api_id": websocket_api_id
995+
}
996+
}
976997

977998
def _generate_websocketapi(self, resource, template):
978999
# type: (models.WebsocketAPI, Dict[str, Any]) -> None
@@ -986,7 +1007,8 @@ def _generate_websocketapi(self, resource, template):
9861007
template['resource'].setdefault('aws_apigatewayv2_api', {})[
9871008
resource.resource_name] = ws_definition
9881009

989-
websocket_api_id = "${aws_apigatewayv2_api.%s.id}" % resource.resource_name
1010+
websocket_api_id = "${aws_apigatewayv2_api.%s.id}" % \
1011+
resource.resource_name
9901012

9911013
websocket_handlers = [
9921014
'websocket_connect',
@@ -996,26 +1018,32 @@ def _generate_websocketapi(self, resource, template):
9961018

9971019
for handler in websocket_handlers:
9981020
if handler in template['resource']['aws_lambda_function']:
999-
self._add_websocket_lambda_integration(websocket_api_id, handler, template)
1000-
self._add_websocket_lambda_invoke_permission(websocket_api_id, handler, template)
1021+
self._add_websocket_lambda_integration(websocket_api_id,
1022+
handler, template)
1023+
self._add_websocket_lambda_invoke_permission(websocket_api_id,
1024+
handler, template)
10011025

10021026
route_resource_names = []
10031027
for route_key in resource.routes:
1004-
route_resource_name = self._add_websockets_route(websocket_api_id, route_key, template)
1028+
route_resource_name = self._add_websockets_route(websocket_api_id,
1029+
route_key,
1030+
template)
10051031
route_resource_names.append(route_resource_name)
10061032

10071033
template['resource'].setdefault(
10081034
'aws_apigatewayv2_deployment', {}
10091035
)['websocket_api_deployment'] = {
10101036
"api_id": websocket_api_id,
1011-
"depends_on": ["aws_apigatewayv2_route.%s" % name for name in route_resource_names]
1037+
"depends_on": ["aws_apigatewayv2_route.%s" % name for name in
1038+
route_resource_names]
10121039
}
10131040

10141041
template['resource'].setdefault(
10151042
'aws_apigatewayv2_stage', {}
10161043
)['websocket_api_stage'] = {
10171044
"api_id": websocket_api_id,
1018-
"deployment_id": "${aws_apigatewayv2_deployment.websocket_api_deployment.id}",
1045+
"deployment_id": ("${aws_apigatewayv2_deployment"
1046+
".websocket_api_deployment.id}"),
10191047
"name": resource.api_gateway_stage
10201048
}
10211049

@@ -1177,10 +1205,10 @@ def _generate_lambdalayer(self, resource, template):
11771205
# type: (models.LambdaLayer, Dict[str, Any]) -> None
11781206
template['resource'].setdefault(
11791207
"aws_lambda_layer_version", {})[
1180-
resource.resource_name] = {
1181-
'layer_name': resource.layer_name,
1182-
'compatible_runtimes': [resource.runtime],
1183-
'filename': resource.deployment_package.filename,
1208+
resource.resource_name] = {
1209+
'layer_name': resource.layer_name,
1210+
'compatible_runtimes': [resource.runtime],
1211+
'filename': resource.deployment_package.filename,
11841212
}
11851213
self._chalice_layer = resource.resource_name
11861214

@@ -1309,7 +1337,8 @@ def _generate_restapi(self, resource, template):
13091337
'principal': self._options.service_principal('apigateway'),
13101338
'source_arn': (
13111339
"${aws_api_gateway_rest_api.%s.execution_arn}" % (
1312-
resource.resource_name) + "/*"
1340+
resource.resource_name
1341+
) + "/*"
13131342
)
13141343
}
13151344
self._add_domain_name(resource, template)

0 commit comments

Comments
 (0)