|
21 | 21 | CorsProperties.__new__.__defaults__ = (None, None, _CORS_WILDCARD, None, False) |
22 | 22 |
|
23 | 23 | AuthProperties = namedtuple("_AuthProperties", |
24 | | - ["Authorizers", "DefaultAuthorizer", "InvokeRole", "AddDefaultAuthorizerToCorsPreflight"]) |
25 | | -AuthProperties.__new__.__defaults__ = (None, None, None, True) |
| 24 | + ["Authorizers", "DefaultAuthorizer", "InvokeRole", "AddDefaultAuthorizerToCorsPreflight", |
| 25 | + "ApiKeyRequired"]) |
| 26 | +AuthProperties.__new__.__defaults__ = (None, None, None, True, None) |
26 | 27 |
|
27 | 28 | GatewayResponseProperties = ["ResponseParameters", "ResponseTemplates", "StatusCode"] |
28 | 29 |
|
@@ -115,6 +116,8 @@ def _construct_rest_api(self): |
115 | 116 | if self.definition_uri: |
116 | 117 | rest_api.BodyS3Location = self._construct_body_s3_dict() |
117 | 118 | elif self.definition_body: |
| 119 | + # # Post Process OpenApi Auth Settings |
| 120 | + self.definition_body = self._openapi_auth_postprocess(self.definition_body) |
118 | 121 | rest_api.Body = self.definition_body |
119 | 122 |
|
120 | 123 | if self.name: |
@@ -308,13 +311,17 @@ def _add_auth(self): |
308 | 311 | authorizers = self._get_authorizers(auth_properties.Authorizers, auth_properties.DefaultAuthorizer) |
309 | 312 |
|
310 | 313 | if authorizers: |
311 | | - swagger_editor.add_authorizers(authorizers) |
| 314 | + swagger_editor.add_authorizers_security_definitions(authorizers) |
312 | 315 | self._set_default_authorizer(swagger_editor, authorizers, auth_properties.DefaultAuthorizer, |
313 | 316 | auth_properties.AddDefaultAuthorizerToCorsPreflight) |
314 | 317 |
|
315 | | - # Assign the Swagger back to template |
| 318 | + if auth_properties.ApiKeyRequired: |
| 319 | + swagger_editor.add_apikey_security_definition() |
| 320 | + self._set_default_apikey_required(swagger_editor) |
316 | 321 |
|
317 | | - self.definition_body = self._openapi_auth_postprocess(swagger_editor.swagger) |
| 322 | + # Assign the Swagger back to template |
| 323 | + # self.definition_body = self._openapi_auth_postprocess(swagger_editor.swagger) |
| 324 | + self.definition_body = swagger_editor.swagger |
318 | 325 |
|
319 | 326 | def _openapi_auth_postprocess(self, definition_body): |
320 | 327 | """ |
@@ -523,6 +530,10 @@ def _set_default_authorizer(self, swagger_editor, authorizers, default_authorize |
523 | 530 | swagger_editor.set_path_default_authorizer(path, default_authorizer, authorizers=authorizers, |
524 | 531 | add_default_auth_to_preflight=add_default_auth_to_preflight) |
525 | 532 |
|
| 533 | + def _set_default_apikey_required(self, swagger_editor): |
| 534 | + for path in swagger_editor.iter_on_path(): |
| 535 | + swagger_editor.set_path_default_apikey_required(path) |
| 536 | + |
526 | 537 | def _set_endpoint_configuration(self, rest_api, value): |
527 | 538 | """ |
528 | 539 | Sets endpoint configuration property of AWS::ApiGateway::RestApi resource |
|
0 commit comments