forked from awslabs/goformation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(schema): Add cdkmetada resource (awslabs#418)
* testing * adding cdkmetada as resource * cleaning * cleaning unnecessary prints
- Loading branch information
Showing
9 changed files
with
128 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
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,59 @@ | ||
package cdkmetadata | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
// CDKMetadata AWS CloudFormation Resource (AWS::CDK::Metadata) | ||
type CDKMetadata struct { | ||
Analytics string `json:"Analytics,omitempty"` | ||
|
||
Metadata map[string]interface{} `json:"-"` | ||
} | ||
|
||
// AWSCloudFormationType returns the AWS CloudFormation resource type | ||
func (r *CDKMetadata) AWSCloudFormationType() string { | ||
return "AWS::CDK::Metadata" | ||
} | ||
|
||
// MarshalJSON is a custom JSON marshalling hook that embeds this object into | ||
// an AWS CloudFormation JSON resource's 'Properties' field and adds a 'Type'. | ||
func (r CDKMetadata) MarshalJSON() ([]byte, error) { | ||
type Properties CDKMetadata | ||
return json.Marshal(&struct { | ||
Type string | ||
Properties Properties | ||
Metadata map[string]interface{} `json:"Metadata,omitempty"` | ||
}{ | ||
Type: r.AWSCloudFormationType(), | ||
Properties: (Properties)(r), | ||
Metadata: r.Metadata, | ||
}) | ||
} | ||
|
||
// UnmarshalJSON is a custom JSON unmarshalling hook that strips the outer | ||
// AWS CloudFormation resource object, and just keeps the 'Properties' field. | ||
func (r *CDKMetadata) UnmarshalJSON(b []byte) error { | ||
type Properties CDKMetadata | ||
res := &struct { | ||
Type string | ||
Properties *Properties | ||
Metadata map[string]interface{} | ||
}{} | ||
|
||
dec := json.NewDecoder(bytes.NewReader(b)) | ||
dec.DisallowUnknownFields() // Force error if unknown field is found | ||
|
||
if err := dec.Decode(&res); err != nil { | ||
fmt.Printf("ERROR: %s\n", err) | ||
return err | ||
} | ||
|
||
// If the resource has no Properties set, it could be nil | ||
if res.Properties != nil { | ||
*r = CDKMetadata(*res.Properties) | ||
} | ||
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
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
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,9 @@ | ||
|
||
AWSTemplateFormatVersion: 2010-09-09 | ||
Resources: | ||
CDKMetadata: | ||
Type: AWS::CDK::Metadata | ||
Properties: | ||
Analytics: v2:deflate64:foobar | ||
Metadata: | ||
aws:cdk:path: foobar/CDKMetadata/Default |