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

Add hooks after input request creation, but before request is submitted. #56

Merged
merged 1 commit into from
May 7, 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
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