Skip to content

Commit

Permalink
chore: Updating CHANGELOG.md and adding EXPERIMENTAL
Browse files Browse the repository at this point in the history
  • Loading branch information
paketeserrano committed Jan 31, 2025
1 parent 2b90cb2 commit 125be91
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Added
- Added support for token-based authentication in the client, including functions for token management.

## [8.14.0]

### Added
Expand Down
2 changes: 1 addition & 1 deletion upcloud/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func WithBasicAuth(username, password string) ConfigFn {
}
}

// WithBearerAuth configures the client to use bearer token for authentication
// WithBearerAuth (EXPERIMENTAL) configures the client to use bearer token for authentication
func WithBearerAuth(apiToken string) ConfigFn {
return func(c *config) {
c.token = apiToken
Expand Down
14 changes: 8 additions & 6 deletions upcloud/request/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ import (

const basePath = "/account/tokens"

// GetTokenDetailsRequest represents a request to get token details. Will not return the actual API token.
// GetTokenDetailsRequest (EXPERIMENTAL) represents a request to get token details. Will not return the actual API token.
type GetTokenDetailsRequest struct {
ID string
}

// RequestURL (EXPERIMENTAL) implements the Request interface.
func (r *GetTokenDetailsRequest) RequestURL() string {
return fmt.Sprintf("%s/%s", basePath, r.ID)
}

// GetTokensRequest represents a request to get a list of tokens. Will not return the actual API tokens.
// GetTokensRequest (EXPERIMENTAL) represents a request to get a list of tokens. Will not return the actual API tokens.
type GetTokensRequest struct {
Page *Page
}

// RequestURL (EXPERIMENTAL) implements the Request interface.
func (r *GetTokensRequest) RequestURL() string {
if r.Page != nil {
f := make([]QueryFilter, 0)
Expand All @@ -31,25 +33,25 @@ func (r *GetTokensRequest) RequestURL() string {
return basePath
}

// CreateTokenRequest represents a request to create a new network.
// CreateTokenRequest (EXPERIMENTAL) represents a request to create a new network.
type CreateTokenRequest struct {
Name string `json:"name"`
ExpiresAt time.Time `json:"expires_at"`
CanCreateSubTokens bool `json:"can_create_tokens"`
AllowedIPRanges []string `json:"allowed_ip_ranges"`
}

// RequestURL implements the Request interface.
// RequestURL (EXPERIMENTAL) implements the Request interface.
func (r *CreateTokenRequest) RequestURL() string {
return basePath
}

// DeleteTokenRequest represents a request to delete a token.
// DeleteTokenRequest (EXPERIMENTAL) represents a request to delete a token.
type DeleteTokenRequest struct {
ID string
}

// RequestURL implements the Request interface.
// RequestURL (EXPERIMENTAL) implements the Request interface.
func (r *DeleteTokenRequest) RequestURL() string {
return fmt.Sprintf("%s/%s", basePath, r.ID)
}
8 changes: 4 additions & 4 deletions upcloud/service/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ type Token interface {
DeleteToken(context.Context, *request.DeleteTokenRequest) error
}

// CreateToken creates a new token.
// CreateToken (EXPERIMENTAL) creates a new token.
func (s *Service) CreateToken(ctx context.Context, r *request.CreateTokenRequest) (*upcloud.Token, error) {
token := upcloud.Token{}
return &token, s.create(ctx, r, &token)
}

// GetTokenDetails returns the details for the specified token.
// GetTokenDetails (EXPERIMENTAL) returns the details for the specified token.
func (s *Service) GetTokenDetails(ctx context.Context, r *request.GetTokenDetailsRequest) (*upcloud.Token, error) {
token := upcloud.Token{}
return &token, s.get(ctx, r.RequestURL(), &token)
}

// GetTokens returns the all the available networks
// GetTokens (EXPERIMENTAL) returns the all the available networks
func (s *Service) GetTokens(ctx context.Context, req *request.GetTokensRequest) (*upcloud.Tokens, error) {
tokens := upcloud.Tokens{}
return &tokens, s.get(ctx, req.RequestURL(), &tokens)
}

// DeleteToken deletes the specified token.
// DeleteToken (EXPERIMENTAL) deletes the specified token.
func (s *Service) DeleteToken(ctx context.Context, r *request.DeleteTokenRequest) error {
return s.delete(ctx, r)
}

0 comments on commit 125be91

Please sign in to comment.