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

Allow Api.Auth in Globals section #682

Merged
merged 12 commits into from
Jan 22, 2019
1 change: 1 addition & 0 deletions samtranslator/plugins/globals/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Globals(object):
# StageName: Because StageName cannot be overridden for Implicit APIs because of the current plugin
# architecture
SamResourceType.Api.value: [
'Auth',
"Name",
"DefinitionUri",
"CacheClusterEnabled",
Expand Down
19 changes: 17 additions & 2 deletions tests/translator/input/globals_for_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Globals:
Name: "some api"
CacheClusterEnabled: True
CacheClusterSize: "1.6"
Auth:
DefaultAuthorizer: MyCognitoAuth
Authorizers:
MyCognitoAuth:
UserPoolArn: !GetAtt MyUserPool.Arn
Variables:
SomeVar: Value

Expand All @@ -25,6 +30,16 @@ Resources:
Properties:
StageName: SomeStage
DefinitionBody:
"this": "is"
"a": "swagger"
swagger: 2.0
info:
version: '1.0'
title: !Ref AWS::StackName
paths:
"/":
get:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations
responses: {}

23 changes: 21 additions & 2 deletions tests/translator/output/aws-cn/globals_for_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,27 @@
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Body": {
"this": "is",
"a": "swagger"
"info": {
"version": "1.0",
"title": {
"Ref": "AWS::StackName"
}
},
"paths": {
"/": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations"
}
},
"responses": {}
}
}
},
"swagger": "2.0"
},
"EndpointConfiguration": {
"Types": [
Expand Down
93 changes: 80 additions & 13 deletions tests/translator/output/aws-us-gov/globals_for_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,52 @@
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Body": {
"this": "is",
"a": "swagger"
},
"info": {
"version": "1.0",
"title": {
"Ref": "AWS::StackName"
}
},
"paths": {
"/": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations"
keetonian marked this conversation as resolved.
Show resolved Hide resolved
}
},
"responses": {},
"security": [
{
"MyCognitoAuth": []
}
]
}
}
},
"swagger": 2.0,
keetonian marked this conversation as resolved.
Show resolved Hide resolved
"securityDefinitions": {
"MyCognitoAuth": {
"type": "apiKey",
"name": "Authorization",
"in": "header",
"x-amazon-apigateway-authtype": "cognito_user_pools",
"x-amazon-apigateway-authorizer": {
"type": "cognito_user_pools",
"providerARNs": [
{
"Fn::GetAtt": [
"MyUserPool",
"Arn"
]
}
]
}
}
}
},
"EndpointConfiguration": {
"Types": [
"REGIONAL"
Expand All @@ -107,13 +150,13 @@
}
}
},
"ServerlessRestApiDeployment5b2cb4ba8f": {
"ServerlessRestApiDeployment8d8686036d": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a",
"Description": "RestApi deployment id: 8d8686036d660a9db5398f6f9d1d3158923cac59",
"StageName": "Stage"
}
},
Expand All @@ -130,7 +173,7 @@
},
"CacheClusterEnabled": true,
"DeploymentId": {
"Ref": "ExplicitApiDeployment359f256a3b"
"Ref": "ExplicitApiDeploymentf8ca980dfb"
}
}
},
Expand All @@ -147,7 +190,7 @@
},
"CacheClusterEnabled": true,
"DeploymentId": {
"Ref": "ServerlessRestApiDeployment5b2cb4ba8f"
"Ref": "ServerlessRestApiDeployment8d8686036d"
}
}
},
Expand All @@ -171,12 +214,36 @@
"Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations"
}
},
"responses": {}
"responses": {},
"security": [
{
"MyCognitoAuth": []
}
]
}
}
},
"swagger": "2.0"
},
"swagger": "2.0",
"securityDefinitions": {
"MyCognitoAuth": {
"type": "apiKey",
"name": "Authorization",
"in": "header",
"x-amazon-apigateway-authtype": "cognito_user_pools",
"x-amazon-apigateway-authorizer": {
"type": "cognito_user_pools",
"providerARNs": [
{
"Fn::GetAtt": [
"MyUserPool",
"Arn"
]
}
]
}
}
}
},
"EndpointConfiguration": {
"Types": [
"REGIONAL"
Expand All @@ -188,15 +255,15 @@
}
}
},
"ExplicitApiDeployment359f256a3b": {
"ExplicitApiDeploymentf8ca980dfb": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ExplicitApi"
},
"Description": "RestApi deployment id: 359f256a3b3ff2e1102e335a4d603f02df9b4988",
"Description": "RestApi deployment id: f8ca980dfb884f427b861089480cf72d9094f39f",
"StageName": "Stage"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"errors": [
{
"errorMessage": "'Globals' section is invalid. 'StageName' is not a supported property of 'Api'. Must be one of the following values - ['Name', 'DefinitionUri', 'CacheClusterEnabled', 'CacheClusterSize', 'Variables', 'EndpointConfiguration', 'MethodSettings', 'BinaryMediaTypes', 'Cors', 'AccessLogSetting', 'CanarySetting']"
"errorMessage": "'Globals' section is invalid. 'StageName' is not a supported property of 'Api'. Must be one of the following values - ['Auth', 'Name', 'DefinitionUri', 'CacheClusterEnabled', 'CacheClusterSize', 'Variables', 'EndpointConfiguration', 'MethodSettings', 'BinaryMediaTypes', 'Cors', 'AccessLogSetting', 'CanarySetting']"
}
],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. 'Globals' section is invalid. 'StageName' is not a supported property of 'Api'. Must be one of the following values - ['Name', 'DefinitionUri', 'CacheClusterEnabled', 'CacheClusterSize', 'Variables', 'EndpointConfiguration', 'MethodSettings', 'BinaryMediaTypes', 'Cors', 'AccessLogSetting', 'CanarySetting', 'TracingEnabled']"
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. 'Globals' section is invalid. 'StageName' is not a supported property of 'Api'. Must be one of the following values - ['Auth', 'Name', 'DefinitionUri', 'CacheClusterEnabled', 'CacheClusterSize', 'Variables', 'EndpointConfiguration', 'MethodSettings', 'BinaryMediaTypes', 'Cors', 'AccessLogSetting', 'CanarySetting', 'TracingEnabled']"
}
93 changes: 80 additions & 13 deletions tests/translator/output/globals_for_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,52 @@
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Body": {
"this": "is",
"a": "swagger"
},
"info": {
"version": "1.0",
"title": {
"Ref": "AWS::StackName"
}
},
"paths": {
"/": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations"
}
},
"responses": {},
"security": [
{
"MyCognitoAuth": []
}
]
}
}
},
"swagger": 2.0,
"securityDefinitions": {
"MyCognitoAuth": {
"type": "apiKey",
"name": "Authorization",
"in": "header",
"x-amazon-apigateway-authtype": "cognito_user_pools",
"x-amazon-apigateway-authorizer": {
"type": "cognito_user_pools",
"providerARNs": [
{
"Fn::GetAtt": [
"MyUserPool",
"Arn"
]
}
]
}
}
}
},
"Name": "some api"
}
},
Expand All @@ -112,27 +155,27 @@
},
"CacheClusterEnabled": true,
"DeploymentId": {
"Ref": "ServerlessRestApiDeployment62b96c1a61"
"Ref": "ServerlessRestApiDeploymentaeab051f80"
}
}
},
"ServerlessRestApiDeployment62b96c1a61": {
"ServerlessRestApiDeploymentaeab051f80": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19",
"Description": "RestApi deployment id: aeab051f804635874701cd506a1540740a379961",
"StageName": "Stage"
}
},
"ExplicitApiDeployment359f256a3b": {
"ExplicitApiDeploymentf8ca980dfb": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ExplicitApi"
},
"Description": "RestApi deployment id: 359f256a3b3ff2e1102e335a4d603f02df9b4988",
"Description": "RestApi deployment id: f8ca980dfb884f427b861089480cf72d9094f39f",
"StageName": "Stage"
}
},
Expand All @@ -156,12 +199,36 @@
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations"
}
},
"responses": {}
"responses": {},
"security": [
{
"MyCognitoAuth": []
}
]
}
}
},
"swagger": "2.0"
},
"swagger": "2.0",
"securityDefinitions": {
"MyCognitoAuth": {
"type": "apiKey",
"name": "Authorization",
"in": "header",
"x-amazon-apigateway-authtype": "cognito_user_pools",
"x-amazon-apigateway-authorizer": {
"type": "cognito_user_pools",
"providerARNs": [
{
"Fn::GetAtt": [
"MyUserPool",
"Arn"
]
}
]
}
}
}
},
"Name": "some api"
}
},
Expand All @@ -178,9 +245,9 @@
},
"CacheClusterEnabled": true,
"DeploymentId": {
"Ref": "ExplicitApiDeployment359f256a3b"
"Ref": "ExplicitApiDeploymentf8ca980dfb"
}
}
}
}
}
}