Skip to content

Commit 4882cd7

Browse files
authored
Default the IAM endpoint on config read (#20)
Default the endpoint on configuration reads so the current plugin will work with configurations stored by v0.1.0.
1 parent 04bfc90 commit 4882cd7

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

path_config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ func (b *ibmCloudSecretBackend) pathConfigRead(ctx context.Context, req *logical
132132
displayKey = redacted
133133
}
134134

135+
if config.IAMEndpoint == "" {
136+
config.IAMEndpoint = iamEndpointFieldDefault
137+
}
138+
135139
resp := &logical.Response{
136140
Data: map[string]interface{}{
137141
apiKeyField: displayKey,
@@ -165,6 +169,9 @@ func (b *ibmCloudSecretBackend) getConfig(ctx context.Context, s logical.Storage
165169
if config.Account == "" {
166170
return nil, logical.ErrorResponse("no account ID was set in the configuration")
167171
}
172+
if config.IAMEndpoint == "" {
173+
config.IAMEndpoint = iamEndpointFieldDefault
174+
}
168175

169176
return config, nil
170177
}

path_config_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,36 @@ func testConfigCreate(t *testing.T, b *ibmCloudSecretBackend, s logical.Storage,
148148
}
149149
return nil
150150
}
151+
152+
func TestLoadOfPreviousConfig(t *testing.T) {
153+
b, s := testBackend(t)
154+
155+
// set config without endpoint default set, mimicking a v0.1.0 config
156+
config, err := b.config(context.Background(), s)
157+
if err != nil {
158+
t.Fatal(err)
159+
}
160+
if config == nil {
161+
config = new(ibmCloudConfig)
162+
}
163+
config.APIKey = "key"
164+
config.Account = "account"
165+
166+
entry, err := logical.StorageEntryJSON("config", config)
167+
if err != nil {
168+
t.Fatal(err)
169+
}
170+
if err := s.Put(context.Background(), entry); err != nil {
171+
t.Fatal(err)
172+
}
173+
174+
// Load the config and verify the endpoints are defaulted
175+
newConfig, resp := b.getConfig(context.Background(), s)
176+
if resp != nil {
177+
t.Fatal(resp.Error())
178+
}
179+
180+
if newConfig.IAMEndpoint != iamEndpointFieldDefault {
181+
t.Fatalf("The config's IAM Endpoint was not defaulted correctly on the load of a previous version config")
182+
}
183+
}

0 commit comments

Comments
 (0)