Skip to content

Commit

Permalink
backport of commit ac9f411 (#23259)
Browse files Browse the repository at this point in the history
Co-authored-by: Thy Ton <[email protected]>
  • Loading branch information
hc-github-team-secure-vault-core and thyton authored Sep 22, 2023
1 parent 20af1eb commit 9e00b34
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
17 changes: 15 additions & 2 deletions vault/logical_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,22 @@ func (b *SystemBackend) handlePluginRuntimeCatalogRead(ctx context.Context, _ *l
}}, nil
}

func (b *SystemBackend) handlePluginRuntimeCatalogList(ctx context.Context, _ *logical.Request, _ *framework.FieldData) (*logical.Response, error) {
func (b *SystemBackend) handlePluginRuntimeCatalogList(ctx context.Context, _ *logical.Request, d *framework.FieldData) (*logical.Response, error) {
var data []map[string]any
for _, runtimeType := range consts.PluginRuntimeTypes {

var pluginRuntimeTypes []consts.PluginRuntimeType
runtimeTypeStr := d.Get("type").(string)
if runtimeTypeStr != "" {
runtimeType, err := consts.ParsePluginRuntimeType(runtimeTypeStr)
if err != nil {
return logical.ErrorResponse(err.Error()), nil
}
pluginRuntimeTypes = []consts.PluginRuntimeType{runtimeType}
} else {
pluginRuntimeTypes = consts.PluginRuntimeTypes
}

for _, runtimeType := range pluginRuntimeTypes {
if runtimeType == consts.PluginRuntimeTypeUnsupported {
continue
}
Expand Down
7 changes: 7 additions & 0 deletions vault/logical_system_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -2243,6 +2243,13 @@ func (b *SystemBackend) pluginsRuntimesCatalogListPaths() []*framework.Path {
{
Pattern: "plugins/runtimes/catalog/?$",

Fields: map[string]*framework.FieldSchema{
"type": {
Type: framework.TypeString,
Description: strings.TrimSpace(sysHelp["plugin-runtime-catalog_type"][0]),
},
},

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: "plugins-runtimes-catalog",
OperationVerb: "list",
Expand Down
28 changes: 28 additions & 0 deletions vault/logical_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6137,6 +6137,23 @@ func TestSystemBackend_pluginRuntimeCRUD(t *testing.T) {
}
}

// List the plugin runtimes of container type
for _, op := range []logical.Operation{logical.ListOperation, logical.ReadOperation} {
req = logical.TestRequest(t, op, "plugins/runtimes/catalog")
req.Data["type"] = "container"
resp, err = b.HandleRequest(namespace.RootContext(nil), req)
if err != nil {
t.Fatalf("err: %v", err)
}

listExp := map[string]interface{}{
"runtimes": []map[string]any{readExp},
}
if !reflect.DeepEqual(resp.Data, listExp) {
t.Fatalf("got: %#v expect: %#v", resp.Data, listExp)
}
}

// Delete the plugin runtime
req = logical.TestRequest(t, logical.DeleteOperation, "plugins/runtimes/catalog/container/foo")
resp, err = b.HandleRequest(namespace.RootContext(nil), req)
Expand Down Expand Up @@ -6176,6 +6193,17 @@ func TestSystemBackend_pluginRuntimeCRUD(t *testing.T) {
if !reflect.DeepEqual(resp.Data, listExp) {
t.Fatalf("got: %#v expect: %#v", resp.Data, listExp)
}

// List the plugin runtimes of container type
req = logical.TestRequest(t, logical.ListOperation, "plugins/runtimes/catalog")
req.Data["type"] = "container"
if err != nil {
t.Fatalf("err: %v", err)
}

if !reflect.DeepEqual(resp.Data, listExp) {
t.Fatalf("got: %#v expect: %#v", resp.Data, listExp)
}
}

func TestGetSealBackendStatus(t *testing.T) {
Expand Down

0 comments on commit 9e00b34

Please sign in to comment.