Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path params as requestParam in put_method #164

Merged
merged 1 commit into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Next Release (TBD)
* Return 405 when method is not supported when running
``chalice local``
(`#159 <https://github.com/awslabs/chalice/issues/159>`__)
* Add path params as requestParameters so they can be used
in generated SDKs as well as cache keys
(`#163 <https://github.com/awslabs/chalice/issues/163>`__)


0.4.0
Expand Down
14 changes: 11 additions & 3 deletions chalice/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import inspect
import re

from typing import Any, Tuple, Callable, IO # noqa
from typing import Any, Tuple, Callable, IO, List # noqa
import botocore.session # noqa
import virtualenv

Expand Down Expand Up @@ -341,6 +341,7 @@ def _configure_resource_route(self, node, http_method):
self._apig_methods.create_method_request(
resource_id, http_method, route_entry.authorization_type,
route_entry.authorizer_id, route_entry.api_key_required,
route_entry.view_args
)
self._apig_methods.create_lambda_method_integration(
resource_id, http_method, route_entry.content_types,
Expand Down Expand Up @@ -833,8 +834,9 @@ def __init__(self, apig_client, rest_api_id):

def create_method_request(self, resource_id, http_method,
authorization_type=None, authorizer_id=None,
api_key_required=False):
# type: (str, str, str, str, bool) -> None
api_key_required=False,
url_params=None):
# type: (str, str, str, str, bool, List[str]) -> None
"""Create an API Gateway method request.

This defines the public API used by consumers of the API Gateway
Expand All @@ -853,6 +855,12 @@ def create_method_request(self, resource_id, http_method,
put_method_cfg['authorizerId'] = authorizer_id
if api_key_required:
put_method_cfg['apiKeyRequired'] = api_key_required
if url_params:
request_params = {
'method.request.path.%s' % param: True
for param in url_params
}
put_method_cfg['requestParameters'] = request_params
self._apig_client.put_method(**put_method_cfg)

def create_lambda_method_integration(self, resource_id, http_method,
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,20 @@ def badview():

with pytest.raises(ValueError):
validate_routes(sample_app.routes)


def test_apig_methods(stubbed_session):
gateway_stub = stubbed_session.stub('apigateway')
gateway_stub.put_method(
authorizationType='NONE',
httpMethod='GET',
resourceId='resource_id',
restApiId='rest_api_id',
requestParameters={'method.request.path.name': True},
).returns({})
apig = APIGatewayMethods(
stubbed_session.create_client('apigateway'), 'rest_api_id')

stubbed_session.activate_stubs()
apig.create_method_request('resource_id', 'GET', url_params=['name'])
stubbed_session.verify_stubs()