From f393241bb2ade902aa3f21bf075a7c7ac11a3bc5 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Tue, 16 Jan 2024 16:36:07 +0000 Subject: [PATCH] List plugin runtimes API always includes a list even if empty (#24864) --- changelog/24864.txt | 3 +++ command/plugin_runtime_list_test.go | 8 ++++---- vault/logical_system.go | 18 +++++++----------- vault/logical_system_test.go | 4 +++- 4 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 changelog/24864.txt diff --git a/changelog/24864.txt b/changelog/24864.txt new file mode 100644 index 0000000000..c29db4f54c --- /dev/null +++ b/changelog/24864.txt @@ -0,0 +1,3 @@ +```release-note:change +plugins: `/sys/plugins/runtimes/catalog` response will always include a list of "runtimes" in the response, even if empty. +``` diff --git a/command/plugin_runtime_list_test.go b/command/plugin_runtime_list_test.go index cd67ece564..8f8d209ca4 100644 --- a/command/plugin_runtime_list_test.go +++ b/command/plugin_runtime_list_test.go @@ -46,14 +46,14 @@ func TestPluginRuntimeListCommand_Run(t *testing.T) { { "list container on empty plugin runtime catalog", []string{"-type=container"}, - "Error listing available plugin runtimes:", - 2, + "OCI Runtime", + 0, }, { "list on empty plugin runtime catalog", nil, - "Error listing available plugin runtimes:", - 2, + "OCI Runtime", + 0, }, } diff --git a/vault/logical_system.go b/vault/logical_system.go index 6215954850..093ab3a95f 100644 --- a/vault/logical_system.go +++ b/vault/logical_system.go @@ -888,7 +888,7 @@ func (b *SystemBackend) handlePluginRuntimeCatalogRead(ctx context.Context, _ *l } func (b *SystemBackend) handlePluginRuntimeCatalogList(ctx context.Context, _ *logical.Request, d *framework.FieldData) (*logical.Response, error) { - var data []map[string]any + runtimes := []map[string]any{} var pluginRuntimeTypes []consts.PluginRuntimeType runtimeTypeStr := d.Get("type").(string) @@ -916,7 +916,7 @@ func (b *SystemBackend) handlePluginRuntimeCatalogList(ctx context.Context, _ *l return strings.Compare(configs[i].Name, configs[j].Name) == -1 }) for _, conf := range configs { - data = append(data, map[string]any{ + runtimes = append(runtimes, map[string]any{ "name": conf.Name, "type": conf.Type.String(), "oci_runtime": conf.OCIRuntime, @@ -929,15 +929,11 @@ func (b *SystemBackend) handlePluginRuntimeCatalogList(ctx context.Context, _ *l } } - resp := &logical.Response{ - Data: map[string]interface{}{}, - } - - if len(data) > 0 { - resp.Data["runtimes"] = data - } - - return resp, nil + return &logical.Response{ + Data: map[string]interface{}{ + "runtimes": runtimes, + }, + }, nil } // handleAuditedHeaderUpdate creates or overwrites a header entry diff --git a/vault/logical_system_test.go b/vault/logical_system_test.go index 3f9ead9a95..2981c758d3 100644 --- a/vault/logical_system_test.go +++ b/vault/logical_system_test.go @@ -6164,7 +6164,9 @@ func TestSystemBackend_pluginRuntimeCRUD(t *testing.T) { t.Fatalf("err: %v", err) } - listExp := map[string]interface{}{} + listExp := map[string]any{ + "runtimes": []map[string]any{}, + } if !reflect.DeepEqual(resp.Data, listExp) { t.Fatalf("got: %#v expect: %#v", resp.Data, listExp) }