Skip to content

Commit

Permalink
Add listing to database connections. (#2827)
Browse files Browse the repository at this point in the history
Fixes #2823
  • Loading branch information
jefferai authored Jun 7, 2017
1 parent 25fd17a commit 2daf018
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin/logical/database/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 13 additions & 0 deletions builtin/logical/database/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 24 additions & 0 deletions builtin/logical/database/path_config_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2daf018

Please sign in to comment.