Skip to content

Commit

Permalink
adding new appsync props (#3423)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssenchenko authored Nov 17, 2023
1 parent c6f153d commit 3e8a2bf
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 0 deletions.
4 changes: 4 additions & 0 deletions samtranslator/internal/model/appsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class GraphQLApi(Resource):
"OpenIDConnectConfig": GeneratedProperty(),
"UserPoolConfig": GeneratedProperty(),
"AdditionalAuthenticationProviders": GeneratedProperty(),
"Visibility": GeneratedProperty(),
"OwnerContact": GeneratedProperty(),
}

Name: str
Expand All @@ -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")}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions samtranslator/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -258761,6 +258761,9 @@
"Name": {
"$ref": "#/definitions/PassThroughProp"
},
"OwnerContact": {
"$ref": "#/definitions/PassThroughProp"
},
"Resolvers": {
"additionalProperties": {
"additionalProperties": {
Expand All @@ -258781,6 +258784,9 @@
"title": "Tags",
"type": "object"
},
"Visibility": {
"$ref": "#/definitions/PassThroughProp"
},
"XrayEnabled": {
"title": "Xrayenabled",
"type": "boolean"
Expand Down
6 changes: 6 additions & 0 deletions schema_source/sam.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6649,6 +6649,9 @@
"Name": {
"$ref": "#/definitions/PassThroughProp"
},
"OwnerContact": {
"$ref": "#/definitions/PassThroughProp"
},
"Resolvers": {
"additionalProperties": {
"additionalProperties": {
Expand All @@ -6669,6 +6672,9 @@
"title": "Tags",
"type": "object"
},
"Visibility": {
"$ref": "#/definitions/PassThroughProp"
},
"XrayEnabled": {
"title": "Xrayenabled",
"type": "boolean"
Expand Down
13 changes: 13 additions & 0 deletions tests/translator/input/graphqlapi_visibility_owner_contract.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
66 changes: 66 additions & 0 deletions tests/translator/output/graphqlapi_visibility_owner_contract.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

0 comments on commit 3e8a2bf

Please sign in to comment.