Skip to content

Commit

Permalink
chore: more typed schema pass-throughs (#3072)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffa committed Mar 28, 2023
1 parent f55b9a5 commit 8d3efe8
Show file tree
Hide file tree
Showing 5 changed files with 312 additions and 131 deletions.
23 changes: 19 additions & 4 deletions samtranslator/internal/schema_source/aws_serverless_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
ResourceAttributes,
SamIntrinsicable,
get_prop,
passthrough_prop,
)

PROPERTIES_STEM = "sam-resource-application"

location = get_prop("sam-property-application-applicationlocationobject")
properties = get_prop("sam-resource-application")
properties = get_prop(PROPERTIES_STEM)


class Location(BaseModel):
Expand All @@ -23,10 +26,22 @@ class Location(BaseModel):

class Properties(BaseModel):
Location: Union[str, Location] = properties("Location")
NotificationARNs: Optional[PassThroughProp] = properties("NotificationARNs")
Parameters: Optional[PassThroughProp] = properties("Parameters")
NotificationARNs: Optional[PassThroughProp] = passthrough_prop(
PROPERTIES_STEM,
"NotificationARNs",
["AWS::CloudFormation::Stack", "Properties", "NotificationARNs"],
)
Parameters: Optional[PassThroughProp] = passthrough_prop(
PROPERTIES_STEM,
"Parameters",
["AWS::CloudFormation::Stack", "Properties", "Parameters"],
)
Tags: Optional[Dict[str, Any]] = properties("Tags")
TimeoutInMinutes: Optional[PassThroughProp] = properties("TimeoutInMinutes")
TimeoutInMinutes: Optional[PassThroughProp] = passthrough_prop(
PROPERTIES_STEM,
"TimeoutInMinutes",
["AWS::CloudFormation::Stack", "Properties", "TimeoutInMinutes"],
)


class Resource(ResourceAttributes):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,57 @@
ResourceAttributes,
SamIntrinsicable,
get_prop,
passthrough_prop,
)

contenturi = get_prop("sam-property-layerversion-layercontent")
properties = get_prop("sam-resource-layerversion")
PROPERTIES_STEM = "sam-resource-layerversion"
CONTENT_URI_STEM = "sam-property-layerversion-layercontent"

contenturi = get_prop(CONTENT_URI_STEM)
properties = get_prop(PROPERTIES_STEM)


class ContentUri(BaseModel):
Bucket: PassThroughProp = contenturi("Bucket")
Key: PassThroughProp = contenturi("Key")
Version: Optional[PassThroughProp] = contenturi("Version")
Bucket: PassThroughProp = passthrough_prop(
CONTENT_URI_STEM,
"Bucket",
["AWS::Lambda::LayerVersion.Content", "S3Bucket"],
)
Key: PassThroughProp = passthrough_prop(
CONTENT_URI_STEM,
"Key",
["AWS::Lambda::LayerVersion.Content", "S3Key"],
)
Version: Optional[PassThroughProp] = passthrough_prop(
CONTENT_URI_STEM,
"Version",
["AWS::Lambda::LayerVersion.Content", "S3ObjectVersion"],
)


class Properties(BaseModel):
CompatibleArchitectures: Optional[PassThroughProp] = properties("CompatibleArchitectures")
CompatibleRuntimes: Optional[PassThroughProp] = properties("CompatibleRuntimes")
CompatibleArchitectures: Optional[PassThroughProp] = passthrough_prop(
PROPERTIES_STEM,
"CompatibleArchitectures",
["AWS::Lambda::LayerVersion", "Properties", "CompatibleArchitectures"],
)
CompatibleRuntimes: Optional[PassThroughProp] = passthrough_prop(
PROPERTIES_STEM,
"CompatibleRuntimes",
["AWS::Lambda::LayerVersion", "Properties", "CompatibleRuntimes"],
)
ContentUri: Union[str, ContentUri] = properties("ContentUri")
Description: Optional[PassThroughProp] = properties("Description")
Description: Optional[PassThroughProp] = passthrough_prop(
PROPERTIES_STEM,
"Description",
["AWS::Lambda::LayerVersion", "Properties", "Description"],
)
LayerName: Optional[PassThroughProp] = properties("LayerName")
LicenseInfo: Optional[PassThroughProp] = properties("LicenseInfo")
LicenseInfo: Optional[PassThroughProp] = passthrough_prop(
PROPERTIES_STEM,
"LicenseInfo",
["AWS::Lambda::LayerVersion", "Properties", "LicenseInfo"],
)
RetentionPolicy: Optional[SamIntrinsicable[str]] = properties("RetentionPolicy")


Expand Down
51 changes: 42 additions & 9 deletions samtranslator/internal/schema_source/aws_serverless_simpletable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,63 @@
from typing_extensions import Literal

from samtranslator.internal.schema_source.aws_serverless_connector import EmbeddedConnector
from samtranslator.internal.schema_source.common import BaseModel, PassThroughProp, ResourceAttributes, get_prop
from samtranslator.internal.schema_source.common import (
BaseModel,
PassThroughProp,
ResourceAttributes,
get_prop,
passthrough_prop,
)

primarykey = get_prop("sam-property-simpletable-primarykeyobject")
properties = get_prop("sam-resource-simpletable")
PROPERTIES_STEM = "sam-resource-simpletable"
PRIMARY_KEY_STEM = "sam-property-simpletable-primarykeyobject"

primarykey = get_prop(PRIMARY_KEY_STEM)
properties = get_prop(PROPERTIES_STEM)


class PrimaryKey(BaseModel):
Name: PassThroughProp = primarykey("Name")
Type: PassThroughProp = primarykey("Type")
Name: PassThroughProp = passthrough_prop(
PRIMARY_KEY_STEM,
"Name",
["AWS::DynamoDB::Table.AttributeDefinition", "AttributeName"],
)
Type: PassThroughProp = passthrough_prop(
PRIMARY_KEY_STEM,
"Type",
["AWS::DynamoDB::Table.AttributeDefinition", "AttributeType"],
)


SSESpecification = Optional[PassThroughProp]


class Properties(BaseModel):
PrimaryKey: Optional[PrimaryKey] = properties("PrimaryKey")
ProvisionedThroughput: Optional[PassThroughProp] = properties("ProvisionedThroughput")
SSESpecification: Optional[SSESpecification] = properties("SSESpecification")
TableName: Optional[PassThroughProp] = properties("TableName")
ProvisionedThroughput: Optional[PassThroughProp] = passthrough_prop(
PROPERTIES_STEM,
"ProvisionedThroughput",
["AWS::DynamoDB::Table", "Properties", "ProvisionedThroughput"],
)
SSESpecification: Optional[SSESpecification] = passthrough_prop(
PROPERTIES_STEM,
"SSESpecification",
["AWS::DynamoDB::Table", "Properties", "SSESpecification"],
)
TableName: Optional[PassThroughProp] = passthrough_prop(
PROPERTIES_STEM,
"TableName",
["AWS::DynamoDB::Table", "Properties", "TableName"],
)
Tags: Optional[Dict[str, Any]] = properties("Tags")


class Globals(BaseModel):
SSESpecification: Optional[SSESpecification] = properties("SSESpecification")
SSESpecification: Optional[SSESpecification] = passthrough_prop(
PROPERTIES_STEM,
"SSESpecification",
["AWS::DynamoDB::Table", "Properties", "SSESpecification"],
)


class Resource(ResourceAttributes):
Expand Down
Loading

0 comments on commit 8d3efe8

Please sign in to comment.