瀏覽代碼

do not rely on /proc/sys/kernel/random/uuid as fallback as it does not exists everywhere (#1575)

blotus 3 年之前
父節點
當前提交
b7f1c5455f
共有 1 個文件被更改,包括 3 次插入6 次删除
  1. 3 6
      cmd/crowdsec-cli/machines.go

+ 3 - 6
cmd/crowdsec-cli/machines.go

@@ -17,6 +17,7 @@ import (
 	"github.com/crowdsecurity/machineid"
 	"github.com/crowdsecurity/machineid"
 	"github.com/enescakir/emoji"
 	"github.com/enescakir/emoji"
 	"github.com/go-openapi/strfmt"
 	"github.com/go-openapi/strfmt"
+	"github.com/google/uuid"
 	"github.com/olekukonko/tablewriter"
 	"github.com/olekukonko/tablewriter"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 	log "github.com/sirupsen/logrus"
 	log "github.com/sirupsen/logrus"
@@ -39,10 +40,6 @@ var (
 	digits         = "0123456789"
 	digits         = "0123456789"
 )
 )
 
 
-const (
-	uuid = "/proc/sys/kernel/random/uuid"
-)
-
 func generatePassword(length int) string {
 func generatePassword(length int) string {
 
 
 	charset := upper + lower + digits
 	charset := upper + lower + digits
@@ -70,9 +67,9 @@ func generateIDPrefix() (string, error) {
 	}
 	}
 	log.Debugf("failed to get machine-id with usual files: %s", err)
 	log.Debugf("failed to get machine-id with usual files: %s", err)
 
 
-	bID, err := ioutil.ReadFile(uuid)
+	bId, err := uuid.NewRandom()
 	if err == nil {
 	if err == nil {
-		return string(bID), nil
+		return bId.String(), nil
 	}
 	}
 	return "", errors.Wrap(err, "generating machine id")
 	return "", errors.Wrap(err, "generating machine id")
 }
 }