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

Make the plugin catalog endpoint roundtrip so we can use terraform to manage them. #3778

Merged
merged 3 commits into from
Jan 18, 2018

Conversation

tomwilkie
Copy link
Contributor

Fixes #3776

You can now do:

$ cat plugin.json 
{
  "args": [
    "--ca-cert=/etc/vault/ca.pem",
    "--client-cert=/etc/vault/cert.pem",
    "--client-key=/etc/vault/key.pem"
  ],
  "command": "google-auth-vault-plugin",
  "name": "google-auth-vault-plugin",
  "sha256": "989845e5a0171d9e1b1c6d9ca13393dd031fd9068c200c52ec723737ed450d4d"
}
$ vault  write sys/plugins/catalog/google-auth-vault-plugin @plugin.json
Success! Data written to: sys/plugins/catalog/google-auth-vault-plugin
$ vault read --format json sys/plugins/catalog/google-auth-vault-plugin
{
	"request_id": "d61b86d4-f5c6-7334-3848-be4c8730f0b1",
	"lease_id": "",
	"lease_duration": 0,
	"renewable": false,
	"data": {
		"args": [
			"--ca-cert=/etc/vault/ca.pem",
			"--client-cert=/etc/vault/cert.pem",
			"--client-key=/etc/vault/key.pem"
		],
		"command": "google-auth-vault-plugin",
		"name": "google-auth-vault-plugin",
		"sha256": "989845e5a0171d9e1b1c6d9ca13393dd031fd9068c200c52ec723737ed450d4d"
	},
	"warnings": null
}

Which should be enough to allow terraform to manage plugins.

@tomwilkie
Copy link
Contributor Author

Failures seem LDAP related?

@jefferai
Copy link
Member

Yep, seems like the LDAP test server is down.

args := d.Get("args").([]string)
// For backwards compatibility, also accept args as part of command.
parts := strings.Split(command, " ")
args = append(parts[1:], args...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do a length check before this line to make sure the command actually has more than one value...otherwise it'll panic.

Copy link
Contributor Author

@tomwilkie tomwilkie Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Length >0 is assured by the check for the empty string above (as with the previous iteration of the code). But I'll add it anyway :-)

if len(parts) <= 0 {
return logical.ErrorResponse("missing command value"), nil
}
args = append(parts[1:], args...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they specify both args and put args in the command they'll end up with doubled args here. I think a better check would be to ensure that len(parts) == 1 and if args is set and the length of parts is not 1, throw an error asking them to pick one or the other.

command := fmt.Sprintf("%s --test", filepath.Base(file.Name()))
err = core.pluginCatalog.Set("mysql-database-plugin", command, []byte{'1'})
command := fmt.Sprintf("%s", filepath.Base(file.Name()))
err = core.pluginCatalog.Set("mysql-database-plugin", command, []string{"--test"}, []byte{'1'})
Copy link
Member

@jefferai jefferai Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a check to verify correct behavior if both args and command-with-args are given (after fixing above)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the test to logical_system_test.go, as the logic to ensure only command or args is specified is in logical_system.go - hope thats okay!

@jefferai
Copy link
Member

Looks good after the requested changes are made.

@jefferai jefferai added this to the 0.9.2 milestone Jan 12, 2018
@jefferai jefferai requested a review from calvn January 12, 2018 16:05
@tomwilkie
Copy link
Contributor Author

@jefferai sorry for the delay, have addressed your comments. Thanks!

@jefferai jefferai modified the milestones: 0.9.2, 0.9.3 Jan 17, 2018
@jefferai
Copy link
Member

Thanks!

@jefferai jefferai merged commit e884946 into hashicorp:master Jan 18, 2018
@tomwilkie tomwilkie deleted the 3776-plugin-catalog-roundtrip branch January 18, 2018 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants