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

This commit is contained in:
Tom Proctor
2024-01-16 16:36:07 +00:00
committed by GitHub
parent d9f0587705
commit f393241bb2
4 changed files with 17 additions and 16 deletions

3
changelog/24864.txt Normal file
View File

@@ -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.
```

View File

@@ -46,14 +46,14 @@ func TestPluginRuntimeListCommand_Run(t *testing.T) {
{ {
"list container on empty plugin runtime catalog", "list container on empty plugin runtime catalog",
[]string{"-type=container"}, []string{"-type=container"},
"Error listing available plugin runtimes:", "OCI Runtime",
2, 0,
}, },
{ {
"list on empty plugin runtime catalog", "list on empty plugin runtime catalog",
nil, nil,
"Error listing available plugin runtimes:", "OCI Runtime",
2, 0,
}, },
} }

View File

@@ -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) { 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 var pluginRuntimeTypes []consts.PluginRuntimeType
runtimeTypeStr := d.Get("type").(string) 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 return strings.Compare(configs[i].Name, configs[j].Name) == -1
}) })
for _, conf := range configs { for _, conf := range configs {
data = append(data, map[string]any{ runtimes = append(runtimes, map[string]any{
"name": conf.Name, "name": conf.Name,
"type": conf.Type.String(), "type": conf.Type.String(),
"oci_runtime": conf.OCIRuntime, "oci_runtime": conf.OCIRuntime,
@@ -929,15 +929,11 @@ func (b *SystemBackend) handlePluginRuntimeCatalogList(ctx context.Context, _ *l
} }
} }
resp := &logical.Response{ return &logical.Response{
Data: map[string]interface{}{}, Data: map[string]interface{}{
} "runtimes": runtimes,
},
if len(data) > 0 { }, nil
resp.Data["runtimes"] = data
}
return resp, nil
} }
// handleAuditedHeaderUpdate creates or overwrites a header entry // handleAuditedHeaderUpdate creates or overwrites a header entry

View File

@@ -6164,7 +6164,9 @@ func TestSystemBackend_pluginRuntimeCRUD(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
listExp := map[string]interface{}{} listExp := map[string]any{
"runtimes": []map[string]any{},
}
if !reflect.DeepEqual(resp.Data, listExp) { if !reflect.DeepEqual(resp.Data, listExp) {
t.Fatalf("got: %#v expect: %#v", resp.Data, listExp) t.Fatalf("got: %#v expect: %#v", resp.Data, listExp)
} }