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

Commit

Permalink
feat: add api operations for project properties
Browse files Browse the repository at this point in the history
Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed Sep 27, 2021
1 parent 99425c7 commit 24e0c68
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 10 deletions.
22 changes: 12 additions & 10 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ type Client struct {
userAgent string
debug bool

About AboutService
Analysis AnalysisService
BOM BOMService
Component ComponentService
Finding FindingService
License LicenseService
Project ProjectService
Repository RepositoryService
User UserService
Vulnerability VulnerabilityService
About AboutService
Analysis AnalysisService
BOM BOMService
Component ComponentService
Finding FindingService
License LicenseService
Project ProjectService
ProjectProperty ProjectPropertyService
Repository RepositoryService
User UserService
Vulnerability VulnerabilityService
}

func NewClient(baseURL string, options ...ClientOption) (*Client, error) {
Expand Down Expand Up @@ -71,6 +72,7 @@ func NewClient(baseURL string, options ...ClientOption) (*Client, error) {
client.Finding = FindingService{client: &client}
client.License = LicenseService{client: &client}
client.Project = ProjectService{client: &client}
client.ProjectProperty = ProjectPropertyService{client: &client}
client.Repository = RepositoryService{client: &client}
client.User = UserService{client: &client}
client.Vulnerability = VulnerabilityService{client: &client}
Expand Down
83 changes: 83 additions & 0 deletions project_property.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,92 @@
package dtrack

import (
"context"
"fmt"
"github.com/google/uuid"
"net/http"
)

type ProjectProperty struct {
Group string `json:"groupName"`
Name string `json:"propertyName"`
Value string `json:"propertyValue"`
Type string `json:"propertyType"`
Description string `json:"description"`
}

type ProjectPropertiesPage struct {
Properties []ProjectProperty
TotalCount int
}

type ProjectPropertyService struct {
client *Client
}

func (p ProjectPropertyService) GetAll(ctx context.Context, projectUUID uuid.UUID, po PageOptions) (*ProjectPropertiesPage, error) {
req, err := p.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/project/%s/property", projectUUID), withPageOptions(po))
if err != nil {
return nil, err
}

var properties []ProjectProperty
res, err := p.client.doRequest(req, &properties)
if err != nil {
return nil, err
}

return &ProjectPropertiesPage{
Properties: properties,
TotalCount: res.TotalCount,
}, nil
}

func (p ProjectPropertyService) Create(ctx context.Context, projectUUID uuid.UUID, property ProjectProperty) (*ProjectProperty, error) {
req, err := p.client.newRequest(ctx, http.MethodPut, fmt.Sprintf("/api/v1/project/%s/property", projectUUID), withBody(property))
if err != nil {
return nil, err
}

var createdProperty ProjectProperty
_, err = p.client.doRequest(req, &createdProperty)
if err != nil {
return nil, err
}

return &createdProperty, nil
}

func (p ProjectPropertyService) Update(ctx context.Context, projectUUID uuid.UUID, property ProjectProperty) (*ProjectProperty, error) {
req, err := p.client.newRequest(ctx, http.MethodPost, fmt.Sprintf("/api/v1/project/%s/property", projectUUID), withBody(property))
if err != nil {
return nil, err
}

var updatedProperty ProjectProperty
_, err = p.client.doRequest(req, &updatedProperty)
if err != nil {
return nil, err
}

return &updatedProperty, nil
}

func (p ProjectPropertyService) Delete(ctx context.Context, projectUUID uuid.UUID, groupName, propertyName string) error {
property := ProjectProperty{
Group: groupName,
Name: propertyName,
}

req, err := p.client.newRequest(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/project/%s/property", projectUUID), withBody(property))
if err != nil {
return err
}

_, err = p.client.doRequest(req, nil)
if err != nil {
return err
}

return nil
}

0 comments on commit 24e0c68

Please sign in to comment.