-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add loggedin user account related entities and API enpoint
interactions
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package api | ||
|
||
import "github.com/maas/gomaasclient/entity" | ||
|
||
// Account is an interface for managing User Account | ||
type Account interface { | ||
CreateAuthorisationToken(name string) (*entity.AuthorisationToken, error) | ||
DeleteAuthorisationToken(key string) | ||
ListAuthorisationTokens() ([]entity.AuthorisationToken, error) | ||
UpdateTokenName(name, token string) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"net/url" | ||
|
||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// Account implements api.Account | ||
type Account struct { | ||
APIClient APIClient | ||
} | ||
|
||
func (a *Account) client() APIClient { | ||
return a.APIClient.GetSubObject("account") | ||
} | ||
|
||
// CreateAuthorisationToken creates authorisation token with provided name | ||
func (a *Account) CreateAuthorisationToken(name string) (*entity.AuthorisationToken, error) { | ||
qsp := url.Values{} | ||
qsp.Set("name", name) | ||
|
||
authToken := new(entity.AuthorisationToken) | ||
err := a.client().Post("create_authorisation_token", qsp, func(data []byte) error { | ||
return json.Unmarshal(data, authToken) | ||
}) | ||
|
||
return authToken, err | ||
} | ||
|
||
// DeleteAuthorisationToken deletes authorisation token with provided key | ||
func (a *Account) DeleteAuthorisationToken(key string) { | ||
qsp := url.Values{} | ||
qsp.Set("token_key", key) | ||
a.client().Post("delete_authorisation_token", qsp, func(data []byte) error { return nil }) | ||
} | ||
|
||
// ListAuthorisationTokens Lists authorisation tokens | ||
func (a *Account) ListAuthorisationTokens() ([]entity.AuthorisationToken, error) { | ||
authToken := make([]entity.AuthorisationToken, 0) | ||
err := a.client().Get("list_authorisation_tokens", url.Values{}, func(data []byte) error { | ||
return json.Unmarshal(data, &authToken) | ||
}) | ||
|
||
return authToken, err | ||
} | ||
|
||
// UpdateTokenName updates given token with provided name | ||
func (a *Account) UpdateTokenName(name, token string) { | ||
qsp := url.Values{} | ||
qsp.Set("name", name) | ||
qsp.Set("token", token) | ||
a.client().Post("update_token_name", qsp, func(data []byte) error { return nil }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package entity | ||
|
||
type AuthorisationToken struct { | ||
Name string `json:"name,omitempty"` | ||
TokenKey string `json:"token_key,omitempty"` | ||
TokenSecret string `json:"token_secret,omitempty"` | ||
ConsumerKey string `json:"consumer_key,omitempty"` | ||
} |