Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
fix(schema): S3Location or String support for AWS::Serverless::LayerV…
Browse files Browse the repository at this point in the history
…ersion.ContentUri (#339)

* S3Location support for LayerVersion.ContentUri

Update to SAM schema
Fixes #337

* go generate

Regenerate resources to support S3Location property for
AWS::Serverless::LayerVersion.ContentUri
  • Loading branch information
PaulMaddox authored Jan 5, 2021
1 parent bdaec19 commit 6e39ebe
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cloudformation/serverless/aws-serverless-layerversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type LayerVersion struct {
// ContentUri AWS CloudFormation Property
// Required: false
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesslayerversion
ContentUri string `json:"ContentUri,omitempty"`
ContentUri *LayerVersion_ContentUri `json:"ContentUri,omitempty"`

// Description AWS CloudFormation Property
// Required: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package serverless

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
)

// LayerVersion_S3Location AWS CloudFormation Resource (AWS::Serverless::LayerVersion.S3Location)
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#s3-location-object
type LayerVersion_S3Location struct {

// Bucket AWS CloudFormation Property
// Required: true
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Bucket string `json:"Bucket,omitempty"`

// Key AWS CloudFormation Property
// Required: true
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Key string `json:"Key,omitempty"`

// Version AWS CloudFormation Property
// Required: false
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Version int `json:"Version,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 *LayerVersion_S3Location) AWSCloudFormationType() string {
return "AWS::Serverless::LayerVersion.S3Location"
}
64 changes: 64 additions & 0 deletions cloudformation/serverless/layerversion_contenturi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package serverless

import (
"encoding/json"
"sort"

"github.com/awslabs/goformation/v4/cloudformation/utils"
)

// LayerVersion_ContentUri is a helper struct that can hold either a String or S3Location value
type LayerVersion_ContentUri struct {
String *string

S3Location *LayerVersion_S3Location
}

func (r LayerVersion_ContentUri) value() interface{} {
ret := []interface{}{}

if r.String != nil {
ret = append(ret, r.String)
}

if r.S3Location != nil {
ret = append(ret, *r.S3Location)
}

sort.Sort(utils.ByJSONLength(ret)) // Heuristic to select best attribute
if len(ret) > 0 {
return ret[0]
}

return nil
}

func (r LayerVersion_ContentUri) MarshalJSON() ([]byte, error) {
return json.Marshal(r.value())
}

// Hook into the marshaller
func (r *LayerVersion_ContentUri) 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

json.Unmarshal(b, &r.S3Location)

case []interface{}:

}

return nil
}
30 changes: 29 additions & 1 deletion generate/sam-2016-10-31.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,12 @@
"ContentUri": {
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesslayerversion",
"Required": false,
"PrimitiveType": "String",
"PrimitiveTypes": [
"String"
],
"Types": [
"S3Location"
],
"UpdateType": "Immutable"
},
"CompatibleRuntimes": {
Expand Down Expand Up @@ -522,6 +527,29 @@
}
}
},
"AWS::Serverless::LayerVersion.S3Location": {
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#s3-location-object",
"Properties": {
"Bucket": {
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction",
"Required": true,
"PrimitiveType": "String",
"UpdateType": "Immutable"
},
"Key": {
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction",
"Required": true,
"PrimitiveType": "String",
"UpdateType": "Immutable"
},
"Version": {
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction",
"Required": false,
"PrimitiveType": "Integer",
"UpdateType": "Immutable"
}
}
},
"AWS::Serverless::Function.FileSystemConfig": {
"Documentation": "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-filesystemconfig.html#cfn-lambda-function-filesystemconfig-localmountpath",
"Properties": {
Expand Down
30 changes: 29 additions & 1 deletion schema/sam.go
Original file line number Diff line number Diff line change
Expand Up @@ -85179,7 +85179,16 @@ var SamSchema = `{
"type": "array"
},
"ContentUri": {
"type": "string"
"anyOf": [
{
"type": [
"string"
]
},
{
"$ref": "#/definitions/AWS::Serverless::LayerVersion.S3Location"
}
]
},
"Description": {
"type": "string"
Expand Down Expand Up @@ -85216,6 +85225,25 @@ var SamSchema = `{
],
"type": "object"
},
"AWS::Serverless::LayerVersion.S3Location": {
"additionalProperties": false,
"properties": {
"Bucket": {
"type": "string"
},
"Key": {
"type": "string"
},
"Version": {
"type": "number"
}
},
"required": [
"Bucket",
"Key"
],
"type": "object"
},
"AWS::Serverless::SimpleTable": {
"additionalProperties": false,
"properties": {
Expand Down
30 changes: 29 additions & 1 deletion schema/sam.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -85176,7 +85176,16 @@
"type": "array"
},
"ContentUri": {
"type": "string"
"anyOf": [
{
"type": [
"string"
]
},
{
"$ref": "#/definitions/AWS::Serverless::LayerVersion.S3Location"
}
]
},
"Description": {
"type": "string"
Expand Down Expand Up @@ -85213,6 +85222,25 @@
],
"type": "object"
},
"AWS::Serverless::LayerVersion.S3Location": {
"additionalProperties": false,
"properties": {
"Bucket": {
"type": "string"
},
"Key": {
"type": "string"
},
"Version": {
"type": "number"
}
},
"required": [
"Bucket",
"Key"
],
"type": "object"
},
"AWS::Serverless::SimpleTable": {
"additionalProperties": false,
"properties": {
Expand Down

0 comments on commit 6e39ebe

Please sign in to comment.