Skip to content

Commit

Permalink
Default the IAM endpoint on config read (#20)
Browse files Browse the repository at this point in the history
Default the endpoint on configuration reads
so the current plugin will work with configurations
stored by v0.1.0.
  • Loading branch information
smatzek authored May 2, 2022
1 parent 04bfc90 commit 4882cd7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions path_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func (b *ibmCloudSecretBackend) pathConfigRead(ctx context.Context, req *logical
displayKey = redacted
}

if config.IAMEndpoint == "" {
config.IAMEndpoint = iamEndpointFieldDefault
}

resp := &logical.Response{
Data: map[string]interface{}{
apiKeyField: displayKey,
Expand Down Expand Up @@ -165,6 +169,9 @@ func (b *ibmCloudSecretBackend) getConfig(ctx context.Context, s logical.Storage
if config.Account == "" {
return nil, logical.ErrorResponse("no account ID was set in the configuration")
}
if config.IAMEndpoint == "" {
config.IAMEndpoint = iamEndpointFieldDefault
}

return config, nil
}
Expand Down
33 changes: 33 additions & 0 deletions path_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,36 @@ func testConfigCreate(t *testing.T, b *ibmCloudSecretBackend, s logical.Storage,
}
return nil
}

func TestLoadOfPreviousConfig(t *testing.T) {
b, s := testBackend(t)

// set config without endpoint default set, mimicking a v0.1.0 config
config, err := b.config(context.Background(), s)
if err != nil {
t.Fatal(err)
}
if config == nil {
config = new(ibmCloudConfig)
}
config.APIKey = "key"
config.Account = "account"

entry, err := logical.StorageEntryJSON("config", config)
if err != nil {
t.Fatal(err)
}
if err := s.Put(context.Background(), entry); err != nil {
t.Fatal(err)
}

// Load the config and verify the endpoints are defaulted
newConfig, resp := b.getConfig(context.Background(), s)
if resp != nil {
t.Fatal(resp.Error())
}

if newConfig.IAMEndpoint != iamEndpointFieldDefault {
t.Fatalf("The config's IAM Endpoint was not defaulted correctly on the load of a previous version config")
}
}

0 comments on commit 4882cd7

Please sign in to comment.