Skip to content

Commit

Permalink
use condition build for os vendor syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunKoyalwar committed Apr 1, 2024
1 parent 4d5a859 commit d5cc32b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 27 deletions.
28 changes: 1 addition & 27 deletions update/types.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package updateutils

import (
"encoding/base64"
"fmt"
"os"
"runtime"
"strings"

"github.com/Masterminds/semver/v3"
"github.com/logrusorgru/aurora"
osutils "github.com/projectdiscovery/utils/os"

"github.com/projectdiscovery/utils/process"
"github.com/zcalusic/sysinfo"
)

type AssetFormat uint
Expand Down Expand Up @@ -158,26 +155,3 @@ func getUtmSource() string {
}
return value
}

// Get OS Vendor returns the linux distribution vendor
// if not linux then returns runtime.GOOS
func GetOSVendor() string {
if !osutils.IsLinux() {
return runtime.GOOS
}
var si sysinfo.SysInfo
si.GetSysInfo()
return si.OS.Vendor
}

// returns platform metadata
func getPlatformMetadata() string {
var si sysinfo.SysInfo
si.GetSysInfo()
tmp := strings.ReplaceAll(si.Board.Vendor, " ", "_") + "|" + strings.ReplaceAll(si.Board.Name, " ", "_")
if tmp == "|" {
// instead of just empty string return os for more context
tmp = runtime.GOOS + "|" + runtime.GOARCH
}
return strings.TrimSuffix(base64.StdEncoding.EncodeToString([]byte(tmp)), "==")
}
22 changes: 22 additions & 0 deletions update/utils_all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build !linux
// +build !linux

package updateutils

import (
"encoding/base64"
"runtime"
"strings"
)

// Get OS Vendor returns the linux distribution vendor
// if not linux then returns runtime.GOOS
func GetOSVendor() string {
return runtime.GOOS
}

// returns platform metadata
func getPlatformMetadata() string {
tmp := runtime.GOOS + "|" + runtime.GOARCH
return strings.TrimSuffix(base64.StdEncoding.EncodeToString([]byte(tmp)), "==")
}
32 changes: 32 additions & 0 deletions update/utils_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build linux
// +build linux

package updateutils

import (
"encoding/base64"
"runtime"
"strings"

"github.com/zcalusic/sysinfo"
)

// Get OS Vendor returns the linux distribution vendor
// if not linux then returns runtime.GOOS
func GetOSVendor() string {
var si sysinfo.SysInfo
si.GetSysInfo()
return si.OS.Vendor
}

// returns platform metadata
func getPlatformMetadata() string {
var si sysinfo.SysInfo
si.GetSysInfo()
tmp := strings.ReplaceAll(si.Board.Vendor, " ", "_") + "|" + strings.ReplaceAll(si.Board.Name, " ", "_")
if tmp == "|" {
// instead of just empty string return os for more context
tmp = runtime.GOOS + "|" + runtime.GOARCH
}
return strings.TrimSuffix(base64.StdEncoding.EncodeToString([]byte(tmp)), "==")
}

0 comments on commit d5cc32b

Please sign in to comment.