Fix empty machineid (#95)

* fix

* fix

Co-authored-by: AlteredCoder <AlteredCoder>
This commit is contained in:
AlteredCoder 2020-06-29 12:46:10 +02:00 committed by GitHub
parent 2e30793188
commit 29df9704a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"path" "path"
"strings" "strings"
@ -26,9 +27,13 @@ var (
) )
var ( var (
userID string // for flag parsing
outputCTX *outputs.Output
)
const (
uuid = "/proc/sys/kernel/random/uuid"
apiConfigFile = "api.yaml" apiConfigFile = "api.yaml"
userID string // for flag parsing
outputCTX *outputs.Output
) )
func dumpCredentials() error { func dumpCredentials() error {
@ -176,7 +181,15 @@ cscli api credentials # Display your API credentials
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
id, err := machineid.ID() id, err := machineid.ID()
if err != nil { if err != nil {
log.Fatalf("failed to get machine id: %s", err) log.Debugf("failed to get machine-id with usual files : %s", err)
}
if id == "" || err != nil {
bID, err := ioutil.ReadFile(uuid)
if err != nil {
log.Fatalf("can'get a valid machine_id")
}
id = string(bID)
id = strings.ReplaceAll(id, "-", "")[:32]
} }
password := generatePassword() password := generatePassword()
@ -213,8 +226,17 @@ cscli api credentials # Display your API credentials
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
id, err := machineid.ID() id, err := machineid.ID()
if err != nil { if err != nil {
log.Fatalf("failed to get machine id: %s", err) log.Debugf("failed to get machine-id with usual files : %s", err)
} }
if id == "" || err != nil {
bID, err := ioutil.ReadFile(uuid)
if err != nil {
log.Fatalf("can'get a valid machine_id")
}
id = string(bID)
id = strings.ReplaceAll(id, "-", "")[:32]
}
password := generatePassword() password := generatePassword()
if err := outputCTX.API.ResetPassword(id, password); err != nil { if err := outputCTX.API.ResetPassword(id, password); err != nil {
log.Fatalf(err.Error()) log.Fatalf(err.Error())