Skip to content

Commit

Permalink
Refactor macOS version retrieval and update device struct to include …
Browse files Browse the repository at this point in the history
…Linux OS version
  • Loading branch information
dz0ny committed Dec 10, 2024
1 parent 4b436db commit 17659f3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 42 deletions.
15 changes: 0 additions & 15 deletions shared/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,3 @@ func SystemSerial() (string, error) {

return serialNumber, nil
}

func MacOSVersion() (string, error) {
cmd := exec.Command("sw_vers", "-productVersion")
output, err := cmd.Output()
if err != nil {
return "", err
}

version := strings.TrimSpace(string(output))
if version == "" {
return "", fmt.Errorf("unable to retrieve macOS version")
}

return version, nil
}
23 changes: 23 additions & 0 deletions shared/system_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package shared

import (
"fmt"

"os/exec"
"strings"
)

func OSVersion() (string, error) {
cmd := exec.Command("sw_vers", "-productVersion")
output, err := cmd.Output()
if err != nil {
return "", err
}

version := strings.TrimSpace(string(output))
if version == "" {
return "", fmt.Errorf("unable to retrieve macOS version")
}

return version, nil
}
24 changes: 12 additions & 12 deletions team/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
const enrollURL = "https://dash.paretosecurity.com/api/v1/team/enroll"

type NewDevice struct {
MachineName string `json:"machineName"`
ModelName string `json:"modelName"`
ModelSerial string `json:"modelSerial"`
MacOSVersion string `json:"macOSVersion"`
MachineUUID string `json:"machineUUID"`
Auth string `json:"auth"`
MachineName string `json:"machineName"`
ModelName string `json:"modelName"`
ModelSerial string `json:"modelSerial"`
LinuxOSVersion string `json:"LinuxOSVersion"`
MachineUUID string `json:"machineUUID"`
Auth string `json:"auth"`
}

type LinkingResponse struct {
Expand Down Expand Up @@ -132,12 +132,12 @@ func AddDevice() error {

res := ""
newDevice := NewDevice{
MachineName: device.MachineName,
ModelName: device.ModelName,
ModelSerial: device.ModelSerial,
MacOSVersion: device.MacOSVersion,
MachineUUID: device.MachineUUID,
Auth: device.Auth,
MachineName: device.MachineName,
ModelName: device.ModelName,
ModelSerial: device.ModelSerial,
LinuxOSVersion: device.LinuxOSVersion,
MachineUUID: device.MachineUUID,
Auth: device.Auth,
}
log.Debug(spew.Sdump(newDevice))
err := requests.URL(reportURL).
Expand Down
23 changes: 8 additions & 15 deletions team/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/hex"
"fmt"
"net/http"
"runtime"
"time"

"github.com/caarlos0/log"
Expand All @@ -19,12 +18,12 @@ import (
const reportURL = "https://dash.paretosecurity.com"

type ReportingDevice struct {
MachineUUID string `json:"machineUUID"`
MachineName string `json:"machineName"`
Auth string `json:"auth"`
MacOSVersion string `json:"macOSVersion"`
ModelName string `json:"modelName"`
ModelSerial string `json:"modelSerial"`
MachineUUID string `json:"machineUUID"`
MachineName string `json:"machineName"`
Auth string `json:"auth"`
LinuxOSVersion string `json:"LinuxOSVersion"`
ModelName string `json:"modelName"`
ModelSerial string `json:"modelSerial"`
}

func CurrentReportingDevice() ReportingDevice {
Expand All @@ -37,14 +36,8 @@ func CurrentReportingDevice() ReportingDevice {
MachineUUID: device.UUID,
MachineName: device.Hostname,
Auth: DeviceAuth(),
MacOSVersion: func() string {
if runtime.GOOS == "darwin" {
version, err := shared.MacOSVersion()
if err == nil {
return version
}
}
return fmt.Sprintf("%s %s", device.OS, device.OSVersion)
LinuxOSVersion: func() string {
return fmt.Sprintf("%s-%s", device.OS, device.Kernel)
}(),
ModelName: func() string {
modelName, err := shared.SystemDevice()
Expand Down

0 comments on commit 17659f3

Please sign in to comment.