mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-09 15:25:20 +02:00
Allow set of single unix or windows path check
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
@ -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{
|
||||
|
@ -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"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user