From f61bbdffd6a232955d49b79456929d7259c34b30 Mon Sep 17 00:00:00 2001 From: Anderson Queiroz Date: Tue, 2 Apr 2024 14:05:34 +0200 Subject: [PATCH] adjust actions in protection package and diagnostics action --- internal/pkg/agent/protection/action.go | 2 +- internal/pkg/agent/protection/action_test.go | 4 +-- internal/pkg/fleetapi/action.go | 30 +++++++++++--------- internal/pkg/fleetapi/action_test.go | 6 ++-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/internal/pkg/agent/protection/action.go b/internal/pkg/agent/protection/action.go index 2548f90d4e9..aca222b10cb 100644 --- a/internal/pkg/agent/protection/action.go +++ b/internal/pkg/agent/protection/action.go @@ -21,7 +21,7 @@ var ( ) type fleetActionWithAgents struct { - ActionID string `json:"action_id"` // Note the action_id here, since the signed action uses action_id for id + ActionID string `json:"id"` ActionType string `json:"type,omitempty"` InputType string `json:"input_type,omitempty"` Timestamp string `json:"@timestamp"` diff --git a/internal/pkg/agent/protection/action_test.go b/internal/pkg/agent/protection/action_test.go index 48774585cb2..d14c16410dd 100644 --- a/internal/pkg/agent/protection/action_test.go +++ b/internal/pkg/agent/protection/action_test.go @@ -46,9 +46,7 @@ func signAction(action map[string]interface{}, emptyData bool, pk *ecdsa.Private "data": base64.StdEncoding.EncodeToString(payload), "signature": base64.StdEncoding.EncodeToString(sig), } - // Remap the action_id to id same way the fleet server does for checkins - action["id"] = action["action_id"] - delete(action, "action_id") + return action, nil } diff --git a/internal/pkg/fleetapi/action.go b/internal/pkg/fleetapi/action.go index d4d67662e1a..f002a810fcf 100644 --- a/internal/pkg/fleetapi/action.go +++ b/internal/pkg/fleetapi/action.go @@ -156,7 +156,7 @@ func (a *ActionUnknown) ID() string { func (a *ActionUnknown) String() string { var s strings.Builder - s.WriteString("action_id: ") + s.WriteString("id: ") s.WriteString(a.ActionID) s.WriteString(", type: ") s.WriteString(a.ActionType) @@ -189,7 +189,7 @@ type ActionPolicyReassignData struct { func (a *ActionPolicyReassign) String() string { var s strings.Builder - s.WriteString("action_id: ") + s.WriteString("id: ") s.WriteString(a.ActionID) s.WriteString(", type: ") s.WriteString(a.ActionType) @@ -223,7 +223,7 @@ type ActionPolicyChangeData struct { func (a *ActionPolicyChange) String() string { var s strings.Builder - s.WriteString("action_id: ") + s.WriteString("id: ") s.WriteString(a.ActionID) s.WriteString(", type: ") s.WriteString(a.ActionType) @@ -265,7 +265,7 @@ type ActionUpgradeData struct { func (a *ActionUpgrade) String() string { var s strings.Builder - s.WriteString("action_id: ") + s.WriteString("id: ") s.WriteString(a.ActionID) s.WriteString(", type: ") s.WriteString(a.ActionType) @@ -368,7 +368,7 @@ type ActionUnenroll struct { func (a *ActionUnenroll) String() string { var s strings.Builder - s.WriteString("action_id: ") + s.WriteString("id: ") s.WriteString(a.ActionID) s.WriteString(", type: ") s.WriteString(a.ActionType) @@ -421,7 +421,7 @@ func (a *ActionSettings) Type() string { func (a *ActionSettings) String() string { var s strings.Builder - s.WriteString("action_id: ") + s.WriteString("id: ") s.WriteString(a.ActionID) s.WriteString(", type: ") s.WriteString(a.ActionType) @@ -457,7 +457,7 @@ func (a *ActionCancel) Type() string { func (a *ActionCancel) String() string { var s strings.Builder - s.WriteString("action_id: ") + s.WriteString("id: ") s.WriteString(a.ActionID) s.WriteString(", type: ") s.WriteString(a.ActionType) @@ -472,11 +472,13 @@ func (a *ActionCancel) AckEvent() AckEvent { // ActionDiagnostics is a request to gather and upload a diagnostics bundle. type ActionDiagnostics struct { - ActionID string `json:"action_id"` - ActionType string `json:"type"` - AdditionalMetrics []string `json:"additional_metrics"` - UploadID string `json:"-"` - Err error `json:"-"` + ActionID string `json:"id"` + ActionType string `json:"type"` + Data struct { + AdditionalMetrics []string `json:"additional_metrics"` + } `json:"data"` + UploadID string `json:"-"` + Err error `json:"-"` } // ID returns the ID of the action. @@ -491,7 +493,7 @@ func (a *ActionDiagnostics) Type() string { func (a *ActionDiagnostics) String() string { var s strings.Builder - s.WriteString("action_id: ") + s.WriteString("id: ") s.WriteString(a.ActionID) s.WriteString(", type: ") s.WriteString(a.ActionType) @@ -531,7 +533,7 @@ type ActionApp struct { func (a *ActionApp) String() string { var s strings.Builder - s.WriteString("action_id: ") + s.WriteString("id: ") s.WriteString(a.ActionID) s.WriteString(", type: ") s.WriteString(a.ActionType) diff --git a/internal/pkg/fleetapi/action_test.go b/internal/pkg/fleetapi/action_test.go index 1e8ddd65737..4df6b75063c 100644 --- a/internal/pkg/fleetapi/action_test.go +++ b/internal/pkg/fleetapi/action_test.go @@ -161,7 +161,7 @@ func TestActionsUnmarshalJSON(t *testing.T) { require.True(t, ok, "unable to cast action to specific type") assert.Equal(t, "testid", action.ActionID) assert.Equal(t, ActionTypeDiagnostics, action.ActionType) - assert.Empty(t, action.AdditionalMetrics) + assert.Empty(t, action.Data.AdditionalMetrics) }) t.Run("ActionDiagnostics with additional CPU metrics", func(t *testing.T) { p := []byte(`[{"id":"testid","type":"REQUEST_DIAGNOSTICS","data":{"additional_metrics":["CPU"]}}]`) @@ -172,8 +172,8 @@ func TestActionsUnmarshalJSON(t *testing.T) { require.True(t, ok, "unable to cast action to specific type") assert.Equal(t, "testid", action.ActionID) assert.Equal(t, ActionTypeDiagnostics, action.ActionType) - require.Len(t, action.AdditionalMetrics, 1) - assert.Equal(t, "CPU", action.AdditionalMetrics[0]) + require.Len(t, action.Data.AdditionalMetrics, 1) + assert.Equal(t, "CPU", action.Data.AdditionalMetrics[0]) }) }