Skip to content

Commit

Permalink
Merge pull request #56 from mbaijal/hooks-rebased-2
Browse files Browse the repository at this point in the history
Add hooks after input request creation, but before request is submitted.
  • Loading branch information
jaypipes authored May 7, 2021
2 parents aa5dbbb + ddbca01 commit 71f5331
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions pkg/generate/ack/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ code paths:
* sdk_create_pre_build_request
* sdk_update_pre_build_request
* sdk_delete_pre_build_request
* sdk_read_one_post_build_request
* sdk_read_many_post_build_request
* sdk_get_attributes_post_build_request
* sdk_create_post_build_request
* sdk_update_post_build_request
* sdk_delete_post_build_request
* sdk_read_one_post_request
* sdk_read_many_post_request
* sdk_get_attributes_post_request
Expand All @@ -55,6 +61,9 @@ The "pre_build_request" hooks are called BEFORE the call to construct
the Input shape that is used in the API operation and therefore BEFORE
any call to validate that Input shape.
The "post_build_request" hooks are called AFTER the call to construct
the Input shape but BEFORE the API operation.
The "post_request" hooks are called IMMEDIATELY AFTER the API operation
aws-sdk-go client call. These hooks will have access to a Go variable
named `resp` that refers to the aws-sdk-go client response and a Go
Expand Down
3 changes: 3 additions & 0 deletions templates/pkg/resource/sdk.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func (rm *resourceManager) sdkCreate(
if err != nil {
return nil, err
}
{{- if $hookCode := Hook .CRD "sdk_create_post_build_request" }}
{{ $hookCode }}
{{- end }}
{{ $createCode := GoCodeSetCreateOutput .CRD "resp" "ko" 1 false }}
{{ if not ( Empty $createCode ) }}resp{{ else }}_{{ end }}, respErr := rm.sdkapi.{{ .CRD.Ops.Create.Name }}WithContext(ctx, input)
{{- if $hookCode := Hook .CRD "sdk_create_post_request" }}
Expand Down
3 changes: 3 additions & 0 deletions templates/pkg/resource/sdk_find_get_attributes.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func (rm *resourceManager) sdkFind(
if err != nil {
return nil, err
}
{{- if $hookCode := Hook .CRD "sdk_get_attributes_post_build_request" }}
{{ $hookCode }}
{{- end }}
{{ $setCode := GoCodeGetAttributesSetOutput .CRD "resp" "ko" 1 }}
{{ if not ( Empty $setCode ) }}resp{{ else }}_{{ end }}, respErr := rm.sdkapi.{{ .CRD.Ops.GetAttributes.Name }}WithContext(ctx, input)
{{- if $hookCode := Hook .CRD "sdk_get_attributes_post_request" }}
Expand Down
3 changes: 3 additions & 0 deletions templates/pkg/resource/sdk_find_read_many.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ func (rm *resourceManager) sdkFind(
if err != nil {
return nil, err
}
{{- if $hookCode := Hook .CRD "sdk_read_many_post_build_request" }}
{{ $hookCode }}
{{- end }}
{{ $setCode := GoCodeSetReadManyOutput .CRD "resp" "ko" 1 true }}
{{ if not ( Empty $setCode ) }}resp{{ else }}_{{ end }}, respErr := rm.sdkapi.{{ .CRD.Ops.ReadMany.Name }}WithContext(ctx, input)
{{- if $hookCode := Hook .CRD "sdk_read_many_post_request" }}
Expand Down
5 changes: 4 additions & 1 deletion templates/pkg/resource/sdk_find_read_one.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func (rm *resourceManager) sdkFind(
if err != nil {
return nil, err
}
{{- if $hookCode := Hook .CRD "sdk_read_one_post_build_request" }}
{{ $hookCode }}
{{- end }}
{{ $setCode := GoCodeSetReadOneOutput .CRD "resp" "ko" 1 true }}
{{ if not ( Empty $setCode ) }}resp{{ else }}_{{ end }}, respErr := rm.sdkapi.{{ .CRD.Ops.ReadOne.Name }}WithContext(ctx, input)
{{- if $hookCode := Hook .CRD "sdk_read_one_post_request" }}
Expand Down Expand Up @@ -52,7 +55,7 @@ func (rm *resourceManager) sdkFind(
}

// requiredFieldsMissingFromReadOneInput returns true if there are any fields
// for the ReadOne Input shape that are required by not present in the
// for the ReadOne Input shape that are required but not present in the
// resource's Spec or Status
func (rm *resourceManager) requiredFieldsMissingFromReadOneInput(
r *resource,
Expand Down
4 changes: 3 additions & 1 deletion templates/pkg/resource/sdk_update.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func (rm *resourceManager) sdkUpdate(
if err != nil {
return nil, err
}

{{- if $hookCode := Hook .CRD "sdk_update_pre_build_request" }}
{{ $hookCode }}
{{- end }}
{{ $setCode := GoCodeSetUpdateOutput .CRD "resp" "ko" 1 false }}
{{ if not ( Empty $setCode ) }}resp{{ else }}_{{ end }}, respErr := rm.sdkapi.{{ .CRD.Ops.Update.Name }}WithContext(ctx, input)
{{- if $hookCode := Hook .CRD "sdk_update_post_request" }}
Expand Down

0 comments on commit 71f5331

Please sign in to comment.