Skip to content

Commit 9a8334d

Browse files
authored
feat(secret_manager): add ListTags to v1beta1 (#2011)
1 parent aefd897 commit 9a8334d

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

api/secret/v1beta1/secret_sdk.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,47 @@ func (r *ListSecretsResponse) UnsafeAppend(res interface{}) (uint64, error) {
734734
return uint64(len(results.Secrets)), nil
735735
}
736736

737+
// ListTagsRequest: list tags request.
738+
type ListTagsRequest struct {
739+
// Region: region to target. If none is passed will use default region from the config.
740+
Region scw.Region `json:"-"`
741+
742+
// ProjectID: ID of the Project to target.
743+
ProjectID string `json:"-"`
744+
745+
Page *int32 `json:"-"`
746+
747+
PageSize *uint32 `json:"-"`
748+
}
749+
750+
// ListTagsResponse: list tags response.
751+
type ListTagsResponse struct {
752+
// Tags: list of tags.
753+
Tags []string `json:"tags"`
754+
755+
// TotalCount: count of all tags matching the requested criteria.
756+
TotalCount uint64 `json:"total_count"`
757+
}
758+
759+
// UnsafeGetTotalCount should not be used
760+
// Internal usage only
761+
func (r *ListTagsResponse) UnsafeGetTotalCount() uint64 {
762+
return r.TotalCount
763+
}
764+
765+
// UnsafeAppend should not be used
766+
// Internal usage only
767+
func (r *ListTagsResponse) UnsafeAppend(res interface{}) (uint64, error) {
768+
results, ok := res.(*ListTagsResponse)
769+
if !ok {
770+
return 0, errors.New("%T type cannot be appended to type %T", res, r)
771+
}
772+
773+
r.Tags = append(r.Tags, results.Tags...)
774+
r.TotalCount += uint64(len(results.Tags))
775+
return uint64(len(results.Tags)), nil
776+
}
777+
737778
// ProtectSecretRequest: protect secret request.
738779
type ProtectSecretRequest struct {
739780
// Region: region to target. If none is passed will use default region from the config.
@@ -1435,3 +1476,46 @@ func (s *API) DisableSecretVersion(req *DisableSecretVersionRequest, opts ...scw
14351476
}
14361477
return &resp, nil
14371478
}
1479+
1480+
// ListTags: List all tags associated with secrets within a given Project.
1481+
func (s *API) ListTags(req *ListTagsRequest, opts ...scw.RequestOption) (*ListTagsResponse, error) {
1482+
var err error
1483+
1484+
if req.Region == "" {
1485+
defaultRegion, _ := s.client.GetDefaultRegion()
1486+
req.Region = defaultRegion
1487+
}
1488+
1489+
if req.ProjectID == "" {
1490+
defaultProjectID, _ := s.client.GetDefaultProjectID()
1491+
req.ProjectID = defaultProjectID
1492+
}
1493+
1494+
defaultPageSize, exist := s.client.GetDefaultPageSize()
1495+
if (req.PageSize == nil || *req.PageSize == 0) && exist {
1496+
req.PageSize = &defaultPageSize
1497+
}
1498+
1499+
query := url.Values{}
1500+
parameter.AddToQuery(query, "project_id", req.ProjectID)
1501+
parameter.AddToQuery(query, "page", req.Page)
1502+
parameter.AddToQuery(query, "page_size", req.PageSize)
1503+
1504+
if fmt.Sprint(req.Region) == "" {
1505+
return nil, errors.New("field Region cannot be empty in request")
1506+
}
1507+
1508+
scwReq := &scw.ScalewayRequest{
1509+
Method: "GET",
1510+
Path: "/secret-manager/v1beta1/regions/" + fmt.Sprint(req.Region) + "/tags",
1511+
Query: query,
1512+
}
1513+
1514+
var resp ListTagsResponse
1515+
1516+
err = s.client.Do(scwReq, &resp, opts...)
1517+
if err != nil {
1518+
return nil, err
1519+
}
1520+
return &resp, nil
1521+
}

0 commit comments

Comments
 (0)