Skip to content

Commit

Permalink
auth: update auth resource to API v3
Browse files Browse the repository at this point in the history
  • Loading branch information
drbild committed Apr 20, 2020
1 parent 71ca1af commit b3dcd1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
14 changes: 7 additions & 7 deletions enf/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ type AuthRequest struct {
// Credentials represents the authentication credentials returned by
// the auth API.
type Credentials struct {
Username *string `json:"username"`
Token *string `json:"token"`
UserID *int64 `json:"user_id"`
UserType *string `json:"type"`
DomainID *int64 `json:"domain_id"`
DomainNetwork *string `json:"domain_network"`
Username *string `json:"username"`
Token *string `json:"token"`
UserID *int64 `json:"user_id"`
Roles []*UserRole `json:"roles"`
DomainID *int64 `json:"domain_id"`
Domain *string `json:"domain"`
}

type authResponse struct {
Expand All @@ -49,7 +49,7 @@ func (s *AuthService) Authenticate(ctx context.Context, authReq *AuthRequest) (*
return nil, nil, ErrMissingPassword
}

endpoint := "/api/xcr/v2/xauth"
endpoint := "/api/xcr/v3/xauth"

body, resp, err := s.client.post(ctx, endpoint, new(authResponse), authReq)
if err != nil {
Expand Down
19 changes: 15 additions & 4 deletions enf/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestAuthService_Authenticate(t *testing.T) {
path := "/api/xcr/v2/xauth"
path := "/api/xcr/v3/xauth"

requestBody := &AuthRequest{
Username: String("user"),
Expand All @@ -19,18 +19,29 @@ func TestAuthService_Authenticate(t *testing.T) {
{
"username":"user",
"token":"12345678",
"user_id":1
"user_id":1,
"roles": [
{
"cidr" : "N/n0",
"role" : "NETWORK_USER"
}
]
}
],
"page": {
}
}
}`

expected := &Credentials{
Username: String("user"),
Token: String("12345678"),
UserID: Int64(1),
Roles: []*UserRole{
{
CIDR: String("N/n0"),
Role: String("NETWORK_USER"),
},
},
}

method := func(client *Client) (interface{}, *http.Response, error) {
Expand Down

0 comments on commit b3dcd1e

Please sign in to comment.