Skip to content

Commit

Permalink
fix(linux): 🔒 as per recommendations, don't use the actual device id,…
Browse files Browse the repository at this point in the history
… generate a random one
  • Loading branch information
joshuar committed May 9, 2024
1 parent a8d76c6 commit 5d69005
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ require (
github.com/go-resty/resty/v2 v2.12.0
github.com/go-text/render v0.1.0 // indirect
github.com/go-text/typesetting v0.1.0 // indirect
github.com/gofrs/uuid/v5 v5.1.0
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jaypipes/ghw v0.12.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ github.com/go-text/typesetting-utils v0.0.0-20240329101916-eee87fb235a3/go.mod h
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/uuid/v5 v5.1.0 h1:S5rqVKIigghZTCBKPCw0Y+bXkn26K3TB5mvQq2Ix8dk=
github.com/gofrs/uuid/v5 v5.1.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down
9 changes: 4 additions & 5 deletions internal/linux/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"os/user"
"strings"

"github.com/gofrs/uuid/v5"
"github.com/jaypipes/ghw"
mqtthass "github.com/joshuar/go-hass-anything/v9/pkg/hass"
"github.com/rs/zerolog/log"
"github.com/shirou/gopsutil/v3/host"

"github.com/joshuar/go-hass-agent/internal/preferences"
"github.com/joshuar/go-hass-agent/pkg/linux/whichdistro"
Expand Down Expand Up @@ -121,16 +121,15 @@ func MQTTDevice() *mqtthass.Device {
}
}

// getDeviceID retrieves the unique host ID of the device running the agent, or
// unknown if that doesn't work.
// getDeviceID create a new device ID. It will be a randomly generated UUIDv4.
func getDeviceID() string {
deviceID, err := host.HostID()
deviceID, err := uuid.NewV4()
if err != nil {
log.Warn().Err(err).
Msg("Could not retrieve a machine ID")
return "unknown"
}
return deviceID
return deviceID.String()
}

// getHostname retrieves the hostname of the device running the agent, or
Expand Down

0 comments on commit 5d69005

Please sign in to comment.