Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
feat: add support for team resource
Browse files Browse the repository at this point in the history
Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed Oct 17, 2022
1 parent 14ac2b9 commit de4afb5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Client struct {
Project ProjectService
ProjectProperty ProjectPropertyService
Repository RepositoryService
Team TeamService
User UserService
VEX VEXService
ViolationAnalysis ViolationAnalysisService
Expand Down Expand Up @@ -83,6 +84,7 @@ func NewClient(baseURL string, options ...ClientOption) (*Client, error) {
client.Project = ProjectService{client: &client}
client.ProjectProperty = ProjectPropertyService{client: &client}
client.Repository = RepositoryService{client: &client}
client.Team = TeamService{client: &client}
client.User = UserService{client: &client}
client.VEX = VEXService{client: &client}
client.ViolationAnalysis = ViolationAnalysisService{client: &client}
Expand Down
60 changes: 60 additions & 0 deletions team.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package dtrack

import (
"context"
"fmt"
"net/http"

"github.com/google/uuid"
)

type Team struct {
UUID uuid.UUID `json:"uuid,omitempty"`
Name string `json:"name,omitempty"`
APIKeys []APIKey `json:"apiKeys,omitempty"`
}

type APIKey struct {
Key string `json:"key"`
}

type TeamService struct {
client *Client
}

func (ts TeamService) Get(ctx context.Context, teamUUID uuid.UUID) (p Project, err error) {
req, err := ts.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/team/%s", teamUUID))
if err != nil {
return
}

_, err = ts.client.doRequest(req, &p)
return
}

func (ts TeamService) GetAll(ctx context.Context, po PageOptions) (p Page[Team], err error) {
req, err := ts.client.newRequest(ctx, http.MethodGet, "/api/v1/team", withPageOptions(po))
if err != nil {
return
}

res, err := ts.client.doRequest(req, &p.Items)
if err != nil {
return
}

p.TotalCount = res.TotalCount
return
}

func (ts TeamService) GenerateAPIKey(ctx context.Context, teamUUID uuid.UUID) (key string, err error) {
req, err := ts.client.newRequest(ctx, http.MethodPut, fmt.Sprintf("/api/v1/team/%s/key", teamUUID))
if err != nil {
return
}

var apiKey APIKey
_, err = ts.client.doRequest(req, &apiKey)
key = apiKey.Key
return
}

0 comments on commit de4afb5

Please sign in to comment.