mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-27 11:53:53 +00:00
Update storageos api dependency to 0.3.4
This commit is contained in:
46
vendor/github.com/storageos/go-api/login.go
generated
vendored
Normal file
46
vendor/github.com/storageos/go-api/login.go
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
package storageos
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
// LoginAPIPrefix is a partial path to the HTTP endpoint.
|
||||
LoginAPIPrefix = "auth/login"
|
||||
ErrLoginFailed = errors.New("Failed to get token from API endpoint")
|
||||
)
|
||||
|
||||
// Login attemps to get a token from the API
|
||||
func (c *Client) Login() (token string, err error) {
|
||||
resp, err := c.do("POST", LoginAPIPrefix, doOptions{data: struct {
|
||||
User string `json:"username"`
|
||||
Pass string `json:"password"`
|
||||
}{c.username, c.secret}})
|
||||
|
||||
if err != nil {
|
||||
if _, ok := err.(*Error); ok {
|
||||
return "", ErrLoginFailed
|
||||
}
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return "", ErrLoginFailed
|
||||
}
|
||||
|
||||
unmarsh := struct {
|
||||
Token string `json:"token"`
|
||||
}{}
|
||||
|
||||
if err := json.NewDecoder(resp.Body).Decode(&unmarsh); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if unmarsh.Token == "" {
|
||||
return "", ErrLoginFailed
|
||||
}
|
||||
|
||||
return unmarsh.Token, nil
|
||||
}
|
||||
Reference in New Issue
Block a user