Skip to content

Conversation

@tobio
Copy link
Member

@tobio tobio commented Dec 2, 2025

Related to #601

Integration policies support two body formats, a map ({"input-id": {...}}) and a list ([{"type":"endpoint"...}]). Only the latter form supports the config field 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.

@tobio tobio requested review from dimuon and nick-benoit December 2, 2025 01:19
@tobio tobio self-assigned this Dec 2, 2025
Copilot AI review requested due to automatic review settings December 2, 2025 01:19
Copy link
Contributor

Copilot AI left a 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

Comment on lines +119 to +120
mappedInputs, _ := resp.Inputs.AsPackagePolicyMappedInputs()
typedInputs, _ := resp.Inputs.AsPackagePolicyTypedInputs()
Copy link

Copilot AI Dec 2, 2025

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.

Suggested change
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
}

Copilot uses AI. Check for mistakes.
Comment on lines +223 to +224
mappedReq, _ := req.AsPackagePolicyRequestMappedInputs()
typedReq, _ := req.AsPackagePolicyRequestTypedInputs()
Copy link

Copilot AI Dec 2, 2025

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.

Suggested change
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
}

Copilot uses AI. Check for mistakes.
@tobio tobio force-pushed the integration-policy-config branch from d893f41 to 5ed4523 Compare December 2, 2025 01:20
@tobio tobio marked this pull request as draft December 3, 2025 10:48
@tobio
Copy link
Member Author

tobio commented Dec 3, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants