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

How to perform update operation for specific keys instead of overwriting existing other keys through java driver just like, vault kv patch in vault CLI? #217

Open
Rupesh-Chaudhari-93 opened this issue Mar 18, 2020 · 2 comments

Comments

@Rupesh-Chaudhari-93
Copy link

Rupesh-Chaudhari-93 commented Mar 18, 2020

Whenever, I am trying to update specific existing keys, its overwriting the other keys as well and there is data loss. I need to update existing keys or add new keys without affecting existing keys.
This scenario can be achieved by using vault CLI. But, I am not sure how to implement it using Vault Java Driver.

For e.g. using vault CLI :
vault kv put secret/partner name="Example Co." partner_id="123456789111111"
Keys stored in Vault :
======= Data =======
Key Value
=== =====
name Example Co.
partner_id 123456789111111

vault kv patch secret/partner contact=889765412
Keys stored in Vault :
======= Data =======
Key Value
=== =====
contact 889765412
name Example Co.
partner_id 123456789111111

Using Vault Java Driver :
Map<String, Object> secretMap = new HashMap<String, Object>();
secretMap.put("name","Example Co.");
secretMap.put("partner_id","123456789111111");
final LogicalResponse writeResponse = vault.logical()
.write("secret/partner", secretMap);
Keys stored in Vault :
======= Data =======
Key Value
=== ====
name Example Co.
partner_id 123456789111111

Map<String, Object> m = new HashMap<String, Object>();
secretMap.put("contact","889765412");
final LogicalResponse writeResponse = vault.logical()
.write("secret/partner", m);
Keys stored in Vault :
======= Data =======
Key Value
=== ====
contact 889765412

Hence, it's overwriting the existing data. Can anybody please help me to achieve this thing with Vault Java Driver.

@Rupesh-Chaudhari-93 Rupesh-Chaudhari-93 changed the title How to perform update operation for specific keys through java driver instead of overwritten existing just like, vault kv patch in vault API? How to perform update operation for specific keys instead of overwriting existing other keys through java driver just like, vault kv patch in vault CLI? Mar 19, 2020
@yuanlu-0
Copy link

yuanlu-0 commented Apr 3, 2021

Have you found a solution? I ran into the same issue.

@siepkes
Copy link

siepkes commented Apr 22, 2021

As far as I can tell the patch command the Vault CLI offers is not based on a special Vault patch API. It is "just" a convenience offered by the CLI tool. It basically downloads the old values, adds the new value and then uploads the entire thing (old and new values) to Vault.

You can see it here: https://github.com/hashicorp/vault/blob/a24653cc5cca475962b27b71dcba29a4aa94d6ee/command/kv_patch.go

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

No branches or pull requests

3 participants