Skip to content

Commit

Permalink
Add mount UUID to the secret and auth list API responses (#6633)
Browse files Browse the repository at this point in the history
  • Loading branch information
briankassouf authored Apr 24, 2019
1 parent e25a8a1 commit f6270ba
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 6 deletions.
1 change: 1 addition & 0 deletions api/sys_mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ type MountConfigInput struct {
}

type MountOutput struct {
UUID string `json:"uuid"`
Type string `json:"type"`
Description string `json:"description"`
Accessor string `json:"accessor"`
Expand Down
5 changes: 3 additions & 2 deletions command/auth_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *AuthListCommand) detailedMounts(auths map[string]*api.AuthMount) []stri
}
}

out := []string{"Path | Plugin | Accessor | Default TTL | Max TTL | Token Type | Replication | Seal Wrap | Options | Description"}
out := []string{"Path | Plugin | Accessor | Default TTL | Max TTL | Token Type | Replication | Seal Wrap | Options | Description | UUID"}
for _, path := range paths {
mount := auths[path]

Expand All @@ -160,7 +160,7 @@ func (c *AuthListCommand) detailedMounts(auths map[string]*api.AuthMount) []stri
pluginName = mount.Config.PluginName
}

out = append(out, fmt.Sprintf("%s | %s | %s | %s | %s | %s | %s | %t | %v | %s",
out = append(out, fmt.Sprintf("%s | %s | %s | %s | %s | %s | %s | %t | %v | %s | %s",
path,
pluginName,
mount.Accessor,
Expand All @@ -171,6 +171,7 @@ func (c *AuthListCommand) detailedMounts(auths map[string]*api.AuthMount) []stri
mount.SealWrap,
mount.Options,
mount.Description,
mount.UUID,
))
}

Expand Down
5 changes: 3 additions & 2 deletions command/secrets_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *SecretsListCommand) detailedMounts(mounts map[string]*api.MountOutput)
}
}

out := []string{"Path | Plugin | Accessor | Default TTL | Max TTL | Force No Cache | Replication | Seal Wrap | Options | Description"}
out := []string{"Path | Plugin | Accessor | Default TTL | Max TTL | Force No Cache | Replication | Seal Wrap | Options | Description | UUID "}
for _, path := range paths {
mount := mounts[path]

Expand All @@ -160,7 +160,7 @@ func (c *SecretsListCommand) detailedMounts(mounts map[string]*api.MountOutput)
pluginName = mount.Config.PluginName
}

out = append(out, fmt.Sprintf("%s | %s | %s | %s | %s | %t | %s | %t | %v | %s",
out = append(out, fmt.Sprintf("%s | %s | %s | %s | %s | %t | %s | %t | %v | %s | %s",
path,
pluginName,
mount.Accessor,
Expand All @@ -171,6 +171,7 @@ func (c *SecretsListCommand) detailedMounts(mounts map[string]*api.MountOutput)
mount.SealWrap,
mount.Options,
mount.Description,
mount.UUID,
))
}

Expand Down
9 changes: 8 additions & 1 deletion http/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"encoding/json"
"errors"
"github.com/go-test/deep"
"net/http"
"net/http/httptest"
"net/textproto"
"reflect"
"strings"
"testing"

"github.com/go-test/deep"

cleanhttp "github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/sdk/helper/consts"
Expand Down Expand Up @@ -375,8 +376,14 @@ func TestSysMounts_headerAuth(t *testing.T) {
if v.(map[string]interface{})["accessor"] == "" {
t.Fatalf("no accessor from %s", k)
}
if v.(map[string]interface{})["uuid"] == "" {
t.Fatalf("no uuid from %s", k)
}

expected[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
}

if diff := deep.Equal(actual, expected); len(diff) > 0 {
Expand Down
18 changes: 18 additions & 0 deletions http/sys_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ func TestSysAuth(t *testing.T) {
if v.(map[string]interface{})["accessor"] == "" {
t.Fatalf("no accessor from %s", k)
}
if v.(map[string]interface{})["uuid"] == "" {
t.Fatalf("no uuid from %s", k)
}

expected[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
}

if !reflect.DeepEqual(actual, expected) {
Expand Down Expand Up @@ -156,8 +162,14 @@ func TestSysEnableAuth(t *testing.T) {
if v.(map[string]interface{})["accessor"] == "" {
t.Fatalf("no accessor from %s", k)
}
if v.(map[string]interface{})["uuid"] == "" {
t.Fatalf("no uuid from %s", k)
}

expected[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
}

if diff := deep.Equal(actual, expected); diff != nil {
Expand Down Expand Up @@ -227,8 +239,14 @@ func TestSysDisableAuth(t *testing.T) {
if v.(map[string]interface{})["accessor"] == "" {
t.Fatalf("no accessor from %s", k)
}
if v.(map[string]interface{})["uuid"] == "" {
t.Fatalf("no uuid from %s", k)
}

expected[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
}

if diff := deep.Equal(actual, expected); diff != nil {
Expand Down
33 changes: 32 additions & 1 deletion http/sys_mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package http

import (
"encoding/json"
"github.com/go-test/deep"
"reflect"
"testing"

"github.com/go-test/deep"

"github.com/fatih/structs"
"github.com/hashicorp/vault/vault"
)
Expand Down Expand Up @@ -134,8 +135,13 @@ func TestSysMounts(t *testing.T) {
if v.(map[string]interface{})["accessor"] == "" {
t.Fatalf("no accessor from %s", k)
}
if v.(map[string]interface{})["uuid"] == "" {
t.Fatalf("no uuid from %s", k)
}
expected[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
}

if diff := deep.Equal(actual, expected); len(diff) > 0 {
Expand Down Expand Up @@ -300,8 +306,13 @@ func TestSysMount(t *testing.T) {
if v.(map[string]interface{})["accessor"] == "" {
t.Fatalf("no accessor from %s", k)
}
if v.(map[string]interface{})["uuid"] == "" {
t.Fatalf("no uuid from %s", k)
}
expected[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
}

if diff := deep.Equal(actual, expected); len(diff) > 0 {
Expand Down Expand Up @@ -486,8 +497,13 @@ func TestSysRemount(t *testing.T) {
if v.(map[string]interface{})["accessor"] == "" {
t.Fatalf("no accessor from %s", k)
}
if v.(map[string]interface{})["uuid"] == "" {
t.Fatalf("no uuid from %s", k)
}
expected[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
}

if !reflect.DeepEqual(actual, expected) {
Expand Down Expand Up @@ -628,8 +644,13 @@ func TestSysUnmount(t *testing.T) {
if v.(map[string]interface{})["accessor"] == "" {
t.Fatalf("no accessor from %s", k)
}
if v.(map[string]interface{})["uuid"] == "" {
t.Fatalf("no uuid from %s", k)
}
expected[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
}

if diff := deep.Equal(actual, expected); len(diff) > 0 {
Expand Down Expand Up @@ -876,8 +897,13 @@ func TestSysTuneMount(t *testing.T) {
if v.(map[string]interface{})["accessor"] == "" {
t.Fatalf("no accessor from %s", k)
}
if v.(map[string]interface{})["uuid"] == "" {
t.Fatalf("no uuid from %s", k)
}
expected[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
}

if diff := deep.Equal(actual, expected); len(diff) > 0 {
Expand Down Expand Up @@ -1069,8 +1095,13 @@ func TestSysTuneMount(t *testing.T) {
if v.(map[string]interface{})["accessor"] == "" {
t.Fatalf("no accessor from %s", k)
}
if v.(map[string]interface{})["uuid"] == "" {
t.Fatalf("no uuid from %s", k)
}
expected[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["accessor"] = v.(map[string]interface{})["accessor"]
expected["data"].(map[string]interface{})[k].(map[string]interface{})["uuid"] = v.(map[string]interface{})["uuid"]
}

if diff := deep.Equal(actual, expected); len(diff) > 0 {
Expand Down
1 change: 1 addition & 0 deletions vault/logical_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ func mountInfo(entry *MountEntry) map[string]interface{} {
"local": entry.Local,
"seal_wrap": entry.SealWrap,
"options": entry.Options,
"uuid": entry.UUID,
}
entryConfig := map[string]interface{}{
"default_lease_ttl": int64(entry.Config.DefaultLeaseTTL.Seconds()),
Expand Down
Loading

0 comments on commit f6270ba

Please sign in to comment.