2019-08-26 06:29:58 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import "net/http"
|
|
|
|
|
|
|
|
// AuthenticateUserRequest represents the body of a request to POST /auth
|
|
|
|
type AuthenticateUserRequest struct {
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
}
|
|
|
|
|
|
|
|
// AuthenticateUserResponse represents the body of a response for a request to POST /auth
|
|
|
|
type AuthenticateUserResponse struct {
|
|
|
|
Jwt string
|
|
|
|
}
|
|
|
|
|
2019-08-26 06:34:01 +00:00
|
|
|
func (n *portainerClientImp) AuthenticateUser() (token string, err error) {
|
2019-08-26 06:29:58 +00:00
|
|
|
reqBody := AuthenticateUserRequest{
|
|
|
|
Username: n.user,
|
|
|
|
Password: n.password,
|
|
|
|
}
|
|
|
|
|
|
|
|
respBody := AuthenticateUserResponse{}
|
|
|
|
|
|
|
|
err = n.doJSON("auth", http.MethodPost, http.Header{}, &reqBody, &respBody)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
token = respBody.Jwt
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|