Skip to content

Commit d3d8b2b

Browse files
authored
Type configuation (#208)
* add type config template
1 parent d23e052 commit d3d8b2b

File tree

19 files changed

+106
-64
lines changed

19 files changed

+106
-64
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
rev: stable
2525
hooks:
2626
- id: black
27-
- repo: git://github.com/dnephin/pre-commit-golang
27+
- repo: https://github.com/dnephin/pre-commit-golang
2828
rev: master
2929
hooks:
3030
- id: go-fmt

cfn/callback/callback.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build callback
12
// +build callback
23

34
/*
@@ -59,7 +60,7 @@ func (c *CloudFormationCallbackAdapter) ReportInitialStatus() error {
5960
return nil
6061
}
6162

62-
//ReportFailureStatus reports the failure status back to the Cloudformation service.
63+
// ReportFailureStatus reports the failure status back to the Cloudformation service.
6364
func (c *CloudFormationCallbackAdapter) ReportFailureStatus(model []byte, errCode string, handlerError error) error {
6465
if err := c.reportProgress(errCode, Failed, InProgress, model, handlerError.Error()); err != nil {
6566
return err

cfn/callback/callback_notag.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !callback
12
// +build !callback
23

34
package callback

cfn/callback/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package callback
22

3-
//Status represents the status of the handler during invocation.
3+
// Status represents the status of the handler during invocation.
44
type Status string
55

66
const (

cfn/cfn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func makeEventFunc(h Handler) eventFunc {
130130
credentials.SessionFromCredentialsProvider(&event.RequestData.CallerCredentials),
131131
event.RequestData.PreviousResourceProperties,
132132
event.RequestData.ResourceProperties,
133+
event.RequestData.TypeConfiguration,
133134
)
134135
p := invoke(handlerFn, request, m, event.Action)
135136
r, err := newResponse(&p, event.BearerToken)

cfn/cfn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func TestMakeEventFunc(t *testing.T) {
129129
}
130130
}
131131

132-
//loadEvent is a helper function that unmarshal the event from a file.
132+
// loadEvent is a helper function that unmarshal the event from a file.
133133
func loadEvent(path string, evt *event) *event {
134134
validevent, err := openFixture(path)
135135
if err != nil {

cfn/event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type requestData struct {
3636
ProviderLogGroupName string `json:"providerLogGroupName"`
3737
StackTags tags `json:"stackTags"`
3838
SystemTags tags `json:"systemTags"`
39+
TypeConfiguration json.RawMessage `json:"typeConfiguration"`
3940
}
4041

4142
// validateEvent ensures the event struct generated from the Lambda SDK is correct

cfn/handler/handler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestNewRequest(t *testing.T) {
1717
prev := Props{}
1818
curr := Props{}
1919

20-
req := NewRequest("foo", nil, rctx, nil, []byte(`{"color": "red"}`), []byte(`{"color": "green"}`))
20+
req := NewRequest("foo", nil, rctx, nil, []byte(`{"color": "red"}`), []byte(`{"color": "green"}`), nil)
2121

2222
if err := req.UnmarshalPrevious(&prev); err != nil {
2323
t.Fatalf("Unable to unmarshal props: %v", err)
@@ -43,7 +43,7 @@ func TestNewRequest(t *testing.T) {
4343

4444
t.Run("ResourceProps", func(t *testing.T) {
4545
t.Run("Invalid Body", func(t *testing.T) {
46-
req := NewRequest("foo", nil, rctx, nil, []byte(``), []byte(``))
46+
req := NewRequest("foo", nil, rctx, nil, []byte(``), []byte(``), nil)
4747

4848
invalid := struct {
4949
Color *int `json:"color"`
@@ -61,7 +61,7 @@ func TestNewRequest(t *testing.T) {
6161
})
6262

6363
t.Run("Invalid Marshal", func(t *testing.T) {
64-
req := NewRequest("foo", nil, rctx, nil, []byte(`{"color": "ref"}`), []byte(`---BAD JSON---`))
64+
req := NewRequest("foo", nil, rctx, nil, []byte(`{"color": "ref"}`), []byte(`---BAD JSON---`), nil)
6565

6666
var invalid Props
6767

@@ -79,7 +79,7 @@ func TestNewRequest(t *testing.T) {
7979

8080
t.Run("PreviousResourceProps", func(t *testing.T) {
8181
t.Run("Invalid Marshal", func(t *testing.T) {
82-
req := NewRequest("foo", nil, rctx, nil, []byte(`---BAD JSON---`), []byte(`{"color": "green"}`))
82+
req := NewRequest("foo", nil, rctx, nil, []byte(`---BAD JSON---`), []byte(`{"color": "green"}`), nil)
8383

8484
var invalid Props
8585

cfn/handler/request.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Request struct {
3636

3737
previousResourcePropertiesBody []byte
3838
resourcePropertiesBody []byte
39+
typeConfigurationBody []byte
3940
}
4041

4142
// RequestContext represents information about the current
@@ -61,14 +62,15 @@ type RequestContext struct {
6162
}
6263

6364
// NewRequest returns a new Request based on the provided parameters
64-
func NewRequest(id string, ctx map[string]interface{}, requestCTX RequestContext, sess *session.Session, previousBody, body []byte) Request {
65+
func NewRequest(id string, ctx map[string]interface{}, requestCTX RequestContext, sess *session.Session, previousBody, body, typeConfig []byte) Request {
6566
return Request{
6667
LogicalResourceID: id,
6768
CallbackContext: ctx,
6869
Session: sess,
6970
previousResourcePropertiesBody: previousBody,
7071
resourcePropertiesBody: body,
7172
RequestContext: requestCTX,
73+
typeConfigurationBody: typeConfig,
7274
}
7375
}
7476

@@ -99,3 +101,17 @@ func (r *Request) Unmarshal(v interface{}) error {
99101

100102
return nil
101103
}
104+
105+
// UnmarshalTypeConfig populates the provided interface
106+
// with the current properties of the model
107+
func (r *Request) UnmarshalTypeConfig(v interface{}) error {
108+
if len(r.typeConfigurationBody) == 0 {
109+
return cfnerr.New(bodyEmptyError, "Type Config is empty", nil)
110+
}
111+
112+
if err := encoding.Unmarshal(r.typeConfigurationBody, v); err != nil {
113+
return cfnerr.New(marshalingError, "Unable to convert type", err)
114+
}
115+
116+
return nil
117+
}

cfn/handler/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package handler
22

3-
//Status represents the status of the handler.
3+
// Status represents the status of the handler.
44
type Status string
55

66
const (

0 commit comments

Comments
 (0)