Skip to content

Commit

Permalink
Add support for api_key_required and authorizer in a view
Browse files Browse the repository at this point in the history
This pulls in aws#473 and adds a test for it.
  • Loading branch information
jamesls committed Sep 5, 2017
1 parent 529edd1 commit 46520fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Next Release (TBD)
(`#500 <https://github.com/aws/chalice/issues/500>`__)
* Add support for Builtin Authorizers in local mode
(`#404 <https://github.com/aws/chalice/issues/404>`__)
* Allow view to require API keys as well as authorization
(`#473 <https://github.com/aws/chalice/pull/473/>`__)


1.0.1
Expand Down
5 changes: 3 additions & 2 deletions chalice/deploy/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ def _generate_route_method(self, view):
# to the security definitions. We have to someone indicate
# this because this neeeds to be added to the global config
# file.
current['security'] = [{'api_key': []}]
current.setdefault('security', []).append({'api_key': []})
if view.authorizer:
current['security'] = [{view.authorizer.name: []}]
current.setdefault('security', []).append(
{view.authorizer.name: []})
if view.view_args:
self._add_view_args(current, view.view_args)
return current
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/deploy/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,22 @@ def auth():
}


def test_can_use_api_key_and_authorizers(sample_app, swagger_gen):
authorizer = CustomAuthorizer(
'MyAuth', authorizer_uri='auth-uri', header='Authorization')

@sample_app.route('/auth', authorizer=authorizer, api_key_required=True)
def auth():
return {'foo': 'bar'}

doc = swagger_gen.generate_swagger(sample_app)
single_method = doc['paths']['/auth']['get']
assert single_method.get('security') == [
{'api_key': []},
{'MyAuth': []},
]


def test_can_use_iam_authorizer_object(sample_app, swagger_gen):
authorizer = IAMAuthorizer()

Expand Down

0 comments on commit 46520fb

Please sign in to comment.