From 3e8a2bf78c094bcd3fad4fa3ef540fe43af6b127 Mon Sep 17 00:00:00 2001 From: Slava Senchenko Date: Fri, 17 Nov 2023 12:54:13 -0800 Subject: [PATCH] adding new appsync props (#3423) --- samtranslator/internal/model/appsync.py | 4 ++ .../aws_serverless_graphqlapi.py | 2 + samtranslator/model/sam_resources.py | 11 ++++ samtranslator/schema/schema.json | 6 ++ schema_source/sam.schema.json | 6 ++ .../graphqlapi_visibility_owner_contract.yaml | 13 ++++ .../graphqlapi_visibility_owner_contract.json | 66 +++++++++++++++++++ .../graphqlapi_visibility_owner_contract.json | 66 +++++++++++++++++++ .../graphqlapi_visibility_owner_contract.json | 66 +++++++++++++++++++ 9 files changed, 240 insertions(+) create mode 100644 tests/translator/input/graphqlapi_visibility_owner_contract.yaml create mode 100644 tests/translator/output/aws-cn/graphqlapi_visibility_owner_contract.json create mode 100644 tests/translator/output/aws-us-gov/graphqlapi_visibility_owner_contract.json create mode 100644 tests/translator/output/graphqlapi_visibility_owner_contract.json diff --git a/samtranslator/internal/model/appsync.py b/samtranslator/internal/model/appsync.py index 5182db1a7..de81660c5 100644 --- a/samtranslator/internal/model/appsync.py +++ b/samtranslator/internal/model/appsync.py @@ -113,6 +113,8 @@ class GraphQLApi(Resource): "OpenIDConnectConfig": GeneratedProperty(), "UserPoolConfig": GeneratedProperty(), "AdditionalAuthenticationProviders": GeneratedProperty(), + "Visibility": GeneratedProperty(), + "OwnerContact": GeneratedProperty(), } Name: str @@ -124,6 +126,8 @@ class GraphQLApi(Resource): Tags: Optional[List[Dict[str, Any]]] XrayEnabled: Optional[bool] LogConfig: Optional[LogConfigType] + Visibility: Optional[str] + OwnerContact: Optional[str] runtime_attrs = {"api_id": lambda self: fnGetAtt(self.logical_id, "ApiId")} diff --git a/samtranslator/internal/schema_source/aws_serverless_graphqlapi.py b/samtranslator/internal/schema_source/aws_serverless_graphqlapi.py index 541e4a7e3..b731abee7 100644 --- a/samtranslator/internal/schema_source/aws_serverless_graphqlapi.py +++ b/samtranslator/internal/schema_source/aws_serverless_graphqlapi.py @@ -162,6 +162,8 @@ class Properties(BaseModel): ApiKeys: Optional[Dict[str, ApiKey]] DomainName: Optional[DomainName] Cache: Optional[Cache] + Visibility: Optional[PassThroughProp] + OwnerContact: Optional[PassThroughProp] class Resource(BaseModel): diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index d5f78047c..4aeed875c 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -2215,6 +2215,8 @@ class SamGraphQLApi(SamResourceMacro): "ApiKeys": Property(False, IS_DICT), "DomainName": Property(False, IS_DICT), "Cache": Property(False, IS_DICT), + "Visibility": PassThroughProperty(False), + "OwnerContact": PassThroughProperty(False), } Auth: List[Dict[str, Any]] @@ -2230,6 +2232,8 @@ class SamGraphQLApi(SamResourceMacro): ApiKeys: Optional[Dict[str, Dict[str, Any]]] DomainName: Optional[Dict[str, Any]] Cache: Optional[Dict[str, Any]] + Visibility: Optional[PassThrough] + OwnerContact: Optional[PassThrough] # stop validation so we can use class variables for tracking state validate_setattr = False @@ -2300,6 +2304,13 @@ def _construct_appsync_api_resources( api = GraphQLApi(logical_id=self.logical_id, depends_on=self.depends_on, attributes=self.resource_attributes) api.Name = passthrough_value(model.Name) or self.logical_id + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-visibility + # WARNING: If Visibility has not been defined, explicitly setting it to GLOBAL in a template/stack update will result in an API replacement and new DNS values. + # we don't want to force client's API re-creation + if model.Visibility: + api.Visibility = passthrough_value(model.Visibility) + if model.OwnerContact: + api.OwnerContact = passthrough_value(model.OwnerContact) api.XrayEnabled = model.XrayEnabled lambda_auth_arns = self._parse_and_set_auth_properties(api, model.Auth) diff --git a/samtranslator/schema/schema.json b/samtranslator/schema/schema.json index 992959354..1e233e79f 100644 --- a/samtranslator/schema/schema.json +++ b/samtranslator/schema/schema.json @@ -258761,6 +258761,9 @@ "Name": { "$ref": "#/definitions/PassThroughProp" }, + "OwnerContact": { + "$ref": "#/definitions/PassThroughProp" + }, "Resolvers": { "additionalProperties": { "additionalProperties": { @@ -258781,6 +258784,9 @@ "title": "Tags", "type": "object" }, + "Visibility": { + "$ref": "#/definitions/PassThroughProp" + }, "XrayEnabled": { "title": "Xrayenabled", "type": "boolean" diff --git a/schema_source/sam.schema.json b/schema_source/sam.schema.json index 196150ed3..2a9899e1b 100644 --- a/schema_source/sam.schema.json +++ b/schema_source/sam.schema.json @@ -6649,6 +6649,9 @@ "Name": { "$ref": "#/definitions/PassThroughProp" }, + "OwnerContact": { + "$ref": "#/definitions/PassThroughProp" + }, "Resolvers": { "additionalProperties": { "additionalProperties": { @@ -6669,6 +6672,9 @@ "title": "Tags", "type": "object" }, + "Visibility": { + "$ref": "#/definitions/PassThroughProp" + }, "XrayEnabled": { "title": "Xrayenabled", "type": "boolean" diff --git a/tests/translator/input/graphqlapi_visibility_owner_contract.yaml b/tests/translator/input/graphqlapi_visibility_owner_contract.yaml new file mode 100644 index 000000000..468b0b607 --- /dev/null +++ b/tests/translator/input/graphqlapi_visibility_owner_contract.yaml @@ -0,0 +1,13 @@ +Transform: AWS::Serverless-2016-10-31 +Resources: + SuperCoolAPI: + Type: AWS::Serverless::GraphQLApi + Properties: + SchemaInline: | + type Mutation { + addTodo(id: ID!, name: String, description: String, priority: Int): Todo + } + Visibility: PRIVATE + OwnerContact: blah-blah + Auth: + Type: AWS_IAM diff --git a/tests/translator/output/aws-cn/graphqlapi_visibility_owner_contract.json b/tests/translator/output/aws-cn/graphqlapi_visibility_owner_contract.json new file mode 100644 index 000000000..aed0dd720 --- /dev/null +++ b/tests/translator/output/aws-cn/graphqlapi_visibility_owner_contract.json @@ -0,0 +1,66 @@ +{ + "Resources": { + "SuperCoolAPI": { + "Properties": { + "AuthenticationType": "AWS_IAM", + "LogConfig": { + "CloudWatchLogsRoleArn": { + "Fn::GetAtt": [ + "SuperCoolAPICloudWatchRole", + "Arn" + ] + }, + "FieldLogLevel": "ALL" + }, + "Name": "SuperCoolAPI", + "OwnerContact": "blah-blah", + "Tags": [ + { + "Key": "graphqlapi:createdBy", + "Value": "SAM" + } + ], + "Visibility": "PRIVATE" + }, + "Type": "AWS::AppSync::GraphQLApi" + }, + "SuperCoolAPICloudWatchRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "appsync.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSAppSyncPushToCloudWatchLogs" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "SuperCoolAPISchema": { + "Properties": { + "ApiId": { + "Fn::GetAtt": [ + "SuperCoolAPI", + "ApiId" + ] + }, + "Definition": "type Mutation {\n addTodo(id: ID!, name: String, description: String, priority: Int): Todo\n}\n" + }, + "Type": "AWS::AppSync::GraphQLSchema" + } + } +} diff --git a/tests/translator/output/aws-us-gov/graphqlapi_visibility_owner_contract.json b/tests/translator/output/aws-us-gov/graphqlapi_visibility_owner_contract.json new file mode 100644 index 000000000..aed0dd720 --- /dev/null +++ b/tests/translator/output/aws-us-gov/graphqlapi_visibility_owner_contract.json @@ -0,0 +1,66 @@ +{ + "Resources": { + "SuperCoolAPI": { + "Properties": { + "AuthenticationType": "AWS_IAM", + "LogConfig": { + "CloudWatchLogsRoleArn": { + "Fn::GetAtt": [ + "SuperCoolAPICloudWatchRole", + "Arn" + ] + }, + "FieldLogLevel": "ALL" + }, + "Name": "SuperCoolAPI", + "OwnerContact": "blah-blah", + "Tags": [ + { + "Key": "graphqlapi:createdBy", + "Value": "SAM" + } + ], + "Visibility": "PRIVATE" + }, + "Type": "AWS::AppSync::GraphQLApi" + }, + "SuperCoolAPICloudWatchRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "appsync.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSAppSyncPushToCloudWatchLogs" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "SuperCoolAPISchema": { + "Properties": { + "ApiId": { + "Fn::GetAtt": [ + "SuperCoolAPI", + "ApiId" + ] + }, + "Definition": "type Mutation {\n addTodo(id: ID!, name: String, description: String, priority: Int): Todo\n}\n" + }, + "Type": "AWS::AppSync::GraphQLSchema" + } + } +} diff --git a/tests/translator/output/graphqlapi_visibility_owner_contract.json b/tests/translator/output/graphqlapi_visibility_owner_contract.json new file mode 100644 index 000000000..aed0dd720 --- /dev/null +++ b/tests/translator/output/graphqlapi_visibility_owner_contract.json @@ -0,0 +1,66 @@ +{ + "Resources": { + "SuperCoolAPI": { + "Properties": { + "AuthenticationType": "AWS_IAM", + "LogConfig": { + "CloudWatchLogsRoleArn": { + "Fn::GetAtt": [ + "SuperCoolAPICloudWatchRole", + "Arn" + ] + }, + "FieldLogLevel": "ALL" + }, + "Name": "SuperCoolAPI", + "OwnerContact": "blah-blah", + "Tags": [ + { + "Key": "graphqlapi:createdBy", + "Value": "SAM" + } + ], + "Visibility": "PRIVATE" + }, + "Type": "AWS::AppSync::GraphQLApi" + }, + "SuperCoolAPICloudWatchRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "appsync.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSAppSyncPushToCloudWatchLogs" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "SuperCoolAPISchema": { + "Properties": { + "ApiId": { + "Fn::GetAtt": [ + "SuperCoolAPI", + "ApiId" + ] + }, + "Definition": "type Mutation {\n addTodo(id: ID!, name: String, description: String, priority: Int): Todo\n}\n" + }, + "Type": "AWS::AppSync::GraphQLSchema" + } + } +}