Add random plant id during configure (#4697)

This commit is contained in:
andig 2022-10-02 19:09:42 +02:00 • committed by GitHub
parent 880557594f
commit 8a655efce8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View file

@ -30,16 +30,20 @@ func CustomID(cid string) error {
return nil
}
// RandomID creates a random id
func RandomID() string {
rnd := util.RandomString(512)
mac := hmac.New(sha256.New, []byte(rnd))
return hex.EncodeToString(mac.Sum(nil))
}
// ID returns the platform specific machine id of the current host OS.
// If ID cannot be generated, a random value is suggested.
func ID() (string, error) {
if id == "" {
var err error
if id, err = machineid.ID(); err != nil {
rnd := util.RandomString(512)
mac := hmac.New(sha256.New, []byte(rnd))
rid := hex.EncodeToString(mac.Sum(nil))
rid := RandomID()
return "", fmt.Errorf("could not get %w; for manual configuration use plant: %s", err, rid)
}
}