Skip to content

Commit

Permalink
fix (id): work with multiple containers
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-kerjean committed Jan 22, 2024
1 parent e34c2a0 commit 2a69ffa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
22 changes: 22 additions & 0 deletions common/random.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package common

import (
"crypto/rand"
"math/big"
)

var Letters = []rune("abcdefghijklmnopqrstuvwxyz0123456789")

func RandomString(n int) string {
b := make([]rune, n)
for i := range b {
max := *big.NewInt(int64(len(Letters)))
r, err := rand.Int(rand.Reader, &max)
if err != nil {
b[i] = Letters[0]
} else {
b[i] = Letters[r.Int64()]
}
}
return string(b)
}
18 changes: 0 additions & 18 deletions ctrl/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package ctrl

import (
"context"
"crypto/rand"
"crypto/tls"
"fmt"
"io/ioutil"
"math/big"
"net/http"
"time"

Expand Down Expand Up @@ -131,19 +129,3 @@ func setup(url string, tenant string, jsonInfo []byte, retry int) error {
ws.Close()
return nil
}

var Letters = []rune("abcdefghijklmnopqrstuvwxyz0123456789")

func RandomString(n int) string {
b := make([]rune, n)
for i := range b {
max := *big.NewInt(int64(len(Letters)))
r, err := rand.Int(rand.Reader, &max)
if err != nil {
b[i] = Letters[0]
} else {
b[i] = Letters[r.Int64()]
}
}
return string(b)
}
6 changes: 3 additions & 3 deletions webfleet/model/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func GetMachineInfo() []byte {
content, err := os.ReadFile("/etc/machine-id")
if err != nil {
return ""
} else if string(content) == "" {
content, _ = os.ReadFile("/proc/sys/kernel/random/uuid")
} else if string(content) != "" {
return strings.TrimSpace(string(content))
}
return strings.TrimSpace(string(content))
return RandomString(5)
}(),
Device: func() string {
if isMac() {
Expand Down

0 comments on commit 2a69ffa

Please sign in to comment.