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

Hyperdrive: Password should be nested in Origin #1501

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/1501.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
hyperdrive: password should be nested in origin
```
43 changes: 31 additions & 12 deletions hyperdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import (
)

var (
ErrMissingHyperdriveConfigID = errors.New("required hyperdrive config id is missing")
ErrMissingHyperdriveConfigName = errors.New("required hyperdrive config name is missing")
ErrMissingHyperdriveConfigPassword = errors.New("required hyperdrive config password is missing")
ErrMissingHyperdriveConfigID = errors.New("required hyperdrive config id is missing")
ErrMissingHyperdriveConfigName = errors.New("required hyperdrive config name is missing")
ErrMissingHyperdriveConfigOriginDatabase = errors.New("required hyperdrive config origin database is missing")
ErrMissingHyperdriveConfigOriginPassword = errors.New("required hyperdrive config origin password is missing")
ErrMissingHyperdriveConfigOriginHost = errors.New("required hyperdrive config origin host is missing")
ErrMissingHyperdriveConfigOriginScheme = errors.New("required hyperdrive config origin scheme is missing")
ErrMissingHyperdriveConfigOriginUser = errors.New("required hyperdrive config origin user is missing")
)

type HyperdriveConfig struct {
Expand All @@ -24,6 +28,7 @@ type HyperdriveConfig struct {

type HyperdriveConfigOrigin struct {
Database string `json:"database,omitempty"`
Password string `json:"password"`
Host string `json:"host,omitempty"`
Port int `json:"port,omitempty"`
Scheme string `json:"scheme,omitempty"`
Expand All @@ -42,10 +47,9 @@ type HyperdriveConfigListResponse struct {
}

type CreateHyperdriveConfigParams struct {
Name string `json:"name"`
Password string `json:"password"`
Origin HyperdriveConfigOrigin `json:"origin"`
Caching HyperdriveConfigCaching `json:"caching,omitempty"`
Name string `json:"name"`
Origin HyperdriveConfigOrigin `json:"origin"`
Caching HyperdriveConfigCaching `json:"caching,omitempty"`
}

type HyperdriveConfigResponse struct {
Expand All @@ -56,7 +60,6 @@ type HyperdriveConfigResponse struct {
type UpdateHyperdriveConfigParams struct {
HyperdriveID string `json:"-"`
Name string `json:"name"`
Password string `json:"password"`
Origin HyperdriveConfigOrigin `json:"origin"`
Caching HyperdriveConfigCaching `json:"caching,omitempty"`
}
Expand Down Expand Up @@ -99,10 +102,6 @@ func (api *API) CreateHyperdriveConfig(ctx context.Context, rc *ResourceContaine
return HyperdriveConfig{}, ErrMissingHyperdriveConfigName
}

if params.Password == "" {
return HyperdriveConfig{}, ErrMissingHyperdriveConfigPassword
}

uri := fmt.Sprintf("/accounts/%s/hyperdrive/configs", rc.Identifier)

res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params)
Expand Down Expand Up @@ -178,6 +177,26 @@ func (api *API) UpdateHyperdriveConfig(ctx context.Context, rc *ResourceContaine
return HyperdriveConfig{}, ErrMissingHyperdriveConfigID
}

if params.Origin.Database == "" {
return HyperdriveConfig{}, ErrMissingHyperdriveConfigOriginDatabase
}

if params.Origin.Password == "" {
return HyperdriveConfig{}, ErrMissingHyperdriveConfigOriginPassword
}

if params.Origin.Host == "" {
return HyperdriveConfig{}, ErrMissingHyperdriveConfigOriginHost
}

if params.Origin.Scheme == "" {
return HyperdriveConfig{}, ErrMissingHyperdriveConfigOriginScheme
}

if params.Origin.User == "" {
return HyperdriveConfig{}, ErrMissingHyperdriveConfigOriginUser
}

uri := fmt.Sprintf("/accounts/%s/hyperdrive/configs/%s", rc.Identifier, params.HyperdriveID)

res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params)
Expand Down
11 changes: 3 additions & 8 deletions hyperdrive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,11 @@ func TestHyperdriveConfig_Create(t *testing.T) {
assert.Equal(t, ErrMissingHyperdriveConfigName, err)
}

_, err = client.CreateHyperdriveConfig(context.Background(), AccountIdentifier(testAccountID), CreateHyperdriveConfigParams{Name: "example-hyperdrive"})
if assert.Error(t, err) {
assert.Equal(t, ErrMissingHyperdriveConfigPassword, err)
}

result, err := client.CreateHyperdriveConfig(context.Background(), AccountIdentifier(testAccountID), CreateHyperdriveConfigParams{
Name: "example-hyperdrive",
Password: "password",
Name: "example-hyperdrive",
Origin: HyperdriveConfigOrigin{
Database: "postgres",
Password: "password",
Host: "database.example.com",
Port: 5432,
Scheme: "postgres",
Expand Down Expand Up @@ -264,9 +259,9 @@ func TestHyperdriveConfig_Update(t *testing.T) {
result, err := client.UpdateHyperdriveConfig(context.Background(), AccountIdentifier(testAccountID), UpdateHyperdriveConfigParams{
HyperdriveID: "6b7efc370ea34ded8327fa20698dfe3a",
Name: "example-hyperdrive",
Password: "password",
Origin: HyperdriveConfigOrigin{
Database: "postgres",
Password: "password",
Host: "database.example.com",
Port: 5432,
Scheme: "postgres",
Expand Down
Loading