Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sam layerversion contenturi #339

Merged
merged 2 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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