-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Vault 36295 Improve plugin mgmt ux in api and cli #30811
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
Changes from 6 commits
16780f4
0bf96d2
3cbd9d1
3ab4609
7a08810
76b9dec
a9ec8c2
814a0d1
04c9bb8
512b038
318bc9a
20b2618
d021fd1
dd91232
ee7d570
83fb091
1cce87a
76214d0
ae42f9f
5ab3c6a
40deae7
91c5446
2982aa5
ab20a4c
4b8446d
29b5d6e
4d66328
e0526ed
5796723
d4b2de6
ca63320
f0d6d25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,15 @@ func TestRegisterPlugin(t *testing.T) { | |
t.Fatal(err) | ||
} | ||
|
||
err = client.Sys().RegisterPluginWithContext(context.Background(), &RegisterPluginInput{ | ||
resp, err := client.Sys().RegisterPluginWithContext(context.Background(), &RegisterPluginInput{ | ||
Version: "v1.0.0", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if len(resp.Warnings) > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: any chance we could check the Warnings here using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a bit of trouble with this, namely needing to differentiate when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case where we don't expect a warning, we should not assert the value. Maybe I am misunderstanding. Is the suggestion to test the non-happy path? |
||
t.Errorf("expected no warnings, got: %v", resp.Warnings) | ||
} | ||
} | ||
|
||
func TestListPlugins(t *testing.T) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,14 +91,18 @@ func TestPluginDeregisterCommand_Run(t *testing.T) { | |
ui, cmd := testPluginDeregisterCommand(t) | ||
cmd.client = client | ||
|
||
if err := client.Sys().RegisterPlugin(&api.RegisterPluginInput{ | ||
registerResp, err := client.Sys().RegisterPlugin(&api.RegisterPluginInput{ | ||
Name: pluginName, | ||
Type: api.PluginTypeCredential, | ||
Command: pluginName, | ||
SHA256: sha256Sum, | ||
}); err != nil { | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if len(registerResp.Warnings) > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: similar comment as above about testing the equality rather than the length of Warnings. Testing both is fine however. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above #30811 (comment) |
||
t.Errorf("expected no warnings, got %q", registerResp.Warnings) | ||
} | ||
|
||
code := cmd.Run([]string{ | ||
consts.PluginTypeCredential.String(), | ||
|
@@ -114,23 +118,23 @@ func TestPluginDeregisterCommand_Run(t *testing.T) { | |
t.Errorf("expected %q to contain %q", combined, expected) | ||
} | ||
|
||
resp, err := client.Sys().ListPlugins(&api.ListPluginsInput{ | ||
listResp, err := client.Sys().ListPlugins(&api.ListPluginsInput{ | ||
Type: api.PluginTypeCredential, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
found := false | ||
for _, plugins := range resp.PluginsByType { | ||
for _, plugins := range listResp.PluginsByType { | ||
for _, p := range plugins { | ||
if p == pluginName { | ||
found = true | ||
} | ||
} | ||
} | ||
if found { | ||
t.Errorf("expected %q to not be in %q", pluginName, resp.PluginsByType) | ||
t.Errorf("expected %q to not be in %q", pluginName, listResp.PluginsByType) | ||
} | ||
}) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -553,8 +553,16 @@ func (b *SystemBackend) handlePluginCatalogUpdate(ctx context.Context, _ *logica | |
|
||
command := d.Get("command").(string) | ||
ociImage := d.Get("oci_image").(string) | ||
if command == "" && ociImage == "" { | ||
return logical.ErrorResponse("must provide at least one of command or oci_image"), nil | ||
var resp logical.Response | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @benashz @thyton When testing this PR locally since the plugin download work was merged, there's some behavioral changes compared to my testing prior to the plugin download work. Namely this command validation was added in the plugin catalog set function and now fails when only CLI$ vault plugin register -version=0.24.1 auth vault-plugin-auth-jwt
Error registering plugin vault-plugin-auth-jwt: Error making API request.
URL: PUT http://127.0.0.1:8200/v1/sys/plugins/catalog/auth/vault-plugin-auth-jwt
Code: 500. Errors:
* 1 error occurred:
* must specify command to register plugin API$ curl --header 'X-Vault-Token: root' --request POST --data @data-register-jwt.json http://127.0.0.1:8200/v1/sys/plugins/catalog/auth/vault-plugin-auth-jwt
{"errors":["1 error occurred:\n\t* must specify command to register plugin\n\n"]} I'm not quite sure exactly what changed the behavior and still working to pinpoint it (i.e. we now send empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 2982aa5 to limit the The alternative is to stop requiring We should likely refactor this when we get to TODO 1 on Thanks @thyton for pairing! |
||
|
||
if sha256 == "" { | ||
helenfufu marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally these parameter constraints would be handled by the Vault server API. The vault client could just pass in everything that it got from the command line to Vault and the Vault server would do the parameter checks, returning any errors to the vault client. This is not a blocker, but something to consider for the future, especially since the Vault client may be connecting to some version of Vault that does support plugin artifacts, etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack for the future, thanks for the input. There might be a misunderstanding on my side: I thought |
||
if command != "" { | ||
resp.AddWarning(fmt.Sprintf("When sha256 is unspecified, a plugin artifact is expected for registration and the command parameter %q will be ignored.", command)) | ||
} | ||
} else { | ||
if command == "" && ociImage == "" { | ||
return logical.ErrorResponse("must provide at least one of command or oci_image"), nil | ||
} | ||
} | ||
|
||
if ociImage == "" { | ||
|
@@ -619,7 +627,7 @@ func (b *SystemBackend) handlePluginCatalogUpdate(ctx context.Context, _ *logica | |
return nil, err | ||
} | ||
|
||
return nil, nil | ||
return &resp, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this change the response code of this API when there are no warnings? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm good call. In I supposed to preserve the existing code, we could do something like the following?: if len(resp.Warnings) == 0 {
return nil, nil
}
return &resp, nil Wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is a common pattern in vault. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! ae42f9f There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The commit above caused some tests to fail (https://github.com/hashicorp/vault/actions/runs/15856157544/job/44701993144). Traced it back to this |
||
} | ||
|
||
func (b *SystemBackend) handlePluginCatalogRead(ctx context.Context, _ *logical.Request, d *framework.FieldData) (*logical.Response, error) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.