fix: handle boolean strings from Splunk Cloud API for HEC useACK field#232
Open
pgiraultmatz wants to merge 1 commit into
Open
Conversation
Splunk Cloud returns "true"/"false" strings for the useACK field in HEC
token responses, while Splunk Enterprise returns "0"/"1". The existing
json:",string" struct tag only handles integer strings, causing an unmarshal
error on Splunk Cloud deployments.
Introduce SplunkBoolInt, a custom int type with a JSON unmarshaler that
accepts both boolean strings ("true"/"false") and integer strings ("0"/"1"),
fixing the panic:
json: invalid use of ,string struct tag, trying to unmarshal "false" into int
Author
|
cc @rrossetti-splunk @micahkemp-splunk — would appreciate a review when you get a chance. This fixes a crash on Splunk Cloud deployments where the API returns boolean strings for |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
On Splunk Cloud deployments,
terraform applyfails with:This happens because Splunk Cloud returns
"useACK": "false"in HEC token API responses, while theHttpEventCollectorObjectstruct declaresUseACKasintwith ajson:",string"tag — which only handles integer strings like"0"or"1".Splunk Enterprise returns
"0"/"1", Splunk Cloud returns"false"/"true". The existing struct tag cannot handle both.Fix
Introduce
SplunkBoolInt, a custominttype with aUnmarshalJSONthat accepts:"true"→ 1,"false"→ 0 (Splunk Cloud)"1"→ 1,"0"→ 0 (Splunk Enterprise)1→ 1,0→ 0MarshalJSONserializes back as an integer string ("0"/"1") to preserve compatibility with the Splunk API write path.Files changed
client/models/splunk_bool_int.go— newSplunkBoolInttypeclient/models/splunk_bool_int_test.go— unit tests covering all cases including the Splunk Cloud regressionclient/models/http_event_collector.go—UseACKfield changed frominttoSplunkBoolIntsplunk/resource_splunk_inputs_http_event_collector.go— cast updated accordinglyTesting
All tests pass. The
TestHttpEventCollectorObject_UnmarshalUseACKtest directly reproduces the Splunk Cloud API response that triggered the bug.Notes
The same
int json:",string"pattern exists inglobal_http_event_collector.goandsaved_searches.go. Those fields may be affected by the same issue on Splunk Cloud —SplunkBoolIntcan be reused to fix them incrementally.