Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List plugin runtimes API always includes a list even if empty #24864

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/24864.txt
Original file line number Diff line number Diff line change
@@ -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.
```
8 changes: 4 additions & 4 deletions command/plugin_runtime_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down
10 changes: 4 additions & 6 deletions vault/logical_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
data := []map[string]any{}

var pluginRuntimeTypes []consts.PluginRuntimeType
runtimeTypeStr := d.Get("type").(string)
Expand Down Expand Up @@ -930,11 +930,9 @@ func (b *SystemBackend) handlePluginRuntimeCatalogList(ctx context.Context, _ *l
}

resp := &logical.Response{
Data: map[string]interface{}{},
}

if len(data) > 0 {
resp.Data["runtimes"] = data
Data: map[string]interface{}{
"runtimes": data,
},
}

return resp, nil
Expand Down
4 changes: 3 additions & 1 deletion vault/logical_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading