This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(schema): S3Location or String support for AWS::Serverless::LayerV…
…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
1 parent
bdaec19
commit 6e39ebe
Showing
6 changed files
with
197 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
cloudformation/serverless/aws-serverless-layerversion_s3location.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters