From 067bef409425696861b222e2f3598434dcd55071 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Wed, 7 Jun 2017 00:27:57 -0400 Subject: [PATCH] Add listing to database connections. Fixes #2823 --- builtin/logical/database/backend.go | 1 + builtin/logical/database/backend_test.go | 13 ++++++++++ .../database/path_config_connection.go | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/builtin/logical/database/backend.go b/builtin/logical/database/backend.go index 91b92e438ae5..af76f9978a94 100644 --- a/builtin/logical/database/backend.go +++ b/builtin/logical/database/backend.go @@ -25,6 +25,7 @@ func Backend(conf *logical.BackendConfig) *databaseBackend { Help: strings.TrimSpace(backendHelp), Paths: []*framework.Path{ + pathListPluginConnection(&b), pathConfigurePluginConnection(&b), pathListRoles(&b), pathRoles(&b), diff --git a/builtin/logical/database/backend_test.go b/builtin/logical/database/backend_test.go index 27c20d33258e..4ad1c0b8c80a 100644 --- a/builtin/logical/database/backend_test.go +++ b/builtin/logical/database/backend_test.go @@ -185,6 +185,19 @@ func TestBackend_config_connection(t *testing.T) { if !reflect.DeepEqual(expected, resp.Data) { t.Fatalf("bad: expected:%#v\nactual:%#v\n", expected, resp.Data) } + + configReq.Operation = logical.ListOperation + configReq.Data = nil + configReq.Path = "config/" + resp, err = b.HandleRequest(configReq) + if err != nil { + t.Fatal(err) + } + keys := resp.Data["keys"].([]string) + key := keys[0] + if key != "plugin-test" { + t.Fatalf("bad key: %q", key) + } } func TestBackend_basic(t *testing.T) { diff --git a/builtin/logical/database/path_config_connection.go b/builtin/logical/database/path_config_connection.go index e84212bb89a8..d1e6cb2923fc 100644 --- a/builtin/logical/database/path_config_connection.go +++ b/builtin/logical/database/path_config_connection.go @@ -115,6 +115,30 @@ func pathConfigurePluginConnection(b *databaseBackend) *framework.Path { } } +func pathListPluginConnection(b *databaseBackend) *framework.Path { + return &framework.Path{ + Pattern: fmt.Sprintf("config/?$"), + + Callbacks: map[logical.Operation]framework.OperationFunc{ + logical.ListOperation: b.connectionListHandler(), + }, + + HelpSynopsis: pathConfigConnectionHelpSyn, + HelpDescription: pathConfigConnectionHelpDesc, + } +} + +func (b *databaseBackend) connectionListHandler() framework.OperationFunc { + return func(req *logical.Request, data *framework.FieldData) (*logical.Response, error) { + entries, err := req.Storage.List("config/") + if err != nil { + return nil, err + } + + return logical.ListResponse(entries), nil + } +} + // connectionReadHandler reads out the connection configuration func (b *databaseBackend) connectionReadHandler() framework.OperationFunc { return func(req *logical.Request, data *framework.FieldData) (*logical.Response, error) {