Fix empty machineid (#95)
* fix * fix Co-authored-by: AlteredCoder <AlteredCoder>
This commit is contained in:
parent
2e30793188
commit
29df9704a2
1 changed files with 26 additions and 4 deletions
|
@ -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())
|
||||||
|
|
Loading…
Reference in a new issue