-
Notifications
You must be signed in to change notification settings - Fork 122
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR adds support for both mapped and typed input schema formats in Fleet integration policies. The Kibana API accepts two input formats: a map structure ({"input-id": {...}}) and a list structure ([{"type":"endpoint"...}]), with only the latter supporting the config field needed by Endpoint and APM integrations.
Key Changes:
- Updated API client to handle union types for both input formats
- Modified secret handling functions to process both mapped and typed inputs
- Enhanced test coverage to validate both input schema formats
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
internal/fleet/integration_policy/secrets_test.go |
Added comprehensive test cases for both mapped and typed input formats in secret handling scenarios |
internal/fleet/integration_policy/secrets.go |
Updated HandleRespSecrets and HandleReqRespSecrets to process both input schema types with proper extraction and mutation |
internal/fleet/integration_policy/models_test.go |
Added initialization of inputs union in output ID test to prevent JSON parse errors |
internal/fleet/integration_policy/models.go |
Modified model conversion to use mapped inputs and handle union type conversions |
go.mod |
Moved google/go-cmp and gopkg.in/yaml.v3 from indirect to direct dependencies |
| mappedInputs, _ := resp.Inputs.AsPackagePolicyMappedInputs() | ||
| typedInputs, _ := resp.Inputs.AsPackagePolicyTypedInputs() |
Copilot
AI
Dec 2, 2025
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() and AsPackagePolicyTypedInputs() 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.
| mappedInputs, _ := resp.Inputs.AsPackagePolicyMappedInputs() | |
| typedInputs, _ := resp.Inputs.AsPackagePolicyTypedInputs() | |
| mappedInputs, mappedErr := resp.Inputs.AsPackagePolicyMappedInputs() | |
| typedInputs, typedErr := resp.Inputs.AsPackagePolicyTypedInputs() | |
| if mappedErr != nil { | |
| diags.AddError("could not convert inputs to mapped inputs", mappedErr.Error()) | |
| return diags | |
| } | |
| if typedErr != nil { | |
| diags.AddError("could not convert inputs to typed inputs", typedErr.Error()) | |
| return diags | |
| } |
| mappedReq, _ := req.AsPackagePolicyRequestMappedInputs() | ||
| typedReq, _ := req.AsPackagePolicyRequestTypedInputs() |
Copilot
AI
Dec 2, 2025
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.
Similar to HandleRespSecrets, the error returns are ignored here. Add error handling to ensure conversion failures are properly reported through diagnostics.
| 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 | |
| } |
d893f41 to
5ed4523
Compare
|
There's some serious issues adding support for the endpoint integration using this resource. There's still a good chance we'll want to add this support in the API but ignore this PR for now. |
Related to #601
Integration policies support two body formats, a map (
{"input-id": {...}}) and a list ([{"type":"endpoint"...}]). Only the latter form supports theconfigfield used by both Endpoint and APM integrations (even though that form is apparently deprecated 🤷).Functionally, this PR should be a no-op. It adds support for the latter input form in the API client, and updates the integration policy resource to match the new generated API client. It doesn't make any resource schema changes, and the behaviour should be identical.