Skip to content

Commit 6d7109e

Browse files
authored
feat(secret_manager): add set secret owner endpoint (#1660)
1 parent 5690851 commit 6d7109e

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

api/secret/v1alpha1/secret_sdk.go

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ var (
3939
_ = namegenerator.GetRandomName
4040
)
4141

42-
// API: this API allows you to conveniently store, access and share sensitive data.
43-
// Secret Manager API documentation.
42+
// API: secret Manager API.
43+
// This API allows you to conveniently store, access and share sensitive data.
4444
type API struct {
4545
client *scw.Client
4646
}
@@ -158,7 +158,7 @@ type AccessSecretVersionResponse struct {
158158
// Data: the base64-encoded secret payload of the version.
159159
Data []byte `json:"data"`
160160
// DataCrc32: the CRC32 checksum of the data as a base-10 integer.
161-
// This field is present only if a CRC32 was supplied during the creation of the version.
161+
// This field is only available if a CRC32 was supplied during the creation of the version.
162162
DataCrc32 *uint32 `json:"data_crc32"`
163163
}
164164

@@ -435,69 +435,25 @@ func (s *API) UpdateSecret(req *UpdateSecretRequest, opts ...scw.RequestOption)
435435
return &resp, nil
436436
}
437437

438-
type AddSecretOwnerRequest struct {
439-
// Region: region to target. If none is passed will use default region from the config.
440-
Region scw.Region `json:"-"`
441-
// SecretID: ID of the secret.
442-
SecretID string `json:"-"`
443-
// ProductName: name of the product to add.
444-
ProductName string `json:"product_name"`
445-
}
446-
447-
// AddSecretOwner: allow another product to use the secret.
448-
func (s *API) AddSecretOwner(req *AddSecretOwnerRequest, opts ...scw.RequestOption) error {
449-
var err error
450-
451-
if req.Region == "" {
452-
defaultRegion, _ := s.client.GetDefaultRegion()
453-
req.Region = defaultRegion
454-
}
455-
456-
if fmt.Sprint(req.Region) == "" {
457-
return errors.New("field Region cannot be empty in request")
458-
}
459-
460-
if fmt.Sprint(req.SecretID) == "" {
461-
return errors.New("field SecretID cannot be empty in request")
462-
}
463-
464-
scwReq := &scw.ScalewayRequest{
465-
Method: "POST",
466-
Path: "/secret-manager/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/secrets/" + fmt.Sprint(req.SecretID) + "/add-owner",
467-
Headers: http.Header{},
468-
}
469-
470-
err = scwReq.SetBody(req)
471-
if err != nil {
472-
return err
473-
}
474-
475-
err = s.client.Do(scwReq, nil, opts...)
476-
if err != nil {
477-
return err
478-
}
479-
return nil
480-
}
481-
482438
type ListSecretsRequest struct {
483439
// Region: region to target. If none is passed will use default region from the config.
484440
Region scw.Region `json:"-"`
485441
// OrganizationID: filter by Organization ID (optional).
486442
OrganizationID *string `json:"-"`
487443
// ProjectID: filter by Project ID (optional).
488444
ProjectID *string `json:"-"`
489-
// Name: filter by secret name (optional).
490-
Name *string `json:"-"`
491-
// Tags: list of tags to filter on (optional).
492-
Tags []string `json:"-"`
493-
// IsManaged: filter by managed / not managed (optional).
494-
IsManaged *bool `json:"-"`
495445
// OrderBy: default value: name_asc
496446
OrderBy ListSecretsRequestOrderBy `json:"-"`
497447

498448
Page *int32 `json:"-"`
499449

500450
PageSize *uint32 `json:"-"`
451+
// Tags: list of tags to filter on (optional).
452+
Tags []string `json:"-"`
453+
// Name: filter by secret name (optional).
454+
Name *string `json:"-"`
455+
// IsManaged: filter by managed / not managed (optional).
456+
IsManaged *bool `json:"-"`
501457
}
502458

503459
// ListSecrets: list secrets.
@@ -583,6 +539,50 @@ func (s *API) DeleteSecret(req *DeleteSecretRequest, opts ...scw.RequestOption)
583539
return nil
584540
}
585541

542+
type AddSecretOwnerRequest struct {
543+
// Region: region to target. If none is passed will use default region from the config.
544+
Region scw.Region `json:"-"`
545+
// SecretID: ID of the secret.
546+
SecretID string `json:"-"`
547+
// ProductName: name of the product to add.
548+
ProductName string `json:"product_name"`
549+
}
550+
551+
// AddSecretOwner: allow a product to use the secret.
552+
func (s *API) AddSecretOwner(req *AddSecretOwnerRequest, opts ...scw.RequestOption) error {
553+
var err error
554+
555+
if req.Region == "" {
556+
defaultRegion, _ := s.client.GetDefaultRegion()
557+
req.Region = defaultRegion
558+
}
559+
560+
if fmt.Sprint(req.Region) == "" {
561+
return errors.New("field Region cannot be empty in request")
562+
}
563+
564+
if fmt.Sprint(req.SecretID) == "" {
565+
return errors.New("field SecretID cannot be empty in request")
566+
}
567+
568+
scwReq := &scw.ScalewayRequest{
569+
Method: "POST",
570+
Path: "/secret-manager/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/secrets/" + fmt.Sprint(req.SecretID) + "/add-owner",
571+
Headers: http.Header{},
572+
}
573+
574+
err = scwReq.SetBody(req)
575+
if err != nil {
576+
return err
577+
}
578+
579+
err = s.client.Do(scwReq, nil, opts...)
580+
if err != nil {
581+
return err
582+
}
583+
return nil
584+
}
585+
586586
type CreateSecretVersionRequest struct {
587587
// Region: region to target. If none is passed will use default region from the config.
588588
Region scw.Region `json:"-"`
@@ -596,11 +596,11 @@ type CreateSecretVersionRequest struct {
596596
// Optional. If there is no previous version or if the previous version was already disabled, does nothing.
597597
DisablePrevious *bool `json:"disable_previous"`
598598
// PasswordGeneration: options to generate a password.
599-
// Optional. If specified, a random password will be generated. The data and data_crc32 fields must be empty. By default, the generator will use upper and lower case letters, and digits. This behavior can be tuned using the generation parameters.
599+
// Optional. If specified, a random password will be generated. The `data` and `data_crc32` fields must be empty. By default, the generator will use upper and lower case letters, and digits. This behavior can be tuned using the generation parameters.
600600
// Precisely one of PasswordGeneration must be set.
601601
PasswordGeneration *PasswordGenerationParams `json:"password_generation,omitempty"`
602602
// DataCrc32: the CRC32 checksum of the data as a base-10 integer.
603-
// Optional. If specified, the Secret Manager will verify the integrity of the data received against the given CRC32. An error is returned if the CRC32 does not match. Otherwise, the CRC32 will be stored and returned along with the SecretVersion on futur accesses.
603+
// Optional. If specified, Secret Manager will verify the integrity of the data received against the given CRC32. An error is returned if the CRC32 does not match. Otherwise, the CRC32 will be stored and returned along with the SecretVersion on futur accesses.
604604
DataCrc32 *uint32 `json:"data_crc32"`
605605
}
606606

0 commit comments

Comments
 (0)