From 25103fcd21b490021ee8cfd23674599afc1f0a14 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Thu, 24 Aug 2023 13:36:31 +0200 Subject: [PATCH] feat(lambda_function): add FunctionUrlConfig property --- cloudformation/global/function.go | 5 ++ .../serverless/aws-serverless-function.go | 5 ++ ...s-serverless-function_corsconfiguration.go | 57 ++++++++++++++ ...s-serverless-function_functionurlconfig.go | 47 ++++++++++++ cloudformation/serverless/function_cors.go | 76 +++++++++++++++++++ generate/sam-2016-10-31.json | 69 +++++++++++++++++ schema/sam.go | 57 ++++++++++++++ schema/sam.schema.json | 57 ++++++++++++++ .../aws-serverless-function-2016-10-31.yaml | 3 + 9 files changed, 376 insertions(+) create mode 100644 cloudformation/serverless/aws-serverless-function_corsconfiguration.go create mode 100644 cloudformation/serverless/aws-serverless-function_functionurlconfig.go create mode 100644 cloudformation/serverless/function_cors.go diff --git a/cloudformation/global/function.go b/cloudformation/global/function.go index e871423ae7..db8677eec0 100644 --- a/cloudformation/global/function.go +++ b/cloudformation/global/function.go @@ -65,6 +65,11 @@ type Function struct { // See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction EventInvokeConfig *serverless.Function_EventInvokeConfig `json:"EventInvokeConfig,omitempty"` + // FunctionUrlConfig AWS CloudFormation Property + // Required: false + // See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionurlconfig.html + FunctionUrlConfig *serverless.Function_FunctionUrlConfig `json:"FunctionUrlConfig,omitempty"` + // Handler AWS CloudFormation Property // Required: false // See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction diff --git a/cloudformation/serverless/aws-serverless-function.go b/cloudformation/serverless/aws-serverless-function.go index 6e9e22736c..a258335f4c 100644 --- a/cloudformation/serverless/aws-serverless-function.go +++ b/cloudformation/serverless/aws-serverless-function.go @@ -83,6 +83,11 @@ type Function struct { // See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction FunctionName *string `json:"FunctionName,omitempty"` + // FunctionUrlConfig AWS CloudFormation Property + // Required: false + // See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionurlconfig.html + FunctionUrlConfig *Function_FunctionUrlConfig `json:"FunctionUrlConfig,omitempty"` + // Handler AWS CloudFormation Property // Required: false // See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction diff --git a/cloudformation/serverless/aws-serverless-function_corsconfiguration.go b/cloudformation/serverless/aws-serverless-function_corsconfiguration.go new file mode 100644 index 0000000000..fe1831351c --- /dev/null +++ b/cloudformation/serverless/aws-serverless-function_corsconfiguration.go @@ -0,0 +1,57 @@ +// Code generated by "go generate". Please don't change this file directly. + +package serverless + +import ( + "github.com/awslabs/goformation/v7/cloudformation/policies" +) + +// Function_CorsConfiguration AWS CloudFormation Resource (AWS::Serverless::Function.CorsConfiguration) +// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration +type Function_CorsConfiguration struct { + + // AllowCredentials AWS CloudFormation Property + // Required: false + // See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration + AllowCredentials *bool `json:"AllowCredentials,omitempty"` + + // AllowHeaders AWS CloudFormation Property + // Required: false + // See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration + AllowHeaders *string `json:"AllowHeaders,omitempty"` + + // AllowMethods AWS CloudFormation Property + // Required: false + // See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration + AllowMethods *string `json:"AllowMethods,omitempty"` + + // AllowOrigin AWS CloudFormation Property + // Required: true + // See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration + AllowOrigin string `json:"AllowOrigin"` + + // MaxAge AWS CloudFormation Property + // Required: false + // See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration + MaxAge *string `json:"MaxAge,omitempty"` + + // AWSCloudFormationDeletionPolicy represents a CloudFormation DeletionPolicy + AWSCloudFormationDeletionPolicy policies.DeletionPolicy `json:"-"` + + // AWSCloudFormationUpdateReplacePolicy represents a CloudFormation UpdateReplacePolicy + AWSCloudFormationUpdateReplacePolicy policies.UpdateReplacePolicy `json:"-"` + + // AWSCloudFormationDependsOn stores the logical ID of the resources to be created before this resource + AWSCloudFormationDependsOn []string `json:"-"` + + // AWSCloudFormationMetadata stores structured data associated with this resource + AWSCloudFormationMetadata map[string]interface{} `json:"-"` + + // AWSCloudFormationCondition stores the logical ID of the condition that must be satisfied for this resource to be created + AWSCloudFormationCondition string `json:"-"` +} + +// AWSCloudFormationType returns the AWS CloudFormation resource type +func (r *Function_CorsConfiguration) AWSCloudFormationType() string { + return "AWS::Serverless::Function.CorsConfiguration" +} diff --git a/cloudformation/serverless/aws-serverless-function_functionurlconfig.go b/cloudformation/serverless/aws-serverless-function_functionurlconfig.go new file mode 100644 index 0000000000..890db1b683 --- /dev/null +++ b/cloudformation/serverless/aws-serverless-function_functionurlconfig.go @@ -0,0 +1,47 @@ +// Code generated by "go generate". Please don't change this file directly. + +package serverless + +import ( + "github.com/awslabs/goformation/v7/cloudformation/policies" +) + +// Function_FunctionUrlConfig AWS CloudFormation Resource (AWS::Serverless::Function.FunctionUrlConfig) +// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionurlconfig.html +type Function_FunctionUrlConfig struct { + + // AuthType AWS CloudFormation Property + // Required: true + // See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionurlconfig.html#sam-function-functionurlconfig-authtype + AuthType string `json:"AuthType"` + + // Cors AWS CloudFormation Property + // Required: false + // See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionurlconfig.html#sam-function-functionurlconfig-cors + Cors *Function_Cors `json:"Cors,omitempty"` + + // InvokeMode AWS CloudFormation Property + // Required: false + // See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionurlconfig.html#sam-function-functionurlconfig-invokemode + InvokeMode *string `json:"InvokeMode,omitempty"` + + // AWSCloudFormationDeletionPolicy represents a CloudFormation DeletionPolicy + AWSCloudFormationDeletionPolicy policies.DeletionPolicy `json:"-"` + + // AWSCloudFormationUpdateReplacePolicy represents a CloudFormation UpdateReplacePolicy + AWSCloudFormationUpdateReplacePolicy policies.UpdateReplacePolicy `json:"-"` + + // AWSCloudFormationDependsOn stores the logical ID of the resources to be created before this resource + AWSCloudFormationDependsOn []string `json:"-"` + + // AWSCloudFormationMetadata stores structured data associated with this resource + AWSCloudFormationMetadata map[string]interface{} `json:"-"` + + // AWSCloudFormationCondition stores the logical ID of the condition that must be satisfied for this resource to be created + AWSCloudFormationCondition string `json:"-"` +} + +// AWSCloudFormationType returns the AWS CloudFormation resource type +func (r *Function_FunctionUrlConfig) AWSCloudFormationType() string { + return "AWS::Serverless::Function.FunctionUrlConfig" +} diff --git a/cloudformation/serverless/function_cors.go b/cloudformation/serverless/function_cors.go new file mode 100644 index 0000000000..86f082c80f --- /dev/null +++ b/cloudformation/serverless/function_cors.go @@ -0,0 +1,76 @@ +// Code generated by "go generate". Please don't change this file directly. + +package serverless + +import ( + "bytes" + "encoding/json" + "io" + "sort" + + "github.com/awslabs/goformation/v7/cloudformation/utils" +) + +// Function_Cors is a helper struct that can hold either a String or CorsConfiguration value +type Function_Cors struct { + String *string + + CorsConfiguration *Function_CorsConfiguration +} + +func (r Function_Cors) value() interface{} { + ret := []interface{}{} + + if r.String != nil { + ret = append(ret, r.String) + } + + if r.CorsConfiguration != nil { + ret = append(ret, *r.CorsConfiguration) + } + + sort.Sort(utils.ByJSONLength(ret)) // Heuristic to select best attribute + if len(ret) > 0 { + return ret[0] + } + + return nil +} + +func (r Function_Cors) MarshalJSON() ([]byte, error) { + return json.Marshal(r.value()) +} + +// Hook into the marshaller +func (r *Function_Cors) UnmarshalJSON(b []byte) error { + + // Unmarshal into interface{} to check it's type + var typecheck interface{} + if err := json.Unmarshal(b, &typecheck); err != nil { + return err + } + + switch val := typecheck.(type) { + + case string: + r.String = &val + + case map[string]interface{}: + val = val // This ensures val is used to stop an error + + reader := bytes.NewReader(b) + decoder := json.NewDecoder(reader) + decoder.DisallowUnknownFields() + reader.Seek(0, io.SeekStart) + + if err := decoder.Decode(&r.CorsConfiguration); err != nil { + r.CorsConfiguration = nil + } + reader.Seek(0, io.SeekStart) + + case []interface{}: + + } + + return nil +} diff --git a/generate/sam-2016-10-31.json b/generate/sam-2016-10-31.json index d52fca810c..6fff3f836c 100644 --- a/generate/sam-2016-10-31.json +++ b/generate/sam-2016-10-31.json @@ -264,6 +264,12 @@ "Type": "List", "PrimitiveItemType": "String", "UpdateType": "Immutable" + }, + "FunctionUrlConfig": { + "Documentation": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionurlconfig.html", + "Required": false, + "Type": "FunctionUrlConfig", + "UpdateType": "Immutable" } } }, @@ -2089,6 +2095,69 @@ } } }, + "AWS::Serverless::Function.FunctionUrlConfig": { + "Documentation": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionurlconfig.html", + "Properties": { + "AuthType": { + "Documentation": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionurlconfig.html#sam-function-functionurlconfig-authtype", + "Required": true, + "PrimitiveType": "String", + "UpdateType": "Immutable" + }, + "Cors": { + "Documentation": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionurlconfig.html#sam-function-functionurlconfig-cors", + "Required": false, + "PrimitiveTypes": [ + "String" + ], + "Types": [ + "CorsConfiguration" + ], + "UpdateType": "Immutable" + }, + "InvokeMode": { + "Documentation": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionurlconfig.html#sam-function-functionurlconfig-invokemode", + "Required": false, + "PrimitiveType": "String", + "UpdateType": "Immutable" + } + } + }, + "AWS::Serverless::Function.CorsConfiguration": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration", + "Properties": { + "AllowMethods": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration", + "Required": false, + "PrimitiveType": "String", + "UpdateType": "Immutable" + }, + "AllowHeaders": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration", + "Required": false, + "PrimitiveType": "String", + "UpdateType": "Immutable" + }, + "AllowOrigin": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration", + "Required": true, + "PrimitiveType": "String", + "UpdateType": "Immutable" + }, + "MaxAge": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration", + "Required": false, + "PrimitiveType": "String", + "UpdateType": "Immutable" + }, + "AllowCredentials": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration", + "Required": false, + "PrimitiveType": "Boolean", + "UpdateType": "Immutable" + } + } + }, "AWS::Serverless::StateMachine.LoggingConfiguration": { "Documentation": "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stepfunctions-statemachine-loggingconfiguration.html", "Properties": { diff --git a/schema/sam.go b/schema/sam.go index e502c6f8bb..e40a588ebd 100644 --- a/schema/sam.go +++ b/schema/sam.go @@ -183816,6 +183816,9 @@ var SamSchema = `{ "FunctionName": { "type": "string" }, + "FunctionUrlConfig": { + "$ref": "#/definitions/AWS::Serverless::Function.FunctionUrlConfig" + }, "Handler": { "type": "string" }, @@ -184164,6 +184167,30 @@ var SamSchema = `{ ], "type": "object" }, + "AWS::Serverless::Function.CorsConfiguration": { + "additionalProperties": false, + "properties": { + "AllowCredentials": { + "type": "boolean" + }, + "AllowHeaders": { + "type": "string" + }, + "AllowMethods": { + "type": "string" + }, + "AllowOrigin": { + "type": "string" + }, + "MaxAge": { + "type": "string" + } + }, + "required": [ + "AllowOrigin" + ], + "type": "object" + }, "AWS::Serverless::Function.DeadLetterQueue": { "additionalProperties": false, "properties": { @@ -184447,6 +184474,33 @@ var SamSchema = `{ ], "type": "object" }, + "AWS::Serverless::Function.FunctionUrlConfig": { + "additionalProperties": false, + "properties": { + "AuthType": { + "type": "string" + }, + "Cors": { + "anyOf": [ + { + "type": [ + "string" + ] + }, + { + "$ref": "#/definitions/AWS::Serverless::Function.CorsConfiguration" + } + ] + }, + "InvokeMode": { + "type": "string" + } + }, + "required": [ + "AuthType" + ], + "type": "object" + }, "AWS::Serverless::Function.HttpApiEvent": { "additionalProperties": false, "properties": { @@ -199064,6 +199118,9 @@ var SamSchema = `{ "EventInvokeConfig": { "$ref": "#/definitions/AWS::Serverless::Function.EventInvokeConfig" }, + "FunctionUrlConfig": { + "$ref": "#/definitions/AWS::Serverless::Function.FunctionUrlConfig" + }, "Handler": { "type": "string" }, diff --git a/schema/sam.schema.json b/schema/sam.schema.json index 67f1f12e0e..86a127d5c4 100644 --- a/schema/sam.schema.json +++ b/schema/sam.schema.json @@ -183811,6 +183811,9 @@ "FunctionName": { "type": "string" }, + "FunctionUrlConfig": { + "$ref": "#/definitions/AWS::Serverless::Function.FunctionUrlConfig" + }, "Handler": { "type": "string" }, @@ -184159,6 +184162,30 @@ ], "type": "object" }, + "AWS::Serverless::Function.CorsConfiguration": { + "additionalProperties": false, + "properties": { + "AllowCredentials": { + "type": "boolean" + }, + "AllowHeaders": { + "type": "string" + }, + "AllowMethods": { + "type": "string" + }, + "AllowOrigin": { + "type": "string" + }, + "MaxAge": { + "type": "string" + } + }, + "required": [ + "AllowOrigin" + ], + "type": "object" + }, "AWS::Serverless::Function.DeadLetterQueue": { "additionalProperties": false, "properties": { @@ -184442,6 +184469,33 @@ ], "type": "object" }, + "AWS::Serverless::Function.FunctionUrlConfig": { + "additionalProperties": false, + "properties": { + "AuthType": { + "type": "string" + }, + "Cors": { + "anyOf": [ + { + "type": [ + "string" + ] + }, + { + "$ref": "#/definitions/AWS::Serverless::Function.CorsConfiguration" + } + ] + }, + "InvokeMode": { + "type": "string" + } + }, + "required": [ + "AuthType" + ], + "type": "object" + }, "AWS::Serverless::Function.HttpApiEvent": { "additionalProperties": false, "properties": { @@ -199059,6 +199113,9 @@ "EventInvokeConfig": { "$ref": "#/definitions/AWS::Serverless::Function.EventInvokeConfig" }, + "FunctionUrlConfig": { + "$ref": "#/definitions/AWS::Serverless::Function.FunctionUrlConfig" + }, "Handler": { "type": "string" }, diff --git a/test/yaml/aws-serverless-function-2016-10-31.yaml b/test/yaml/aws-serverless-function-2016-10-31.yaml index 61fc3ed45e..03a480ffed 100644 --- a/test/yaml/aws-serverless-function-2016-10-31.yaml +++ b/test/yaml/aws-serverless-function-2016-10-31.yaml @@ -7,6 +7,9 @@ Resources: Runtime: nodejs CodeUri: s3://bucket/path/key FunctionName: functionname + FunctionUrlConfig: + AuthType: AWS_IAM + InvokeMode: BUFFERED Description: description MemorySize: 128 Timeout: 30