Skip to content
Snippets Groups Projects
Commit f8ff5570 authored by André Sterba's avatar André Sterba
Browse files

Fix cli parsing of pnd and sbi

parent 3536b64f
No related branches found
No related tags found
1 merge request!150Let user set a name for a device or autogenerate it
Pipeline #68985 failed
......@@ -3,11 +3,12 @@ package cli
import (
"errors"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"io/ioutil"
"net/http"
"strings"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
const apiRoot = "?"
......@@ -26,6 +27,7 @@ func HTTPGet(apiEndpoint, f string, args ...string) error {
}
resp, err := http.Get(apiEndpoint + apiRoot + "q=" + f + builder.String())
if err != nil {
log.Info(fmt.Sprintf("Err: %s", err))
return err
}
builder.Reset()
......@@ -38,8 +40,8 @@ func HTTPGet(apiEndpoint, f string, args ...string) error {
}
switch f {
case "init":
pnd := string(bytes[:36])
sbi := string(bytes[36:])
pnd := string(bytes[9:45])
sbi := string(bytes[55:91])
viper.Set("CLI_PND", pnd)
viper.Set("CLI_SBI", sbi)
err := viper.WriteConfig()
......@@ -49,6 +51,7 @@ func HTTPGet(apiEndpoint, f string, args ...string) error {
default:
fmt.Println(string(bytes))
}
case http.StatusCreated:
defer resp.Body.Close()
bytes, err := ioutil.ReadAll(resp.Body)
......@@ -58,8 +61,8 @@ func HTTPGet(apiEndpoint, f string, args ...string) error {
uuid := string(bytes[19:55])
viper.Set("LAST_DEVICE_UUID", uuid)
fmt.Println(string(bytes))
case http.StatusAccepted:
case http.StatusAccepted:
default:
log.WithFields(log.Fields{
"status code": resp.StatusCode,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment