mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
39 lines
883 B
Go
39 lines
883 B
Go
package client
|
|
|
|
import "net/http"
|
|
|
|
// AuthenticateUserOptions represents options passed to PortainerClient.AuthenticateUser()
|
|
type AuthenticateUserOptions struct {
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
func (n *portainerClientImp) AuthenticateUser(options AuthenticateUserOptions) (token string, err error) {
|
|
reqBody := AuthenticateUserRequest{
|
|
Username: options.Username,
|
|
Password: options.Password,
|
|
}
|
|
|
|
respBody := AuthenticateUserResponse{}
|
|
|
|
err = n.doJSON("auth", http.MethodPost, http.Header{}, &reqBody, &respBody)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
token = respBody.Jwt
|
|
|
|
return
|
|
}
|