mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(site): add ability to create tokens from account tokens page (#6608)
* add token actions * added basic token form * removed token switch * refined date field * limiting lifetime days to maxTokenLifetime * broke apart files * added loader and error * fixed form layout * added some unit tests * fixed be tests * no authorize check
This commit is contained in:
@@ -97,6 +97,10 @@ type APIKeyWithOwner struct {
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type TokenConfig struct {
|
||||
MaxTokenLifetime time.Duration `json:"max_token_lifetime"`
|
||||
}
|
||||
|
||||
// asRequestOption returns a function that can be used in (*Client).Request.
|
||||
// It modifies the request query parameters.
|
||||
func (f TokensFilter) asRequestOption() RequestOption {
|
||||
@@ -161,3 +165,17 @@ func (c *Client) DeleteAPIKey(ctx context.Context, userID string, id string) err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTokenConfig returns deployment options related to token management
|
||||
func (c *Client) GetTokenConfig(ctx context.Context, userID string) (TokenConfig, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/users/%s/keys/tokens/tokenconfig", userID), nil)
|
||||
if err != nil {
|
||||
return TokenConfig{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode > http.StatusOK {
|
||||
return TokenConfig{}, ReadBodyAsError(res)
|
||||
}
|
||||
tokenConfig := TokenConfig{}
|
||||
return tokenConfig, json.NewDecoder(res.Body).Decode(&tokenConfig)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user