Skip to content

Commit

Permalink
feat: api personal token
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwelbm committed Jul 10, 2024
1 parent a80b0b9 commit 2a1543c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
11 changes: 7 additions & 4 deletions pkg/api/personal_token/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ type Request struct {

func (c *Client) Create(ctx context.Context, req *Request) (Response, error) {
logger.Debug("Create Personal Token")

response, httpResp, err := c.apiClient.PersonalTokenApi.CreatePersonalToken(ctx).
CreatePersonalTokenRequest(req.CreatePersonalTokenRequest).Execute()

if err != nil {
logger.Error("Error while creating a personal token", zap.Error(err))
if httpResp != nil {
logger.Debug("Error while creating your personal token", zap.Error(err))
err := utils.LogAndRewindBody(httpResp)
if err != nil {
return nil, err
}
}
return nil, utils.ErrorPerStatusCode(httpResp, err)
}

return response, nil
}
10 changes: 7 additions & 3 deletions pkg/api/personal_token/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import (

func (c *Client) Delete(ctx context.Context, id string) error {
logger.Debug("Delete personal token")

httpResp, err := c.apiClient.PersonalTokenApi.DeletePersonalToken(ctx, id).Execute()
if err != nil {
logger.Debug("Error while deleting a personal token", zap.Error(err))
if httpResp != nil {
logger.Debug("Error while delete your personal token", zap.Error(err))
err := utils.LogAndRewindBody(httpResp)
if err != nil {
return err
}
}
return utils.ErrorPerStatusCode(httpResp, err)
}

return nil
}
27 changes: 27 additions & 0 deletions pkg/api/personal_token/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package personal_token

import (
"context"

"github.com/aziontech/azion-cli/pkg/logger"
"github.com/aziontech/azion-cli/utils"
"go.uber.org/zap"

sdk "github.com/aziontech/azionapi-go-sdk/personal_tokens"
)

func (c *Client) Get(ctx context.Context, personalTokenID string) (*sdk.PersonalTokenResponseGet, error) {
logger.Debug("Get Personal Token")
resp, httpResp, err := c.apiClient.PersonalTokenApi.GetPersonalToken(ctx, personalTokenID).Execute()
if err != nil {
if httpResp != nil {
logger.Debug("Error while get your personal token", zap.Error(err))
err := utils.LogAndRewindBody(httpResp)
if err != nil {
return nil, err
}
}
return nil, utils.ErrorPerStatusCode(httpResp, err)
}
return resp, nil
}
10 changes: 7 additions & 3 deletions pkg/api/personal_token/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import (

func (c *Client) List(ctx context.Context) ([]sdk.PersonalTokenResponseGet, error) {
logger.Debug("List Personal Tokens")

resp, httpResp, err := c.apiClient.PersonalTokenApi.ListPersonalToken(ctx).Execute()
if err != nil {
logger.Error("Error while listing personal tokens", zap.Error(err))
if httpResp != nil {
logger.Debug("Error while list your personal token", zap.Error(err))
err := utils.LogAndRewindBody(httpResp)
if err != nil {
return nil, err
}
}
return nil, utils.ErrorPerStatusCode(httpResp, err)
}

return resp.Results, nil
}

0 comments on commit 2a1543c

Please sign in to comment.