如何从Vault Java驱动程序检索hashicorp Vault中不同版本的机密。或者我们可以禁用机密版本控制?

时间:2019-10-01 05:47:00

标签: java command-line-interface hashicorp-vault

我最近遇到了秘密版本控制。但是只能从Vault Java驱动程序中检索写入的最新机密

我试图禁用版本控制,以便可以正常检索它,但是它没有用。如果我们可以禁用它,那就没问题了。

这是我的Java程序,用于检索编写的机密信息。我该如何提及版本?

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import com.bettercloud.vault.SslConfig;
import com.bettercloud.vault.Vault;
import com.bettercloud.vault.VaultConfig;
import com.bettercloud.vault.VaultException;
import com.bettercloud.vault.response.AuthResponse;
import com.bettercloud.vault.response.LogicalResponse;
import com.bettercloud.vault.api.Seal;
import com.bettercloud.vault.response.SealResponse;

public class VaultDriver {

    public static void main(String args[]) throws VaultException {

        File sslCertificate = new File("vault.crt");
        final VaultConfig config =
                    new VaultConfig()
                        .address("https://127.0.0.1:8200")
                        .openTimeout(5)
                        .readTimeout(30)
                        .sslConfig(new SslConfig().verify(true).pemFile(sslCertificate).build())
                        .token("XXXXXX");

        //You may choose not to provide a root token initially, if you plan to use
        //the Vault driver to retrieve one programmatically from an auth backend.

        final Vault vault = new Vault(config,1);
        //System.out.println(vault.toString());
        // vault.auth().loginByUserPass("rohit", "rohit");

        /*final Map<String, Object> secrets = new HashMap<String, Object>();
         * secrets.put("value1", "world"); secrets.put("value2", "bar");
         * 
         * // Write operation final LogicalResponse writeResponse =
         * vault.logical().write("kv/name", secrets);
         * 
         * System.out.println(writeResponse.toString());
         */

        // Read operation
        final String value = vault.logical()
                                  .read("kv/name")
                                  .getData()
                                  .get("key");
        System.out.println();
        System.out.println(value);
    }
}

0 个答案:

没有答案