open-vault/api
Alexander Scheel df07170d26
Vault Raw Read Support (CLI & Client) (#14945)
* Expose raw request from client.Logical()

Not all Vault API endpoints return well-formatted JSON objects.
Sometimes, in the case of the PKI secrets engine, they're not even
printable (/pki/ca returns a binary (DER-encoded) certificate). While
this endpoint isn't authenticated, in general the API caller would
either need to use Client.RawRequestWithContext(...) directly (which
the docs advise against), or setup their own net/http client and
re-create much of Client and/or Client.Logical.

Instead, exposing the raw Request (via the new ReadRawWithData(...))
allows callers to directly consume these non-JSON endpoints like they
would nearly any other endpoint.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add raw formatter for direct []byte data

As mentioned in the previous commit, some API endpoints return non-JSON
data. We get as far as fetching this data (via client.Logical().Read),
but parsing it as an api.Secret fails (as in this case, it is non-JSON).
Given that we intend to update `vault read` to support such endpoints,
we'll need a "raw" formatter that accepts []byte-encoded data and simply
writes it to the UI.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add support for reading raw API endpoints

Some endpoints, such as `pki/ca` and `pki/ca/pem` return non-JSON
objects. When calling `vault read` on these endpoints, an error
is returned because they cannot be parsed as api.Secret instances:

> Error reading pki/ca/pem: invalid character '-' in numeric literal

Indeed, we go to all the trouble of (successfully) fetching this value,
only to be unable to Unmarshal into a Secrets value. Instead, add
support for a new -format=raw option, allowing these endpoints to be
consumed by callers of `vault read` directly.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add changelog entry

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Remove panic

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2022-10-28 09:45:32 -04:00
..
auth Update vault to v1.8.1 (#17516) 2022-10-20 11:56:55 -07:00
test-fixtures Add More TLS Tests and Verification of TLS Root Certificate (#11300) 2021-04-12 08:39:40 -07:00
api_test.go Add HTTP PATCH support to KV (#12687) 2021-10-13 15:24:31 -04:00
auth.go [Vault-5248] MFA support for api login helpers (#14900) 2022-04-15 11:13:15 -07:00
auth_test.go [Vault-5248] MFA support for api login helpers (#14900) 2022-04-15 11:13:15 -07:00
auth_token.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
client.go Added flag and env var which will disable client redirection (#17352) 2022-09-30 09:29:37 +01:00
client_test.go Added flag and env var which will disable client redirection (#17352) 2022-09-30 09:29:37 +01:00
go.mod Update httpguts for GO-2022-0236 fix (#17520) 2022-10-12 15:02:54 -07:00
go.sum Update httpguts for GO-2022-0236 fix (#17520) 2022-10-12 15:02:54 -07:00
help.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
kv.go Add a sentinel error for missing KV secrets (#16699) 2022-08-12 19:29:42 -04:00
kv_test.go Fix for KV_V2 Custom Metadata Bug (#17395) 2022-10-05 16:43:54 -07:00
kv_v1.go Add a sentinel error for missing KV secrets (#16699) 2022-08-12 19:29:42 -04:00
kv_v2.go Fix for KV_V2 Custom Metadata Bug (#17395) 2022-10-05 16:43:54 -07:00
lifetime_watcher.go update gofumpt to 0.3.1 and reformat the repo (#17055) 2022-09-07 17:31:20 -07:00
logical.go Vault Raw Read Support (CLI & Client) (#14945) 2022-10-28 09:45:32 -04:00
output_policy.go Global flag that outputs minimum policy HCL required for an operation (#14899) 2022-04-27 16:35:18 -07:00
output_string.go refactor: replace strings.Replace with strings.ReplaceAll (#15392) 2022-08-03 15:22:48 -04:00
plugin_helpers.go feature: secrets/auth plugin multiplexing (#14946) 2022-08-29 21:42:26 -05:00
plugin_helpers_test.go Global flag that outputs minimum policy HCL required for an operation (#14899) 2022-04-27 16:35:18 -07:00
README.md Developer Quickstart docs improvements (#16199) 2022-06-30 08:50:35 -07:00
renewer_test.go TestLifetimeWatcher: Address race condition in test assertions (#15969) 2022-06-14 09:44:51 -04:00
request.go Fix SRV Lookups (#8520) 2020-03-11 14:22:58 +01:00
request_test.go
response.go VAULT-1303 when a request to vault fails, show namespace if set (#12196) 2021-07-30 12:32:05 -04:00
secret.go Fix integer overflows with new parseutil (#15437) 2022-05-16 13:57:19 -04:00
ssh.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
ssh_agent.go update gofumpt to 0.3.1 and reformat the repo (#17055) 2022-09-07 17:31:20 -07:00
ssh_agent_test.go Run a more strict formatter over the code (#11312) 2021-04-08 09:43:39 -07:00
sys.go
sys_audit.go update gofumpt to 0.3.1 and reformat the repo (#17055) 2022-09-07 17:31:20 -07:00
sys_auth.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
sys_capabilities.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
sys_config_cors.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
sys_generate_root.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
sys_hastatus.go Add autopilot automated upgrades and redundancy zones (#15521) 2022-05-20 16:49:11 -04:00
sys_health.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
sys_init.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
sys_leader.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
sys_leases.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
sys_mfa.go [Vault-5248] MFA support for api login helpers (#14900) 2022-04-15 11:13:15 -07:00
sys_monitor.go api/monitor: Adding log format to monitor command and debug (#15536) 2022-05-24 13:10:53 -04:00
sys_mounts.go CLI: Tune plugin version for auth/secret mounts (#17277) 2022-09-22 20:55:46 +01:00
sys_mounts_test.go Plugins: Consistently use plugin_version (#17171) 2022-09-20 12:35:50 +01:00
sys_plugins.go Plugins: Add -version flag to 'vault plugin info' (#17454) 2022-10-07 15:28:15 +01:00
sys_plugins_test.go Plugins: Add -version flag to 'vault plugin info' (#17454) 2022-10-07 15:28:15 +01:00
sys_policy.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
sys_raft.go Add autopilot automated upgrades and redundancy zones (#15521) 2022-05-20 16:49:11 -04:00
sys_rekey.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
sys_rotate.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00
sys_seal.go HCP link integration (#16939) 2022-09-06 14:11:04 -04:00
sys_stepdown.go Replace http method strings with net/http constants (#14677) 2022-03-24 13:58:03 -04:00

Vault API

This provides the github.com/hashicorp/vault/api package which contains code useful for interacting with a Vault server.

For examples of how to use this module, see the vault-examples repo. For a step-by-step walkthrough on using these client libraries, see the developer quickstart.

GoDoc