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

patch fix for Release v1.13.2 #1061

Merged
merged 3 commits into from
Aug 1, 2019
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
2 changes: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.13.1'
__version__ = '1.13.2'
2 changes: 1 addition & 1 deletion samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def _construct_stage(self, deployment, swagger):
stage.TracingEnabled = self.tracing_enabled

if swagger is not None:
deployment.make_auto_deployable(stage, swagger)
deployment.make_auto_deployable(stage, self.open_api_version, swagger)

return stage

Expand Down
18 changes: 13 additions & 5 deletions samtranslator/model/apigateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class ApiGatewayAccount(Resource):


class ApiGatewayDeployment(Resource):
_X_HASH_DELIMITER = "||"

resource_type = 'AWS::ApiGateway::Deployment'
property_types = {
'Description': PropertyType(False, is_str()),
Expand All @@ -73,9 +75,10 @@ class ApiGatewayDeployment(Resource):
"deployment_id": lambda self: ref(self.logical_id),
}

def make_auto_deployable(self, stage, swagger=None):
def make_auto_deployable(self, stage, openapi_version=None, swagger=None):
"""
Sets up the resource such that it will triggers a re-deployment when Swagger changes
Sets up the resource such that it will trigger a re-deployment when Swagger changes
or the openapi version changes.

:param swagger: Dictionary containing the Swagger definition of the API
"""
Expand All @@ -88,10 +91,15 @@ def make_auto_deployable(self, stage, swagger=None):
# to prevent redeployment when API has not changed

# NOTE: `str(swagger)` is for backwards compatibility. Changing it to a JSON or something will break compat
generator = logical_id_generator.LogicalIdGenerator(self.logical_id, str(swagger))
hash_input = [str(swagger)]
if openapi_version:
hash_input.append(str(openapi_version))

data = self._X_HASH_DELIMITER.join(hash_input)
generator = logical_id_generator.LogicalIdGenerator(self.logical_id, data)
self.logical_id = generator.gen()
hash = generator.get_hash(length=40) # Get the full hash
self.Description = "RestApi deployment id: {}".format(hash)
digest = generator.get_hash(length=40) # Get the full hash
self.Description = "RestApi deployment id: {}".format(digest)
stage.update_deployment_ref(self.logical_id)


Expand Down
20 changes: 10 additions & 10 deletions tests/translator/output/api_request_model_openapi_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
}
}
},
"HtmlApiDeploymentefb667b26e": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "HtmlApi"
},
"Description": "RestApi deployment id: efb667b26e8a0b0f733f5dfc27d039c1a2867db0"
}
},
"HtmlFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -49,7 +58,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "HtmlApiDeployment47f78fe7d9"
"Ref": "HtmlApiDeploymentefb667b26e"
},
"RestApiId": {
"Ref": "HtmlApi"
Expand Down Expand Up @@ -164,15 +173,6 @@
}
}
},
"HtmlApiDeployment47f78fe7d9": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "HtmlApi"
},
"Description": "RestApi deployment id: 47f78fe7d91eb5d2070674ad77943842c49dab89"
}
},
"HtmlFunctionGetHtmlPermissionTest": {
"Type": "AWS::Lambda::Permission",
"Properties": {
Expand Down
20 changes: 10 additions & 10 deletions tests/translator/output/api_with_auth_all_maximum_openapi_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@
}
}
},
"MyApiDeployment7d5eb3f14f": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyApi"
},
"Description": "RestApi deployment id: 7d5eb3f14f891b4276d48b764348b944dcaf2918"
}
},
"MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": {
"Type": "AWS::Lambda::Permission",
"Properties": {
Expand Down Expand Up @@ -453,20 +462,11 @@
}
}
},
"MyApiDeployment18e0cddfbf": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyApi"
},
"Description": "RestApi deployment id: 18e0cddfbf74ca986461d5a484b9eedd934a6423"
}
},
"MyApiProdStage": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "MyApiDeployment18e0cddfbf"
"Ref": "MyApiDeployment7d5eb3f14f"
},
"RestApiId": {
"Ref": "MyApi"
Expand Down
128 changes: 64 additions & 64 deletions tests/translator/output/api_with_auth_all_minimum_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "MyApiWithLambdaRequestAuthDeployment54a6335ed7"
"Ref": "MyApiWithLambdaRequestAuthDeployment14ab3ddf12"
},
"RestApiId": {
"Ref": "MyApiWithLambdaRequestAuth"
Expand Down Expand Up @@ -131,13 +131,25 @@
}
}
},
"MyApiWithLambdaTokenAuthDeployment2ac4484273": {
"Type": "AWS::ApiGateway::Deployment",
"MyFnCognitoPermissionTest": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"RestApiId": {
"Ref": "MyApiWithLambdaTokenAuth"
"Action": "lambda:invokeFunction",
"Principal": "apigateway.amazonaws.com",
"FunctionName": {
"Ref": "MyFn"
},
"Description": "RestApi deployment id: 2ac4484273f55c601b17c8491ffad73a979b2aeb"
"SourceArn": {
"Fn::Sub": [
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito",
{
"__Stage__": "*",
"__ApiId__": {
"Ref": "MyApiWithCognitoAuth"
}
}
]
}
}
},
"MyAuthFn": {
Expand All @@ -163,15 +175,6 @@
]
}
},
"MyApiWithCognitoAuthDeployment2eadfec019": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyApiWithCognitoAuth"
},
"Description": "RestApi deployment id: 2eadfec019d342cb7f6d66f595b9ab88e82fa00a"
}
},
"MyFnRole": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand All @@ -196,11 +199,20 @@
}
}
},
"MyApiWithLambdaRequestAuthDeployment14ab3ddf12": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyApiWithLambdaRequestAuth"
},
"Description": "RestApi deployment id: 14ab3ddf12ee76d46cac076ecffc24b3acd2fb7f"
}
},
"MyApiWithCognitoAuthProdStage": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "MyApiWithCognitoAuthDeployment2eadfec019"
"Ref": "MyApiWithCognitoAuthDeployment87cdbda651"
},
"RestApiId": {
"Ref": "MyApiWithCognitoAuth"
Expand Down Expand Up @@ -229,36 +241,6 @@
}
}
},
"MyApiWithLambdaRequestAuthDeployment54a6335ed7": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyApiWithLambdaRequestAuth"
},
"Description": "RestApi deployment id: 54a6335ed76c2060eaf1fff2ff6522f20ecaef0f"
}
},
"MyUserPool": {
"Type": "AWS::Cognito::UserPool",
"Properties": {
"UsernameAttributes": [
"email"
],
"UserPoolName": "UserPoolName",
"Policies": {
"PasswordPolicy": {
"MinimumLength": 8
}
},
"Schema": [
{
"AttributeDataType": "String",
"Required": false,
"Name": "email"
}
]
}
},
"MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
Expand Down Expand Up @@ -383,25 +365,25 @@
}
}
},
"MyFnCognitoPermissionTest": {
"Type": "AWS::Lambda::Permission",
"MyUserPool": {
"Type": "AWS::Cognito::UserPool",
"Properties": {
"Action": "lambda:invokeFunction",
"Principal": "apigateway.amazonaws.com",
"FunctionName": {
"Ref": "MyFn"
"UsernameAttributes": [
"email"
],
"UserPoolName": "UserPoolName",
"Policies": {
"PasswordPolicy": {
"MinimumLength": 8
}
},
"SourceArn": {
"Fn::Sub": [
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito",
{
"__Stage__": "*",
"__ApiId__": {
"Ref": "MyApiWithCognitoAuth"
}
}
]
}
"Schema": [
{
"AttributeDataType": "String",
"Required": false,
"Name": "email"
}
]
}
},
"MyFn": {
Expand Down Expand Up @@ -455,14 +437,23 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "MyApiWithLambdaTokenAuthDeployment2ac4484273"
"Ref": "MyApiWithLambdaTokenAuthDeployment4fdb5f4e3c"
},
"RestApiId": {
"Ref": "MyApiWithLambdaTokenAuth"
},
"StageName": "Prod"
}
},
"MyApiWithCognitoAuthDeployment87cdbda651": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyApiWithCognitoAuth"
},
"Description": "RestApi deployment id: 87cdbda651523df8d04d15fc50f72ae8ead08c1d"
}
},
"MyApiWithLambdaRequestAuth": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
Expand Down Expand Up @@ -522,6 +513,15 @@
}
}
}
},
"MyApiWithLambdaTokenAuthDeployment4fdb5f4e3c": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyApiWithLambdaTokenAuth"
},
"Description": "RestApi deployment id: 4fdb5f4e3c6e0e2b12af6d7a637ce66bb5bf7d0a"
}
}
}
}
26 changes: 13 additions & 13 deletions tests/translator/output/api_with_cors_openapi_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "ServerlessRestApiDeployment36174ded39"
"Ref": "ServerlessRestApiDeploymentf0997bcd64"
},
"RestApiId": {
"Ref": "ServerlessRestApi"
Expand All @@ -265,7 +265,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "ExplicitApiDeployment3a5a78688c"
"Ref": "ExplicitApiDeployment8cc53ffaa5"
},
"RestApiId": {
"Ref": "ExplicitApi"
Expand Down Expand Up @@ -318,13 +318,22 @@
}
}
},
"ExplicitApiDeployment3a5a78688c": {
"ExplicitApiDeployment8cc53ffaa5": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ExplicitApi"
},
"Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c"
"Description": "RestApi deployment id: 8cc53ffaa59a19b69e73d5b422142c7396739b16"
}
},
"ServerlessRestApiDeploymentf0997bcd64": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"Description": "RestApi deployment id: f0997bcd645ceb1529586bc2b9faf855687b46ce"
}
},
"RestApiFunction": {
Expand All @@ -350,15 +359,6 @@
]
}
},
"ServerlessRestApiDeployment36174ded39": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"Description": "RestApi deployment id: 36174ded3978092f96669107074db6caeaaafddd"
}
},
"ServerlessRestApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
Expand Down
Loading