join as api call

Signed-off-by: Matthew R. Kasun <mkasun@nusak.ca>
This commit is contained in:
Matthew R. Kasun
2022-04-20 15:44:33 -04:00
parent 12dfc5f820
commit 955e0e544c
4 changed files with 80 additions and 136 deletions

View File

@@ -352,11 +352,16 @@ func Authenticate(cfg *config.ClientConfig) (string, error) {
if err != nil {
return "", err
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
bodybytes, _ := ioutil.ReadAll(response.Body)
return "", fmt.Errorf("failed to authenticate %s %s", response.Status, string(bodybytes))
}
resp := models.SuccessResponse{}
if err := json.NewDecoder(response.Body).Decode(&resp); err != nil {
return "", err
return "", fmt.Errorf("error decoding respone %w", err)
}
tokenData := (resp.Response.(map[string]interface{}))
tokenData := resp.Response.(map[string]interface{})
token := tokenData["AuthToken"]
return token.(string), nil
}