Skip to content

Commit

Permalink
adjust actions in protection package and diagnostics action
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersonQ committed Apr 2, 2024
1 parent 1c3dfe0 commit f61bbdf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/agent/protection/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 1 addition & 3 deletions internal/pkg/agent/protection/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
30 changes: 16 additions & 14 deletions internal/pkg/fleetapi/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/fleetapi/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}}]`)
Expand All @@ -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])
})
}

Expand Down

0 comments on commit f61bbdf

Please sign in to comment.