diff --git a/management/server/http/api/openapi.yml b/management/server/http/api/openapi.yml index c1719a822..69e723de1 100644 --- a/management/server/http/api/openapi.yml +++ b/management/server/http/api/openapi.yml @@ -976,9 +976,6 @@ components: description: Path to the process executable file in a Windows operating system type: string example: "C:\ProgramData\NetBird\netbird.exe" - required: - - path - - windows_path Location: description: Describe geographical location information type: object diff --git a/management/server/http/api/types.gen.go b/management/server/http/api/types.gen.go index 2d324102e..f2a374fc7 100644 --- a/management/server/http/api/types.gen.go +++ b/management/server/http/api/types.gen.go @@ -916,10 +916,10 @@ type PostureCheckUpdate struct { // Process Describe the operational activity within peer's system. type Process struct { // Path Path to the process executable file in a Unix-like operating system - Path string `json:"path"` + Path *string `json:"path,omitempty"` // WindowsPath Path to the process executable file in a Windows operating system - WindowsPath string `json:"windows_path"` + WindowsPath *string `json:"windows_path,omitempty"` } // ProcessCheck Posture Check for binaries exist and are running in the peer’s system diff --git a/management/server/http/posture_checks_handler.go b/management/server/http/posture_checks_handler.go index 48b256043..6ea84ea26 100644 --- a/management/server/http/posture_checks_handler.go +++ b/management/server/http/posture_checks_handler.go @@ -302,10 +302,7 @@ func validatePostureChecksUpdate(req api.PostureCheckUpdate) error { } for _, process := range processCheck.Processes { - if process.WindowsPath == "" { - return status.Errorf(status.InvalidArgument, "windows path for process check shouldn't be empty") - } - if process.Path == "" { + if process.Path == nil && process.WindowsPath == nil { return status.Errorf(status.InvalidArgument, "path for process check shouldn't be empty") } } @@ -423,7 +420,10 @@ func toPeerNetworkRangeCheck(check *api.PeerNetworkRangeCheck) (*posture.PeerNet func toProcessCheckResponse(check *posture.ProcessCheck) *api.ProcessCheck { processes := make([]api.Process, 0, len(check.Processes)) for _, process := range check.Processes { - processes = append(processes, (api.Process)(process)) + processes = append(processes, api.Process{ + Path: &process.Path, + WindowsPath: &process.WindowsPath, + }) } return &api.ProcessCheck{ @@ -434,10 +434,15 @@ func toProcessCheckResponse(check *posture.ProcessCheck) *api.ProcessCheck { func toProcessCheck(check *api.ProcessCheck) *posture.ProcessCheck { processes := make([]posture.Process, 0, len(check.Processes)) for _, process := range check.Processes { - processes = append(processes, posture.Process{ - Path: process.Path, - WindowsPath: process.WindowsPath, - }) + var p posture.Process + if process.Path != nil { + p.Path = *process.Path + } + if process.WindowsPath != nil { + p.WindowsPath = *process.WindowsPath + } + + processes = append(processes, p) } return &posture.ProcessCheck{ diff --git a/management/server/http/posture_checks_handler_test.go b/management/server/http/posture_checks_handler_test.go index 18194e128..f312ba961 100644 --- a/management/server/http/posture_checks_handler_test.go +++ b/management/server/http/posture_checks_handler_test.go @@ -462,8 +462,8 @@ func TestPostureCheckUpdate(t *testing.T) { ProcessCheck: &api.ProcessCheck{ Processes: []api.Process{ { - Path: "/usr/local/bin/netbird", - WindowsPath: "C:\\ProgramData\\NetBird\\netbird.exe", + Path: str("/usr/local/bin/netbird"), + WindowsPath: str("C:\\ProgramData\\NetBird\\netbird.exe"), }, }, }, @@ -880,6 +880,8 @@ func TestPostureCheckUpdate(t *testing.T) { } func TestPostureCheck_validatePostureChecksUpdate(t *testing.T) { + str := func(s string) *string { return &s } + // empty name err := validatePostureChecksUpdate(api.PostureCheckUpdate{}) assert.Error(t, err) @@ -979,8 +981,8 @@ func TestPostureCheck_validatePostureChecksUpdate(t *testing.T) { processCheck := api.ProcessCheck{ Processes: []api.Process{ { - Path: "/usr/local/bin/netbird", - WindowsPath: "C:\\ProgramData\\NetBird\\netbird.exe", + Path: str("/usr/local/bin/netbird"), + WindowsPath: str("C:\\ProgramData\\NetBird\\netbird.exe"), }, }, } @@ -998,7 +1000,7 @@ func TestPostureCheck_validatePostureChecksUpdate(t *testing.T) { processCheck = api.ProcessCheck{ Processes: []api.Process{ { - Path: "/usr/local/bin/netbird", + Path: str("/usr/local/bin/netbird"), }, }, } @@ -1009,7 +1011,7 @@ func TestPostureCheck_validatePostureChecksUpdate(t *testing.T) { processCheck = api.ProcessCheck{ Processes: []api.Process{ { - WindowsPath: "C:\\ProgramData\\NetBird\\netbird.exe", + WindowsPath: str("C:\\ProgramData\\NetBird\\netbird.exe"), }, }, }