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 intrinsics for some less important fields #3253

Merged
merged 2 commits into from
Jul 12, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ class ApiKey(BaseModel):
class Logging(BaseModel):
CloudWatchLogsRoleArn: Optional[PassThroughProp]
ExcludeVerboseContent: Optional[PassThroughProp]
FieldLogLevel: Optional[str]
FieldLogLevel: Optional[PassThroughProp]


class DeltaSync(BaseModel):
BaseTableTTL: str
DeltaSyncTableName: str
DeltaSyncTableTTL: str
BaseTableTTL: PassThroughProp
DeltaSyncTableName: PassThroughProp
DeltaSyncTableTTL: PassThroughProp


class DynamoDBDataSource(BaseModel):
TableName: PassThroughProp
ServiceRoleArn: Optional[PassThroughProp]
TableArn: Optional[PassThroughProp]
Permissions: Optional[PermissionsType]
Name: Optional[str]
Name: Optional[PassThroughProp]
Description: Optional[PassThroughProp]
Region: Optional[PassThroughProp]
DeltaSync: Optional[DeltaSync]
Expand All @@ -82,7 +82,7 @@ class DynamoDBDataSource(BaseModel):
class LambdaDataSource(BaseModel):
FunctionArn: PassThroughProp
ServiceRoleArn: Optional[PassThroughProp]
Name: Optional[str]
Name: Optional[PassThroughProp]
Description: Optional[PassThroughProp]


Expand Down Expand Up @@ -153,7 +153,7 @@ class Cache(BaseModel):
class Properties(BaseModel):
Auth: Auth
Tags: Optional[DictStrAny]
Name: Optional[str]
Name: Optional[PassThroughProp]
XrayEnabled: Optional[bool]
SchemaInline: Optional[PassThroughProp]
SchemaUri: Optional[PassThroughProp]
Expand Down
14 changes: 7 additions & 7 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@ class SamGraphQLApi(SamResourceMacro):

resource_type = "AWS::Serverless::GraphQLApi"
property_types = {
"Name": Property(False, IS_STR),
"Name": PassThroughProperty(False),
"Tags": Property(False, IS_DICT),
"XrayEnabled": PassThroughProperty(False),
"Auth": Property(True, IS_DICT),
Expand All @@ -2211,7 +2211,7 @@ class SamGraphQLApi(SamResourceMacro):
Auth: List[Dict[str, Any]]
Tags: Optional[Dict[str, Any]]
XrayEnabled: Optional[PassThrough]
Name: Optional[str]
Name: Optional[PassThrough]
SchemaInline: Optional[str]
SchemaUri: Optional[str]
Logging: Optional[Union[Dict[str, Any], bool]]
Expand Down Expand Up @@ -2290,7 +2290,7 @@ def _construct_appsync_api_resources(
) -> Tuple[GraphQLApi, Optional[IAMRole], List[SamConnector]]:
api = GraphQLApi(logical_id=self.logical_id, depends_on=self.depends_on, attributes=self.resource_attributes)

api.Name = model.Name or self.logical_id
api.Name = passthrough_value(model.Name) or self.logical_id
api.XrayEnabled = model.XrayEnabled

lambda_auth_arns = self._parse_and_set_auth_properties(api, model.Auth)
Expand Down Expand Up @@ -2465,7 +2465,7 @@ def _parse_logging_properties(
if model.Logging.ExcludeVerboseContent:
log_config["ExcludeVerboseContent"] = cast(PassThrough, model.Logging.ExcludeVerboseContent)

log_config["FieldLogLevel"] = model.Logging.FieldLogLevel or "ALL"
log_config["FieldLogLevel"] = passthrough_value(model.Logging.FieldLogLevel) or "ALL"
log_config["CloudWatchLogsRoleArn"] = cast(PassThrough, model.Logging.CloudWatchLogsRoleArn)

if log_config["CloudWatchLogsRoleArn"]:
Expand Down Expand Up @@ -2598,7 +2598,7 @@ def _construct_ddb_datasources(
)

# Datasource "Name" property must be unique from all other datasources.
cfn_datasource.Name = ddb_datasource.Name or relative_id
cfn_datasource.Name = passthrough_value(ddb_datasource.Name) or relative_id
cfn_datasource.Type = "AMAZON_DYNAMODB"
cfn_datasource.ApiId = api_id
cfn_datasource.Description = passthrough_value(ddb_datasource.Description)
Expand Down Expand Up @@ -2652,7 +2652,7 @@ def _parse_ddb_datasource_role(
def _parse_ddb_config(self, ddb_datasource: aws_serverless_graphqlapi.DynamoDBDataSource) -> DynamoDBConfigType:
ddb_config: DynamoDBConfigType = {}

ddb_config["AwsRegion"] = cast(PassThrough, ddb_datasource.Region) or ref("AWS::Region")
ddb_config["AwsRegion"] = passthrough_value(ddb_datasource.Region) or ref("AWS::Region")
ddb_config["TableName"] = passthrough_value(ddb_datasource.TableName)

if ddb_datasource.UseCallerCredentials:
Expand Down Expand Up @@ -2713,7 +2713,7 @@ def _construct_lambda_datasources(
logical_id=datasource_logical_id, depends_on=self.depends_on, attributes=self.resource_attributes
)

cfn_datasource.Name = lambda_datasource.Name or relative_id
cfn_datasource.Name = passthrough_value(lambda_datasource.Name) or relative_id
cfn_datasource.Type = "AWS_LAMBDA"
cfn_datasource.ApiId = api_id
cfn_datasource.Description = passthrough_value(lambda_datasource.Description)
Expand Down
21 changes: 7 additions & 14 deletions samtranslator/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -241895,16 +241895,13 @@
"additionalProperties": false,
"properties": {
"BaseTableTTL": {
"title": "Basetablettl",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
},
"DeltaSyncTableName": {
"title": "Deltasynctablename",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
},
"DeltaSyncTableTTL": {
"title": "Deltasynctablettl",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
}
},
"required": [
Expand Down Expand Up @@ -242176,8 +242173,7 @@
"$ref": "#/definitions/PassThroughProp"
},
"Name": {
"title": "Name",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
},
"Permissions": {
"items": {
Expand Down Expand Up @@ -243264,8 +243260,7 @@
"$ref": "#/definitions/PassThroughProp"
},
"Name": {
"title": "Name",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
},
"ServiceRoleArn": {
"$ref": "#/definitions/PassThroughProp"
Expand Down Expand Up @@ -243516,8 +243511,7 @@
"$ref": "#/definitions/PassThroughProp"
},
"FieldLogLevel": {
"title": "Fieldloglevel",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
}
},
"title": "Logging",
Expand Down Expand Up @@ -247182,8 +247176,7 @@
"title": "Logging"
},
"Name": {
"title": "Name",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
},
"Resolvers": {
"additionalProperties": {
Expand Down
21 changes: 7 additions & 14 deletions schema_source/sam.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,13 @@
"additionalProperties": false,
"properties": {
"BaseTableTTL": {
"title": "Basetablettl",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
},
"DeltaSyncTableName": {
"title": "Deltasynctablename",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
},
"DeltaSyncTableTTL": {
"title": "Deltasynctablettl",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
}
},
"required": [
Expand Down Expand Up @@ -850,8 +847,7 @@
"$ref": "#/definitions/PassThroughProp"
},
"Name": {
"title": "Name",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
},
"Permissions": {
"items": {
Expand Down Expand Up @@ -1956,8 +1952,7 @@
"$ref": "#/definitions/PassThroughProp"
},
"Name": {
"title": "Name",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
},
"ServiceRoleArn": {
"$ref": "#/definitions/PassThroughProp"
Expand Down Expand Up @@ -2208,8 +2203,7 @@
"$ref": "#/definitions/PassThroughProp"
},
"FieldLogLevel": {
"title": "Fieldloglevel",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
}
},
"title": "Logging",
Expand Down Expand Up @@ -6541,8 +6535,7 @@
"title": "Logging"
},
"Name": {
"title": "Name",
"type": "string"
"$ref": "#/definitions/PassThroughProp"
},
"Resolvers": {
"additionalProperties": {
Expand Down
57 changes: 57 additions & 0 deletions tests/translator/input/graphqlapi_intrinsical_names.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Transform: AWS::Serverless-2016-10-31

Parameters:
ApiName:
Type: String
Default: SomeApi
LambdaDSName:
Type: String
Default: MyLamdaDS
DDB1DSName:
Type: String
Default: MyDDB1DS
MyLoggingLevel:
Type: String
Default: ALL
PassItThrough:
Type: String
Default: SomeValue

Resources:
SuperCoolAPI:
Type: AWS::Serverless::GraphQLApi
Properties:
Name: !Ref ApiName
SchemaInline: |
type Todo {
id: ID!
description: String!
}
type Mutation {
addTodo(id: ID!, description: String!): Todo!
}
type Query {
getTodo(id: ID!): Todo
}
schema {
mutation: Mutation
query: Query
}
Auth:
Type: AWS_IAM
Logging:
FieldLogLevel: !Ref MyLoggingLevel
DataSources:
Lambda:
MyDataSource:
FunctionArn: my-lambda-arn
ServiceRoleArn: some-role-arn
Name: !Ref LambdaDSName
DynamoDb:
DDB1:
Name: !Ref DDB1DSName
TableName: AwesomeTable
DeltaSync:
BaseTableTTL: !Ref PassItThrough
DeltaSyncTableName: !Ref PassItThrough
DeltaSyncTableTTL: !Ref PassItThrough
Loading