Skip to content

Commit 7e48bb1

Browse files
Vault: detailed errors for remaining paths (#115)
Vault: detailed errors for remaining paths Remaining error messages updated for: path_creds.go path_static_creds.go path_rotate_root.go path_static_role.go Acceptance tests vault-plugin-secrets-openstack % make functional Running acceptance tests... === RUN TestPlugin === RUN TestPlugin/TestCloudLifecycle === RUN TestPlugin/TestCloudLifecycle/WriteCloud === RUN TestPlugin/TestCloudLifecycle/ReadCloud === RUN TestPlugin/TestCloudLifecycle/ListClouds === RUN TestPlugin/TestCloudLifecycle/ListClouds/method-LIST === PAUSE TestPlugin/TestCloudLifecycle/ListClouds/method-LIST === RUN TestPlugin/TestCloudLifecycle/ListClouds/method-GET === PAUSE TestPlugin/TestCloudLifecycle/ListClouds/method-GET === CONT TestPlugin/TestCloudLifecycle/ListClouds/method-LIST === CONT TestPlugin/TestCloudLifecycle/ListClouds/method-GET === RUN TestPlugin/TestCloudLifecycle/DeleteCloud === RUN TestPlugin/TestCredsLifecycle === RUN TestPlugin/TestCredsLifecycle/root_token === RUN TestPlugin/TestCredsLifecycle/user_token === RUN TestPlugin/TestCredsLifecycle/user_password === RUN TestPlugin/TestInfo info_test.go:42: Error Trace: info_test.go:42 Error: Should NOT be empty, but was &{ } Test: TestPlugin/TestInfo === RUN TestPlugin/TestRoleLifecycle === RUN TestPlugin/TestRoleLifecycle/WriteRole === RUN TestPlugin/TestRoleLifecycle/ReadRole === RUN TestPlugin/TestRoleLifecycle/ListRoles === RUN TestPlugin/TestRoleLifecycle/ListRoles/method-LIST === PAUSE TestPlugin/TestRoleLifecycle/ListRoles/method-LIST === RUN TestPlugin/TestRoleLifecycle/ListRoles/method-GET === PAUSE TestPlugin/TestRoleLifecycle/ListRoles/method-GET === CONT TestPlugin/TestRoleLifecycle/ListRoles/method-LIST === CONT TestPlugin/TestRoleLifecycle/ListRoles/method-GET === RUN TestPlugin/TestRoleLifecycle/DeleteRole === RUN TestPlugin/TestRootRotate rotate_test.go:65: Cloud with name default1 was created rotate_test.go:68: Cloud with name rc1k was created plugin_test.go:337: Cloud with name rc1k has been removed plugin_test.go:337: Cloud with name default1 has been removed === RUN TestPlugin/TestStaticCredsLifecycle === RUN TestPlugin/TestStaticCredsLifecycle/user_password === RUN TestPlugin/TestStaticCredsLifecycle/user_token_project_id === RUN TestPlugin/TestStaticCredsLifecycle/user_token_project_name === RUN TestPlugin/TestStaticRoleLifecycle === RUN TestPlugin/TestStaticRoleLifecycle/WriteRole === RUN TestPlugin/TestStaticRoleLifecycle/ReadRole === RUN TestPlugin/TestStaticRoleLifecycle/ListRoles === RUN TestPlugin/TestStaticRoleLifecycle/ListRoles/method-LIST === PAUSE TestPlugin/TestStaticRoleLifecycle/ListRoles/method-LIST === RUN TestPlugin/TestStaticRoleLifecycle/ListRoles/method-GET === PAUSE TestPlugin/TestStaticRoleLifecycle/ListRoles/method-GET === CONT TestPlugin/TestStaticRoleLifecycle/ListRoles/method-LIST === CONT TestPlugin/TestStaticRoleLifecycle/ListRoles/method-GET === RUN TestPlugin/TestStaticRoleLifecycle/DeleteRole --- FAIL: TestPlugin (26.68s) --- PASS: TestPlugin/TestCloudLifecycle (0.09s) --- PASS: TestPlugin/TestCloudLifecycle/WriteCloud (0.09s) --- PASS: TestPlugin/TestCloudLifecycle/ReadCloud (0.00s) --- PASS: TestPlugin/TestCloudLifecycle/ListClouds (0.00s) --- PASS: TestPlugin/TestCloudLifecycle/ListClouds/method-LIST (0.00s) --- PASS: TestPlugin/TestCloudLifecycle/ListClouds/method-GET (0.00s) --- PASS: TestPlugin/TestCloudLifecycle/DeleteCloud (0.00s) --- PASS: TestPlugin/TestCredsLifecycle (5.86s) --- PASS: TestPlugin/TestCredsLifecycle/root_token (1.61s) --- PASS: TestPlugin/TestCredsLifecycle/user_token (2.19s) --- PASS: TestPlugin/TestCredsLifecycle/user_password (1.06s) --- FAIL: TestPlugin/TestInfo (0.01s) --- PASS: TestPlugin/TestRoleLifecycle (0.63s) --- PASS: TestPlugin/TestRoleLifecycle/WriteRole (0.61s) --- PASS: TestPlugin/TestRoleLifecycle/ReadRole (0.00s) --- PASS: TestPlugin/TestRoleLifecycle/ListRoles (0.00s) --- PASS: TestPlugin/TestRoleLifecycle/ListRoles/method-LIST (0.01s) --- PASS: TestPlugin/TestRoleLifecycle/ListRoles/method-GET (0.01s) --- PASS: TestPlugin/TestRoleLifecycle/DeleteRole (0.00s) --- PASS: TestPlugin/TestRootRotate (4.76s) --- PASS: TestPlugin/TestStaticCredsLifecycle (12.35s) --- PASS: TestPlugin/TestStaticCredsLifecycle/user_password (3.39s) --- PASS: TestPlugin/TestStaticCredsLifecycle/user_token_project_id (3.90s) --- PASS: TestPlugin/TestStaticCredsLifecycle/user_token_project_name (3.97s) --- PASS: TestPlugin/TestStaticRoleLifecycle (2.81s) --- PASS: TestPlugin/TestStaticRoleLifecycle/WriteRole (1.09s) --- PASS: TestPlugin/TestStaticRoleLifecycle/ReadRole (0.01s) --- PASS: TestPlugin/TestStaticRoleLifecycle/ListRoles (0.00s) --- PASS: TestPlugin/TestStaticRoleLifecycle/ListRoles/method-GET (0.00s) --- PASS: TestPlugin/TestStaticRoleLifecycle/ListRoles/method-LIST (0.00s) --- PASS: TestPlugin/TestStaticRoleLifecycle/DeleteRole (0.00s) FAIL FAIL github.com/opentelekomcloud/vault-plugin-secrets-openstack/acceptance 27.274s FAIL make: *** [functional] Error 1 Reviewed-by: Aloento Reviewed-by: Anton Sidelnikov
1 parent 13da509 commit 7e48bb1

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

openstack/path_creds.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func (b *backend) tokenRevoke(ctx context.Context, r *logical.Request, d *framew
277277
sharedCloud := b.getSharedCloud(cloudName)
278278
client, err := sharedCloud.getClient(ctx, r.Storage)
279279
if err != nil {
280-
return nil, err
280+
return nil, logical.CodedError(http.StatusConflict, common.LogHttpError(err).Error())
281281
}
282282

283283
err = tokens.Revoke(client, token).Err
@@ -306,7 +306,7 @@ func (b *backend) userDelete(ctx context.Context, r *logical.Request, _ *framewo
306306
sharedCloud := b.getSharedCloud(cloudName)
307307
client, err := sharedCloud.getClient(ctx, r.Storage)
308308
if err != nil {
309-
return nil, err
309+
return nil, logical.CodedError(http.StatusConflict, common.LogHttpError(err).Error())
310310
}
311311

312312
err = users.Delete(client, userID).ExtractErr()

openstack/path_rotate_root.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package openstack
33
import (
44
"context"
55
"fmt"
6+
"github.com/opentelekomcloud/vault-plugin-secrets-openstack/openstack/common"
7+
"github.com/opentelekomcloud/vault-plugin-secrets-openstack/vars"
8+
9+
"net/http"
610

711
"github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
812
"github.com/gophercloud/gophercloud/openstack/identity/v3/users"
@@ -52,16 +56,16 @@ func (b *backend) rotateRootCredentials(ctx context.Context, req *logical.Reques
5256
sharedCloud := b.getSharedCloud(cloudName)
5357
client, err := sharedCloud.getClient(ctx, req.Storage)
5458
if err != nil {
55-
return nil, err
59+
return nil, logical.CodedError(http.StatusConflict, common.LogHttpError(err).Error())
5660
}
5761
user, err := tokens.Get(client, client.Token()).ExtractUser()
5862
if err != nil {
59-
return nil, err
63+
return nil, logical.CodedError(http.StatusConflict, common.LogHttpError(err).Error())
6064
}
6165

6266
cloudConfig, err := sharedCloud.getCloudConfig(ctx, req.Storage)
6367
if err != nil {
64-
return nil, err
68+
return nil, fmt.Errorf(vars.ErrCloudConf)
6569
}
6670

6771
newPassword, err := sharedCloud.passwords.Generate(ctx)
@@ -78,7 +82,8 @@ func (b *backend) rotateRootCredentials(ctx context.Context, req *logical.Reques
7882
OriginalPassword: cloudConfig.Password,
7983
}).ExtractErr()
8084
if err != nil {
81-
return nil, err
85+
errorMessage := fmt.Sprintf("error changing root password: %s", common.LogHttpError(err).Error())
86+
return nil, logical.CodedError(http.StatusConflict, errorMessage)
8287
}
8388
cloudConfig.Password = newPassword
8489

openstack/path_static_creds.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"github.com/gophercloud/gophercloud/openstack/identity/v3/users"
88
"github.com/hashicorp/vault/sdk/framework"
99
"github.com/hashicorp/vault/sdk/logical"
10+
"github.com/opentelekomcloud/vault-plugin-secrets-openstack/openstack/common"
11+
"github.com/opentelekomcloud/vault-plugin-secrets-openstack/vars"
12+
"net/http"
1013
)
1114

1215
const (
@@ -79,17 +82,18 @@ func (b *backend) pathStaticCredsRead(ctx context.Context, r *logical.Request, d
7982
sharedCloud := b.getSharedCloud(role.Cloud)
8083
cloudConfig, err := sharedCloud.getCloudConfig(ctx, r.Storage)
8184
if err != nil {
82-
return nil, err
85+
return nil, fmt.Errorf(vars.ErrCloudConf)
8386
}
8487

8588
client, err := sharedCloud.getClient(ctx, r.Storage)
8689
if err != nil {
87-
return nil, err
90+
return nil, logical.CodedError(http.StatusConflict, common.LogHttpError(err).Error())
8891
}
8992

9093
user, err := users.Get(client, role.UserID).Extract()
9194
if err != nil {
92-
return nil, err
95+
errorMessage := fmt.Sprintf("error querying static user: %s", common.LogHttpError(err).Error())
96+
return nil, logical.CodedError(http.StatusConflict, errorMessage)
9397
}
9498

9599
var data map[string]interface{}
@@ -162,7 +166,7 @@ func (b *backend) rotateStaticCreds(ctx context.Context, r *logical.Request, d *
162166

163167
client, err := sharedCloud.getClient(ctx, r.Storage)
164168
if err != nil {
165-
return nil, err
169+
return nil, logical.CodedError(http.StatusConflict, common.LogHttpError(err).Error())
166170
}
167171

168172
newPassword, err := Passwords{}.Generate(ctx)
@@ -172,7 +176,8 @@ func (b *backend) rotateStaticCreds(ctx context.Context, r *logical.Request, d *
172176

173177
_, err = users.Update(client, role.UserID, users.UpdateOpts{Password: newPassword}).Extract()
174178
if err != nil {
175-
return nil, fmt.Errorf("error rotating user password for user `%s`: %s", role.Username, err)
179+
errorMessage := fmt.Sprintf("error rotating user password for user `%s`: %s", role.Username, common.LogHttpError(err))
180+
return nil, logical.CodedError(http.StatusConflict, errorMessage)
176181
}
177182

178183
role.Secret = newPassword
@@ -256,7 +261,7 @@ func (b *backend) rotateUserPassword(ctx context.Context, req *logical.Request,
256261
var userId string
257262
client, err := cloud.getClient(ctx, req.Storage)
258263
if err != nil {
259-
return userId, err
264+
return userId, common.LogHttpError(err)
260265
}
261266
opts := users.ListOpts{Name: user}
262267
allPages, err := users.List(client, opts).AllPages()
@@ -279,7 +284,7 @@ func (b *backend) rotateUserPassword(ctx context.Context, req *logical.Request,
279284

280285
_, err = users.Update(client, userId, users.UpdateOpts{Password: password}).Extract()
281286
if err != nil {
282-
return userId, fmt.Errorf("error rotating user password for user `%s`: %s", user, err)
287+
return userId, fmt.Errorf("error rotating user password for user `%s`: %s", user, common.LogHttpError(err))
283288
}
284289
return userId, nil
285290
}

openstack/path_static_role.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package openstack
33
import (
44
"context"
55
"fmt"
6+
"github.com/opentelekomcloud/vault-plugin-secrets-openstack/vars"
67
"time"
78

89
"github.com/hashicorp/vault/sdk/framework"
@@ -232,7 +233,7 @@ func (b *backend) pathStaticRoleUpdate(ctx context.Context, req *logical.Request
232233
cloud := b.getSharedCloud(cloudName)
233234
cloudConfig, err := cloud.getCloudConfig(ctx, req.Storage)
234235
if err != nil {
235-
return nil, err
236+
return nil, fmt.Errorf(vars.ErrCloudConf)
236237
}
237238
if cloudConfig == nil {
238239
return logical.ErrorResponse("cloud `%s` doesn't exist", cloudName), nil

0 commit comments

Comments
 (0)