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 (
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"path"
"strings"
@ -26,9 +27,13 @@ var (
)
var (
userID string // for flag parsing
outputCTX *outputs.Output
)
const (
uuid = "/proc/sys/kernel/random/uuid"
apiConfigFile = "api.yaml"
userID string // for flag parsing
outputCTX *outputs.Output
)
func dumpCredentials() error {
@ -176,7 +181,15 @@ cscli api credentials # Display your API credentials
Run: func(cmd *cobra.Command, args []string) {
id, err := machineid.ID()
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()
@ -213,8 +226,17 @@ cscli api credentials # Display your API credentials
Run: func(cmd *cobra.Command, args []string) {
id, err := machineid.ID()
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()
if err := outputCTX.API.ResetPassword(id, password); err != nil {
log.Fatalf(err.Error())