Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HV-1702 create postgres rotating secret #192

Merged
merged 11 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/192.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
hvs: support postgres rotating secret CRUDL
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/hcl/v2 v2.22.0
github.com/hashicorp/hcp-sdk-go v0.117.0
github.com/hashicorp/hcp-sdk-go v0.121.0
github.com/lithammer/dedent v1.1.0
github.com/manifoldco/promptui v0.9.0
github.com/mitchellh/cli v1.1.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mO
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M=
github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
github.com/hashicorp/hcp-sdk-go v0.117.0 h1:7lJpkinpWdsXtejC+X7MdaE/3zhFMweB9Ym3uJ7qFJw=
github.com/hashicorp/hcp-sdk-go v0.117.0/go.mod h1:vQ4fzdL1AmhIAbCw+4zmFe5Hbpajj3NvRWkJoVuxmAk=
github.com/hashicorp/hcp-sdk-go v0.121.0 h1:fDCB0sexSNontS7LLuhF1RJd7eYx1hmFVBFmY4kXU78=
github.com/hashicorp/hcp-sdk-go v0.121.0/go.mod h1:vQ4fzdL1AmhIAbCw+4zmFe5Hbpajj3NvRWkJoVuxmAk=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
MongoDBAtlas IntegrationType = "mongodb-atlas"
AWS IntegrationType = "aws"
GCP IntegrationType = "gcp"
Postgres IntegrationType = "postgres"
)

func NewCmdIntegrations(ctx *cmd.Context) *cmd.Command {
Expand Down
33 changes: 33 additions & 0 deletions internal/commands/vaultsecrets/secrets/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ var (
},
}

postgresRotatingSecretTemplate = map[string]any{
"integration_name": "",
"rotation_policy_name": "",
"postgres_params": map[string]any{
"usernames": "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this allow multiple usernames to be specified?

},
}

awsDynamicSecretTemplate = map[string]any{
"integration_name": "",
"default_ttl": "",
Expand Down Expand Up @@ -365,6 +373,30 @@ func createRun(opts *CreateOpts) error {
return fmt.Errorf("failed to create secret with name %q: %w", opts.SecretName, err)
}

case integrations.Postgres:
req := preview_secret_service.NewCreatePostgresRotatingSecretParamsWithContext(opts.Ctx)
req.OrganizationID = opts.Profile.OrganizationID
req.AppName = opts.AppName

var postgresBody preview_models.SecretServiceCreatePostgresRotatingSecretBody
detailBytes, err := json.Marshal(internalConfig.Details)
if err != nil {
return fmt.Errorf("error marshaling details config: %w", err)
}

err = postgresBody.UnmarshalBinary(detailBytes)
if err != nil {
return fmt.Errorf("error marshaling details config: %w", err)
}

postgresBody.Name = opts.SecretName
req.Body = &postgresBody

_, err = opts.PreviewClient.CreatePostgresRotatingSecret(req, nil)
if err != nil {
return fmt.Errorf("failed to create secret with name %q: %w", opts.SecretName, err)
}

default:
return fmt.Errorf("unsupported rotating secret provider type")
}
Expand Down Expand Up @@ -538,6 +570,7 @@ var availableRotatingSecretProviders = map[string]map[string]any{
string(integrations.MongoDBAtlas): mongoDBAtlasRotatingSecretTemplate,
string(integrations.AWS): awsRotatingSecretTemplate,
string(integrations.GCP): gcpRotatingSecretTemplate,
string(integrations.Postgres): postgresRotatingSecretTemplate,
}

var availableDynamicSecretProviders = map[string]map[string]any{
Expand Down
25 changes: 25 additions & 0 deletions internal/commands/vaultsecrets/secrets/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,31 @@ func updateRun(opts *UpdateOpts) error {
if err != nil {
return fmt.Errorf("failed to update secret with name %q: %w", opts.SecretName, err)
}

case integrations.Postgres:
req := preview_secret_service.NewUpdatePostgresRotatingSecretParamsWithContext(opts.Ctx)
req.OrganizationID = opts.Profile.OrganizationID
req.ProjectID = opts.Profile.ProjectID
req.AppName = opts.AppName
req.Name = opts.SecretName

var postgresBody preview_models.SecretServiceUpdatePostgresRotatingSecretBody
detailBytes, err := json.Marshal(internalConfig.Details)
if err != nil {
return fmt.Errorf("error marshaling details config: %w", err)
}

err = postgresBody.UnmarshalBinary(detailBytes)
if err != nil {
return fmt.Errorf("error unmarshaling details config: %w", err)
}

req.Body = &postgresBody

_, err = opts.PreviewClient.UpdatePostgresRotatingSecret(req, nil)
if err != nil {
return fmt.Errorf("failed to update secret with name %q: %w", opts.SecretName, err)
}
}

case secretTypeDynamic:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading