From fedb013e3b19ab1242cf8e3ae28a40240103d9b1 Mon Sep 17 00:00:00 2001 From: Graham Jenson Date: Thu, 27 Feb 2020 19:01:50 -0800 Subject: [PATCH] feat(schema): Added CloudWatch Logs event for SAM (#271) --- ...serverless-function_cloudwatchlogsevent.go | 37 +++++++++++++++++++ .../serverless/function_properties.go | 9 ++++- generate/sam-2016-10-31.json | 18 +++++++++ go.mod | 5 ++- go.sum | 4 ++ schema/sam.go | 19 ++++++++++ schema/sam.schema.json | 19 ++++++++++ 7 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 cloudformation/serverless/aws-serverless-function_cloudwatchlogsevent.go diff --git a/cloudformation/serverless/aws-serverless-function_cloudwatchlogsevent.go b/cloudformation/serverless/aws-serverless-function_cloudwatchlogsevent.go new file mode 100644 index 0000000000..3a79117091 --- /dev/null +++ b/cloudformation/serverless/aws-serverless-function_cloudwatchlogsevent.go @@ -0,0 +1,37 @@ +package serverless + +import ( + "github.com/awslabs/goformation/v4/cloudformation/policies" +) + +// Function_CloudWatchLogsEvent AWS CloudFormation Resource (AWS::Serverless::Function.CloudWatchLogsEvent) +// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cloudwatchevent +type Function_CloudWatchLogsEvent struct { + + // FilterPattern AWS CloudFormation Property + // Required: true + // See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cloudwatchlogs + FilterPattern string `json:"FilterPattern,omitempty"` + + // LogGroupName AWS CloudFormation Property + // Required: true + // See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cloudwatchlogs + LogGroupName string `json:"LogGroupName,omitempty"` + + // AWSCloudFormationDeletionPolicy represents a CloudFormation DeletionPolicy + AWSCloudFormationDeletionPolicy policies.DeletionPolicy `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_CloudWatchLogsEvent) AWSCloudFormationType() string { + return "AWS::Serverless::Function.CloudWatchLogsEvent" +} diff --git a/cloudformation/serverless/function_properties.go b/cloudformation/serverless/function_properties.go index eb1c0652ff..2fd8e36be7 100644 --- a/cloudformation/serverless/function_properties.go +++ b/cloudformation/serverless/function_properties.go @@ -7,7 +7,7 @@ import ( "github.com/awslabs/goformation/v4/cloudformation/utils" ) -// Function_Properties is a helper struct that can hold either a S3Event, SNSEvent, SQSEvent, KinesisEvent, DynamoDBEvent, ApiEvent, ScheduleEvent, CloudWatchEventEvent, IoTRuleEvent, or AlexaSkillEvent value +// Function_Properties is a helper struct that can hold either a S3Event, SNSEvent, SQSEvent, KinesisEvent, DynamoDBEvent, ApiEvent, ScheduleEvent, CloudWatchEventEvent, CloudWatchLogsEvent, IoTRuleEvent, or AlexaSkillEvent value type Function_Properties struct { S3Event *Function_S3Event SNSEvent *Function_SNSEvent @@ -17,6 +17,7 @@ type Function_Properties struct { ApiEvent *Function_ApiEvent ScheduleEvent *Function_ScheduleEvent CloudWatchEventEvent *Function_CloudWatchEventEvent + CloudWatchLogsEvent *Function_CloudWatchLogsEvent IoTRuleEvent *Function_IoTRuleEvent AlexaSkillEvent *Function_AlexaSkillEvent } @@ -56,6 +57,10 @@ func (r Function_Properties) value() interface{} { ret = append(ret, *r.CloudWatchEventEvent) } + if r.CloudWatchLogsEvent != nil { + ret = append(ret, *r.CloudWatchLogsEvent) + } + if r.IoTRuleEvent != nil { ret = append(ret, *r.IoTRuleEvent) } @@ -106,6 +111,8 @@ func (r *Function_Properties) UnmarshalJSON(b []byte) error { json.Unmarshal(b, &r.CloudWatchEventEvent) + json.Unmarshal(b, &r.CloudWatchLogsEvent) + json.Unmarshal(b, &r.IoTRuleEvent) json.Unmarshal(b, &r.AlexaSkillEvent) diff --git a/generate/sam-2016-10-31.json b/generate/sam-2016-10-31.json index c61d72d8d9..7849d20dc1 100644 --- a/generate/sam-2016-10-31.json +++ b/generate/sam-2016-10-31.json @@ -439,6 +439,7 @@ "ApiEvent", "ScheduleEvent", "CloudWatchEventEvent", + "CloudWatchLogsEvent", "IoTRuleEvent", "AlexaSkillEvent" ], @@ -639,6 +640,23 @@ } } }, + "AWS::Serverless::Function.CloudWatchLogsEvent": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cloudwatchevent", + "Properties": { + "LogGroupName": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cloudwatchlogs", + "Required": true, + "PrimitiveType": "String", + "UpdateType": "Immutable" + }, + "FilterPattern": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cloudwatchlogs", + "Required": true, + "PrimitiveType": "String", + "UpdateType": "Immutable" + } + } + }, "AWS::Serverless::Function.IoTRuleEvent": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#iotrule", "Properties": { diff --git a/go.mod b/go.mod index 0dfeaa07d7..06aa95a5ad 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,16 @@ module github.com/awslabs/goformation/v4 require ( - github.com/awslabs/goformation/v3 v3.1.0 github.com/imdario/mergo v0.3.6 github.com/onsi/ginkgo v1.5.0 github.com/onsi/gomega v1.2.0 github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b github.com/sanathkr/yaml v0.0.0-20170819201035-0056894fa522 + github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect + github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonschema v0.0.0-20181112162635-ac52e6811b56 + golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect + gopkg.in/yaml.v2 v2.2.8 // indirect ) go 1.13 diff --git a/go.sum b/go.sum index e1f37ba6a4..637d7b0ca3 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,8 @@ github.com/xeipuuv/gojsonschema v0.0.0-20181112162635-ac52e6811b56/go.mod h1:5yf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20191021144547-ec77196f6094 h1:5O4U9trLjNpuhpynaDsqwCk+Tw6seqJz1EbqbnzHrc8= golang.org/x/net v0.0.0-20191021144547-ec77196f6094/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= @@ -47,3 +49,5 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/schema/sam.go b/schema/sam.go index 1500e9955c..54e390375e 100644 --- a/schema/sam.go +++ b/schema/sam.go @@ -55101,6 +55101,22 @@ var SamSchema = `{ ], "type": "object" }, + "AWS::Serverless::Function.CloudWatchLogsEvent": { + "additionalProperties": false, + "properties": { + "FilterPattern": { + "type": "string" + }, + "LogGroupName": { + "type": "string" + } + }, + "required": [ + "FilterPattern", + "LogGroupName" + ], + "type": "object" + }, "AWS::Serverless::Function.CollectionSAMPT": { "additionalProperties": false, "properties": { @@ -55227,6 +55243,9 @@ var SamSchema = `{ { "$ref": "#/definitions/AWS::Serverless::Function.CloudWatchEventEvent" }, + { + "$ref": "#/definitions/AWS::Serverless::Function.CloudWatchLogsEvent" + }, { "$ref": "#/definitions/AWS::Serverless::Function.IoTRuleEvent" }, diff --git a/schema/sam.schema.json b/schema/sam.schema.json index 1518623b6e..a7193e3b7e 100644 --- a/schema/sam.schema.json +++ b/schema/sam.schema.json @@ -55098,6 +55098,22 @@ ], "type": "object" }, + "AWS::Serverless::Function.CloudWatchLogsEvent": { + "additionalProperties": false, + "properties": { + "FilterPattern": { + "type": "string" + }, + "LogGroupName": { + "type": "string" + } + }, + "required": [ + "FilterPattern", + "LogGroupName" + ], + "type": "object" + }, "AWS::Serverless::Function.CollectionSAMPT": { "additionalProperties": false, "properties": { @@ -55224,6 +55240,9 @@ { "$ref": "#/definitions/AWS::Serverless::Function.CloudWatchEventEvent" }, + { + "$ref": "#/definitions/AWS::Serverless::Function.CloudWatchLogsEvent" + }, { "$ref": "#/definitions/AWS::Serverless::Function.IoTRuleEvent" },