-
Notifications
You must be signed in to change notification settings - Fork 123
Support both mapped and typed input schemas in Fleet integration polies #1500
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
Draft
tobio
wants to merge
1
commit into
main
Choose a base branch
from
integration-policy-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ package integration_policy | |||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||
| "encoding/json" | ||||||||||||||||||||||||||
| "maps" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" | ||||||||||||||||||||||||||
| "github.com/elastic/terraform-provider-elasticstack/internal/utils" | ||||||||||||||||||||||||||
|
|
@@ -113,15 +114,46 @@ func HandleRespSecrets(ctx context.Context, resp *kbapi.PackagePolicy, private p | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| handleVars(utils.Deref(resp.Vars)) | ||||||||||||||||||||||||||
| for _, input := range resp.Inputs { | ||||||||||||||||||||||||||
| handleVars(utils.Deref(input.Vars)) | ||||||||||||||||||||||||||
| for _, stream := range utils.Deref(input.Streams) { | ||||||||||||||||||||||||||
| handleVars(utils.Deref(stream.Vars)) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Mapped inputs: extract, mutate, and write back | ||||||||||||||||||||||||||
| mappedInputs, _ := resp.Inputs.AsPackagePolicyMappedInputs() | ||||||||||||||||||||||||||
| typedInputs, _ := resp.Inputs.AsPackagePolicyTypedInputs() | ||||||||||||||||||||||||||
| if mappedInputs != nil { | ||||||||||||||||||||||||||
| for _, input := range mappedInputs { | ||||||||||||||||||||||||||
| if input.Vars != nil { | ||||||||||||||||||||||||||
| handleVars(*input.Vars) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if input.Streams != nil { | ||||||||||||||||||||||||||
| for _, stream := range *input.Streams { | ||||||||||||||||||||||||||
| if stream.Vars != nil { | ||||||||||||||||||||||||||
| handleVars(*stream.Vars) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| // Write back the mutated data | ||||||||||||||||||||||||||
| if err := resp.Inputs.FromPackagePolicyMappedInputs(mappedInputs); err != nil { | ||||||||||||||||||||||||||
| diags.AddError("could not write back mapped inputs", err.Error()) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } else if typedInputs != nil { | ||||||||||||||||||||||||||
| // Typed inputs: mutate in place through pointers | ||||||||||||||||||||||||||
| for i := range typedInputs { | ||||||||||||||||||||||||||
| if typedInputs[i].Vars != nil { | ||||||||||||||||||||||||||
| handleVars(*typedInputs[i].Vars) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| for j := range typedInputs[i].Streams { | ||||||||||||||||||||||||||
| if typedInputs[i].Streams[j].Vars != nil { | ||||||||||||||||||||||||||
| handleVars(*typedInputs[i].Streams[j].Vars) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if err := resp.Inputs.FromPackagePolicyTypedInputs(typedInputs); err != nil { | ||||||||||||||||||||||||||
| diags.AddError("could not write back typed inputs", err.Error()) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| nd = secrets.Save(ctx, private) | ||||||||||||||||||||||||||
| diags.Append(nd...) | ||||||||||||||||||||||||||
| diags.Append(secrets.Save(ctx, private)...) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
@@ -188,19 +220,46 @@ func HandleReqRespSecrets(ctx context.Context, req kbapi.PackagePolicyRequest, r | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| handleVars(utils.Deref(req.Vars), utils.Deref(resp.Vars)) | ||||||||||||||||||||||||||
| for inputID, inputReq := range utils.Deref(req.Inputs) { | ||||||||||||||||||||||||||
| inputResp := resp.Inputs[inputID] | ||||||||||||||||||||||||||
| handleVars(utils.Deref(inputReq.Vars), utils.Deref(inputResp.Vars)) | ||||||||||||||||||||||||||
| streamsResp := utils.Deref(inputResp.Streams) | ||||||||||||||||||||||||||
| for streamID, streamReq := range utils.Deref(inputReq.Streams) { | ||||||||||||||||||||||||||
| streamResp := streamsResp[streamID] | ||||||||||||||||||||||||||
| handleVars(utils.Deref(streamReq.Vars), utils.Deref(streamResp.Vars)) | ||||||||||||||||||||||||||
| mappedReq, _ := req.AsPackagePolicyRequestMappedInputs() | ||||||||||||||||||||||||||
| typedReq, _ := req.AsPackagePolicyRequestTypedInputs() | ||||||||||||||||||||||||||
|
Comment on lines
+223
to
+224
|
||||||||||||||||||||||||||
| mappedReq, _ := req.AsPackagePolicyRequestMappedInputs() | |
| typedReq, _ := req.AsPackagePolicyRequestTypedInputs() | |
| mappedReq, err := req.AsPackagePolicyRequestMappedInputs() | |
| if err != nil { | |
| diags.AddError("failed to convert request mapped inputs", err.Error()) | |
| return | |
| } | |
| typedReq, err := req.AsPackagePolicyRequestTypedInputs() | |
| if err != nil { | |
| diags.AddError("failed to convert request typed inputs", err.Error()) | |
| return | |
| } |
tobio marked this conversation as resolved.
Show resolved
Hide resolved
tobio marked this conversation as resolved.
Show resolved
Hide resolved
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error returns from
AsPackagePolicyMappedInputs()andAsPackagePolicyTypedInputs()are silently ignored. If these conversions fail, the function proceeds without proper error handling, potentially leading to unexpected behavior. Add error checking and return appropriate diagnostics if conversion fails.