BetterCloud / vault-java-driver

Zero-dependency Java client for HashiCorp's Vault
https://bettercloud.github.io/vault-java-driver/
335 stars 224 forks source link

KVv1 and KVv2 - Non-Functional #159

Open Xtigyro opened 5 years ago

Xtigyro commented 5 years ago

I cannot make it work neither with KVv2, nor with KVv1 - using v4.0.0 of the Vault Java Driver. Some help will be highly appreciated!

I have:

[root@localhost vault-java-example]# curl -sk     -H "X-Vault-Token: s.7z4VY4YWzYgXJYAWql9JHAjR"     -X GET     https://127.0.0.1:8200/v1/kv/data/hello | jq
{
  "request_id": "513716aa-3df1-01e4-b889-25fea3207e76",
  "lease_id": "",
  "renewable": false,
  "lease_duration": 0,
  "data": {
    "data": {
      "foo": "world"
    },
    "metadata": {
      "created_time": "2019-03-03T11:53:34.657119825Z",
      "deletion_time": "",
      "destroyed": false,
      "version": 1
    }
  },
  "wrap_info": null,
  "warnings": null,
  "auth": null
}

And:

public class App
{
    public static void main( String[] args ) throws VaultException
    {         
        final VaultConfig config =
                new VaultConfig()
                .build();
        final Vault vault = new Vault(config);
        try {
        final String value = vault.logical()
                .read("kv/hello")
                .getData().get("foo");
            System.out.format( "foo key in kv/hello is " + value +"\n");
        } catch(VaultException e) {
          System.out.println("Exception thrown: " + e);
        }
    }
}

However, I cannot read with that code the secret - it returns:

[root@localhost vault-java-example]# java -jar target/java-client-example-1.0-SNAPSHOT-jar-with-dependencies.jar    
Constructing a Vault instance with no provided Engine version, defaulting to version 2.
Exception thrown: com.bettercloud.vault.VaultException: Vault responded with HTTP status code: 404
Response body: {"errors":[]}