Skip to content

Commit 50f2533

Browse files
authored
chore: more improved pass-through schema (#3060)
1 parent b4bc7a9 commit 50f2533

File tree

6 files changed

+703
-359
lines changed

6 files changed

+703
-359
lines changed

samtranslator/internal/schema_source/aws_serverless_api.py

Lines changed: 109 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
ResourceAttributes,
1313
SamIntrinsicable,
1414
get_prop,
15+
passthrough_prop,
1516
)
1617

18+
PROPERTIES_STEM = "sam-resource-api"
19+
1720
resourcepolicy = get_prop("sam-property-api-resourcepolicystatement")
1821
cognitoauthorizeridentity = get_prop("sam-property-api-cognitoauthorizationidentity")
1922
cognitoauthorizer = get_prop("sam-property-api-cognitoauthorizer")
@@ -28,7 +31,7 @@
2831
domain = get_prop("sam-property-api-domainconfiguration")
2932
definitionuri = get_prop("sam-property-api-apidefinition")
3033
endpointconfiguration = get_prop("sam-property-api-endpointconfiguration")
31-
properties = get_prop("sam-resource-api")
34+
properties = get_prop(PROPERTIES_STEM)
3235

3336

3437
class ResourcePolicy(BaseModel):
@@ -180,53 +183,137 @@ class EndpointConfiguration(BaseModel):
180183

181184

182185
class Properties(BaseModel):
183-
AccessLogSetting: Optional[AccessLogSetting] = properties("AccessLogSetting")
184-
ApiKeySourceType: Optional[PassThroughProp] = properties("ApiKeySourceType")
186+
AccessLogSetting: Optional[AccessLogSetting] = passthrough_prop(
187+
PROPERTIES_STEM,
188+
"AccessLogSetting",
189+
["AWS::ApiGateway::Stage", "Properties", "AccessLogSetting"],
190+
)
191+
ApiKeySourceType: Optional[PassThroughProp] = passthrough_prop(
192+
PROPERTIES_STEM,
193+
"ApiKeySourceType",
194+
["AWS::ApiGateway::RestApi", "Properties", "ApiKeySourceType"],
195+
)
185196
Auth: Optional[Auth] = properties("Auth")
186197
BinaryMediaTypes: Optional[BinaryMediaTypes] = properties("BinaryMediaTypes")
187-
CacheClusterEnabled: Optional[CacheClusterEnabled] = properties("CacheClusterEnabled")
188-
CacheClusterSize: Optional[CacheClusterSize] = properties("CacheClusterSize")
189-
CanarySetting: Optional[CanarySetting] = properties("CanarySetting")
198+
CacheClusterEnabled: Optional[CacheClusterEnabled] = passthrough_prop(
199+
PROPERTIES_STEM,
200+
"CacheClusterEnabled",
201+
["AWS::ApiGateway::Stage", "Properties", "CacheClusterEnabled"],
202+
)
203+
CacheClusterSize: Optional[CacheClusterSize] = passthrough_prop(
204+
PROPERTIES_STEM,
205+
"CacheClusterSize",
206+
["AWS::ApiGateway::Stage", "Properties", "CacheClusterSize"],
207+
)
208+
CanarySetting: Optional[CanarySetting] = passthrough_prop(
209+
PROPERTIES_STEM,
210+
"CanarySetting",
211+
["AWS::ApiGateway::Stage", "Properties", "CanarySetting"],
212+
)
190213
Cors: Optional[CorsType] = properties("Cors")
191214
DefinitionBody: Optional[DictStrAny] = properties("DefinitionBody")
192215
DefinitionUri: Optional[DefinitionUriType] = properties("DefinitionUri")
193216
MergeDefinitions: Optional[MergeDefinitions] = properties("MergeDefinitions")
194-
Description: Optional[PassThroughProp] = properties("Description")
217+
Description: Optional[PassThroughProp] = passthrough_prop(
218+
PROPERTIES_STEM,
219+
"Description",
220+
["AWS::ApiGateway::Stage", "Properties", "Description"],
221+
)
195222
DisableExecuteApiEndpoint: Optional[PassThroughProp] = properties("DisableExecuteApiEndpoint")
196223
Domain: Optional[Domain] = properties("Domain")
197224
EndpointConfiguration: Optional[EndpointConfigurationType] = properties("EndpointConfiguration")
198-
FailOnWarnings: Optional[PassThroughProp] = properties("FailOnWarnings")
225+
FailOnWarnings: Optional[PassThroughProp] = passthrough_prop(
226+
PROPERTIES_STEM,
227+
"FailOnWarnings",
228+
["AWS::ApiGateway::RestApi", "Properties", "FailOnWarnings"],
229+
)
199230
GatewayResponses: Optional[GatewayResponses] = properties("GatewayResponses")
200-
MethodSettings: Optional[MethodSettings] = properties("MethodSettings")
201-
MinimumCompressionSize: Optional[MinimumCompressionSize] = properties("MinimumCompressionSize")
202-
Mode: Optional[PassThroughProp] = properties("Mode")
231+
MethodSettings: Optional[MethodSettings] = passthrough_prop(
232+
PROPERTIES_STEM,
233+
"MethodSettings",
234+
["AWS::ApiGateway::Stage", "Properties", "MethodSettings"],
235+
)
236+
MinimumCompressionSize: Optional[MinimumCompressionSize] = passthrough_prop(
237+
PROPERTIES_STEM,
238+
"MinimumCompressionSize",
239+
["AWS::ApiGateway::RestApi", "Properties", "MinimumCompressionSize"],
240+
)
241+
Mode: Optional[PassThroughProp] = passthrough_prop(
242+
PROPERTIES_STEM,
243+
"Mode",
244+
["AWS::ApiGateway::RestApi", "Properties", "Mode"],
245+
)
203246
Models: Optional[DictStrAny] = properties("Models")
204-
Name: Optional[Name] = properties("Name")
247+
Name: Optional[Name] = passthrough_prop(
248+
PROPERTIES_STEM,
249+
"Name",
250+
["AWS::ApiGateway::RestApi", "Properties", "Name"],
251+
)
205252
OpenApiVersion: Optional[OpenApiVersion] = properties("OpenApiVersion")
206253
StageName: SamIntrinsicable[str] = properties("StageName")
207254
Tags: Optional[DictStrAny] = properties("Tags")
208-
TracingEnabled: Optional[TracingEnabled] = properties("TracingEnabled")
209-
Variables: Optional[Variables] = properties("Variables")
255+
TracingEnabled: Optional[TracingEnabled] = passthrough_prop(
256+
PROPERTIES_STEM,
257+
"TracingEnabled",
258+
["AWS::ApiGateway::Stage", "Properties", "TracingEnabled"],
259+
)
260+
Variables: Optional[Variables] = passthrough_prop(
261+
PROPERTIES_STEM,
262+
"Variables",
263+
["AWS::ApiGateway::Stage", "Properties", "Variables"],
264+
)
210265
AlwaysDeploy: Optional[AlwaysDeploy] = properties("AlwaysDeploy")
211266

212267

213268
class Globals(BaseModel):
214269
Auth: Optional[Auth] = properties("Auth")
215-
Name: Optional[Name] = properties("Name")
270+
Name: Optional[Name] = passthrough_prop(
271+
PROPERTIES_STEM,
272+
"Name",
273+
["AWS::ApiGateway::RestApi", "Properties", "Name"],
274+
)
216275
DefinitionUri: Optional[PassThroughProp] = properties("DefinitionUri")
217-
CacheClusterEnabled: Optional[CacheClusterEnabled] = properties("CacheClusterEnabled")
218-
CacheClusterSize: Optional[CacheClusterSize] = properties("CacheClusterSize")
276+
CacheClusterEnabled: Optional[CacheClusterEnabled] = passthrough_prop(
277+
PROPERTIES_STEM,
278+
"CacheClusterEnabled",
279+
["AWS::ApiGateway::Stage", "Properties", "CacheClusterEnabled"],
280+
)
281+
CacheClusterSize: Optional[CacheClusterSize] = passthrough_prop(
282+
PROPERTIES_STEM,
283+
"CacheClusterSize",
284+
["AWS::ApiGateway::Stage", "Properties", "CacheClusterSize"],
285+
)
219286
MergeDefinitions: Optional[MergeDefinitions] = properties("MergeDefinitions")
220-
Variables: Optional[Variables] = properties("Variables")
287+
Variables: Optional[Variables] = passthrough_prop(
288+
PROPERTIES_STEM,
289+
"Variables",
290+
["AWS::ApiGateway::Stage", "Properties", "Variables"],
291+
)
221292
EndpointConfiguration: Optional[PassThroughProp] = properties("EndpointConfiguration")
222293
MethodSettings: Optional[MethodSettings] = properties("MethodSettings")
223294
BinaryMediaTypes: Optional[BinaryMediaTypes] = properties("BinaryMediaTypes")
224-
MinimumCompressionSize: Optional[MinimumCompressionSize] = properties("MinimumCompressionSize")
295+
MinimumCompressionSize: Optional[MinimumCompressionSize] = passthrough_prop(
296+
PROPERTIES_STEM,
297+
"MinimumCompressionSize",
298+
["AWS::ApiGateway::RestApi", "Properties", "MinimumCompressionSize"],
299+
)
225300
Cors: Optional[CorsType] = properties("Cors")
226301
GatewayResponses: Optional[GatewayResponses] = properties("GatewayResponses")
227-
AccessLogSetting: Optional[AccessLogSetting] = properties("AccessLogSetting")
228-
CanarySetting: Optional[CanarySetting] = properties("CanarySetting")
229-
TracingEnabled: Optional[TracingEnabled] = properties("TracingEnabled")
302+
AccessLogSetting: Optional[AccessLogSetting] = passthrough_prop(
303+
PROPERTIES_STEM,
304+
"AccessLogSetting",
305+
["AWS::ApiGateway::Stage", "Properties", "AccessLogSetting"],
306+
)
307+
CanarySetting: Optional[CanarySetting] = passthrough_prop(
308+
PROPERTIES_STEM,
309+
"CanarySetting",
310+
["AWS::ApiGateway::Stage", "Properties", "CanarySetting"],
311+
)
312+
TracingEnabled: Optional[TracingEnabled] = passthrough_prop(
313+
PROPERTIES_STEM,
314+
"TracingEnabled",
315+
["AWS::ApiGateway::Stage", "Properties", "TracingEnabled"],
316+
)
230317
OpenApiVersion: Optional[OpenApiVersion] = properties("OpenApiVersion")
231318
Domain: Optional[Domain] = properties("Domain")
232319
AlwaysDeploy: Optional[AlwaysDeploy] = properties("AlwaysDeploy")

samtranslator/internal/schema_source/aws_serverless_function.py

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818

1919
PROPERTIES_STEM = "sam-resource-function"
20+
DEPLOYMENT_PREFERENCE_STEM = "sam-property-function-deploymentpreference"
2021

2122
alexaskilleventproperties = get_prop("sam-property-function-alexaskill")
2223
apiauth = get_prop("sam-property-function-apifunctionauth")
@@ -26,7 +27,7 @@
2627
codeuri = get_prop("sam-property-function-functioncode")
2728
cognitoeventproperties = get_prop("sam-property-function-cognito")
2829
deadletterconfig = get_prop("sam-property-function-deadletterconfig")
29-
deploymentpreference = get_prop("sam-property-function-deploymentpreference")
30+
deploymentpreference = get_prop(DEPLOYMENT_PREFERENCE_STEM)
3031
dlq = get_prop("sam-property-function-deadletterqueue")
3132
documentdbeventproperties = get_prop("sam-property-function-documentdb")
3233
dynamodbeventproperties = get_prop("sam-property-function-dynamodb")
@@ -46,7 +47,7 @@
4647
kinesiseventproperties = get_prop("sam-property-function-kinesis")
4748
mqeventproperties = get_prop("sam-property-function-mq")
4849
mskeventproperties = get_prop("sam-property-function-msk")
49-
prop = get_prop("sam-resource-function")
50+
prop = get_prop(PROPERTIES_STEM)
5051
requestmodel = get_prop("sam-property-function-requestmodel")
5152
requestparameters = get_prop("sam-property-function-requestparameter")
5253
resourcepolicy = get_prop("sam-property-api-resourcepolicystatement")
@@ -89,7 +90,11 @@ class DeploymentPreference(BaseModel):
8990
Hooks: Optional[Hooks] = deploymentpreference("Hooks")
9091
PassthroughCondition: Optional[SamIntrinsicable[bool]] = deploymentpreference("PassthroughCondition")
9192
Role: Optional[SamIntrinsicable[str]] = deploymentpreference("Role")
92-
TriggerConfigurations: Optional[PassThroughProp] = deploymentpreference("TriggerConfigurations")
93+
TriggerConfigurations: Optional[PassThroughProp] = passthrough_prop(
94+
DEPLOYMENT_PREFERENCE_STEM,
95+
"TriggerConfigurations",
96+
["AWS::CodeDeploy::DeploymentGroup", "Properties", "TriggerConfigurations"],
97+
)
9398
Type: Optional[SamIntrinsicable[str]] = deploymentpreference(
9499
"Type"
95100
) # TODO: Should investigate whether this is a required field. This is a required field on documentation. However, we don't seem to use this field.
@@ -494,28 +499,38 @@ class ScheduleV2Event(BaseModel):
494499

495500

496501
class Properties(BaseModel):
497-
Architectures: Optional[Architectures] = prop("Architectures")
502+
Architectures: Optional[Architectures] = passthrough_prop(
503+
PROPERTIES_STEM,
504+
"Architectures",
505+
["AWS::Lambda::Function", "Properties", "Architectures"],
506+
)
498507
AssumeRolePolicyDocument: Optional[AssumeRolePolicyDocument] = prop("AssumeRolePolicyDocument")
499508
AutoPublishAlias: Optional[AutoPublishAlias] = prop("AutoPublishAlias")
500509
AutoPublishAliasAllProperties: Optional[AutoPublishAliasAllProperties] = prop("AutoPublishAliasAllProperties")
501510
AutoPublishCodeSha256: Optional[SamIntrinsicable[str]] = prop("AutoPublishCodeSha256")
502-
CodeSigningConfigArn: Optional[SamIntrinsicable[str]] = prop("CodeSigningConfigArn")
511+
CodeSigningConfigArn: Optional[SamIntrinsicable[str]] = passthrough_prop(
512+
PROPERTIES_STEM,
513+
"CodeSigningConfigArn",
514+
["AWS::Lambda::Function", "Properties", "CodeSigningConfigArn"],
515+
)
503516
CodeUri: Optional[CodeUriType] = prop("CodeUri")
504517
DeadLetterQueue: Optional[DeadLetterQueueType] = prop("DeadLetterQueue")
505518
DeploymentPreference: Optional[DeploymentPreference] = prop("DeploymentPreference")
506-
Description: Optional[Description] = prop("Description")
519+
Description: Optional[Description] = passthrough_prop(
520+
PROPERTIES_STEM,
521+
"Description",
522+
["AWS::Lambda::Function", "Properties", "Description"],
523+
)
507524
# TODO: Make the notation shorter; resource type and SAM/CFN property names usually same
508525
Environment: Optional[Environment] = passthrough_prop(
509526
PROPERTIES_STEM,
510527
"Environment",
511-
"AWS::Lambda::Function",
512-
"Environment",
528+
["AWS::Lambda::Function", "Properties", "Environment"],
513529
)
514530
EphemeralStorage: Optional[EphemeralStorage] = passthrough_prop(
515531
PROPERTIES_STEM,
516532
"EphemeralStorage",
517-
"AWS::Lambda::Function",
518-
"EphemeralStorage",
533+
["AWS::Lambda::Function", "Properties", "EphemeralStorage"],
519534
)
520535
EventInvokeConfig: Optional[EventInvokeConfig] = prop("EventInvokeConfig")
521536
Events: Optional[
@@ -544,22 +559,32 @@ class Properties(BaseModel):
544559
],
545560
]
546561
] = prop("Events")
547-
FileSystemConfigs: Optional[PassThroughProp] = prop("FileSystemConfigs")
562+
FileSystemConfigs: Optional[PassThroughProp] = passthrough_prop(
563+
PROPERTIES_STEM,
564+
"FileSystemConfigs",
565+
["AWS::Lambda::Function", "Properties", "FileSystemConfigs"],
566+
)
548567
FunctionName: Optional[PassThroughProp] = passthrough_prop(
549568
PROPERTIES_STEM,
550569
"FunctionName",
551-
"AWS::Lambda::Function",
552-
"FunctionName",
570+
["AWS::Lambda::Function", "Properties", "FunctionName"],
553571
)
554572
FunctionUrlConfig: Optional[FunctionUrlConfig] = prop("FunctionUrlConfig")
555573
Handler: Optional[Handler] = passthrough_prop(
556574
PROPERTIES_STEM,
557575
"Handler",
558-
"AWS::Lambda::Function",
559-
"Handler",
576+
["AWS::Lambda::Function", "Properties", "Handler"],
577+
)
578+
ImageConfig: Optional[PassThroughProp] = passthrough_prop(
579+
PROPERTIES_STEM,
580+
"ImageConfig",
581+
["AWS::Lambda::Function", "Properties", "ImageConfig"],
582+
)
583+
ImageUri: Optional[PassThroughProp] = passthrough_prop(
584+
PROPERTIES_STEM,
585+
"ImageUri",
586+
["AWS::Lambda::Function.Code", "ImageUri"],
560587
)
561-
ImageConfig: Optional[PassThroughProp] = prop("ImageConfig")
562-
ImageUri: Optional[PassThroughProp] = prop("ImageUri")
563588
InlineCode: Optional[PassThroughProp] = prop("InlineCode")
564589
KmsKeyArn: Optional[KmsKeyArn] = prop("KmsKeyArn")
565590
Layers: Optional[Layers] = prop("Layers")
@@ -568,29 +593,25 @@ class Properties(BaseModel):
568593
RolePath: Optional[RolePath] = passthrough_prop(
569594
PROPERTIES_STEM,
570595
"RolePath",
571-
"AWS::IAM::Role",
572-
"Path",
596+
["AWS::IAM::Role", "Properties", "Path"],
573597
)
574598
PermissionsBoundary: Optional[PermissionsBoundary] = passthrough_prop(
575599
PROPERTIES_STEM,
576600
"PermissionsBoundary",
577-
"AWS::IAM::Role",
578-
"PermissionsBoundary",
601+
["AWS::IAM::Role", "Properties", "PermissionsBoundary"],
579602
)
580603
Policies: Optional[Union[str, DictStrAny, List[Union[str, DictStrAny]]]] = prop("Policies")
581604
ProvisionedConcurrencyConfig: Optional[ProvisionedConcurrencyConfig] = passthrough_prop(
582605
PROPERTIES_STEM,
583606
"ProvisionedConcurrencyConfig",
584-
"AWS::Lambda::Alias",
585-
"ProvisionedConcurrencyConfig",
607+
["AWS::Lambda::Alias", "Properties", "ProvisionedConcurrencyConfig"],
586608
)
587609
ReservedConcurrentExecutions: Optional[ReservedConcurrentExecutions] = prop("ReservedConcurrentExecutions")
588610
Role: Optional[SamIntrinsicable[str]] = prop("Role")
589611
Runtime: Optional[Runtime] = passthrough_prop(
590612
PROPERTIES_STEM,
591613
"Runtime",
592-
"AWS::Lambda::Function",
593-
"Runtime",
614+
["AWS::Lambda::Function", "Properties", "Runtime"],
594615
)
595616
SnapStart: Optional[SnapStart] = prop("SnapStart")
596617
RuntimeManagementConfig: Optional[RuntimeManagementConfig] = prop("RuntimeManagementConfig")
@@ -605,14 +626,12 @@ class Globals(BaseModel):
605626
Handler: Optional[Handler] = passthrough_prop(
606627
PROPERTIES_STEM,
607628
"Handler",
608-
"AWS::Lambda::Function",
609-
"Handler",
629+
["AWS::Lambda::Function", "Properties", "Handler"],
610630
)
611631
Runtime: Optional[Runtime] = passthrough_prop(
612632
PROPERTIES_STEM,
613633
"Runtime",
614-
"AWS::Lambda::Function",
615-
"Runtime",
634+
["AWS::Lambda::Function", "Properties", "Runtime"],
616635
)
617636
CodeUri: Optional[CodeUriType] = prop("CodeUri")
618637
DeadLetterQueue: Optional[DeadLetterQueueType] = prop("DeadLetterQueue")
@@ -623,8 +642,7 @@ class Globals(BaseModel):
623642
Environment: Optional[Environment] = passthrough_prop(
624643
PROPERTIES_STEM,
625644
"Environment",
626-
"AWS::Lambda::Function",
627-
"Environment",
645+
["AWS::Lambda::Function", "Properties", "Environment"],
628646
)
629647
Tags: Optional[Tags] = prop("Tags")
630648
Tracing: Optional[Tracing] = prop("Tracing")
@@ -635,25 +653,26 @@ class Globals(BaseModel):
635653
RolePath: Optional[RolePath] = passthrough_prop(
636654
PROPERTIES_STEM,
637655
"RolePath",
638-
"AWS::IAM::Role",
639-
"Path",
656+
["AWS::IAM::Role", "Properties", "Path"],
640657
)
641658
PermissionsBoundary: Optional[PermissionsBoundary] = passthrough_prop(
642659
PROPERTIES_STEM,
643660
"PermissionsBoundary",
644-
"AWS::IAM::Role",
645-
"PermissionsBoundary",
661+
["AWS::IAM::Role", "Properties", "PermissionsBoundary"],
646662
)
647663
ReservedConcurrentExecutions: Optional[ReservedConcurrentExecutions] = prop("ReservedConcurrentExecutions")
648664
ProvisionedConcurrencyConfig: Optional[ProvisionedConcurrencyConfig] = prop("ProvisionedConcurrencyConfig")
649665
AssumeRolePolicyDocument: Optional[AssumeRolePolicyDocument] = prop("AssumeRolePolicyDocument")
650666
EventInvokeConfig: Optional[EventInvokeConfig] = prop("EventInvokeConfig")
651-
Architectures: Optional[Architectures] = prop("Architectures")
667+
Architectures: Optional[Architectures] = passthrough_prop(
668+
PROPERTIES_STEM,
669+
"Architectures",
670+
["AWS::Lambda::Function", "Properties", "Architectures"],
671+
)
652672
EphemeralStorage: Optional[EphemeralStorage] = passthrough_prop(
653673
PROPERTIES_STEM,
654674
"EphemeralStorage",
655-
"AWS::Lambda::Function",
656-
"EphemeralStorage",
675+
["AWS::Lambda::Function", "Properties", "EphemeralStorage"],
657676
)
658677
SnapStart: Optional[SnapStart] = prop("SnapStart")
659678
RuntimeManagementConfig: Optional[RuntimeManagementConfig] = prop("RuntimeManagementConfig")

0 commit comments

Comments
 (0)