1 package fr.paris.lutece.util.configsource;
2
3 import java.util.List;
4
5 import com.bettercloud.vault.Vault;
6 import com.bettercloud.vault.VaultConfig;
7 import com.bettercloud.vault.VaultException;
8
9
10
11 // TODO: Auto-generated Javadoc
12 /**
13 * The Class VaultService.
14 */
15 public class VaultService {
16
17
18 /** The vault. */
19 private Vault _vault;
20
21 /**
22 * Instantiates a new vault service.
23 *
24 * @param strAdress the str adress
25 * @param strVaultToken the str vault token
26 * @throws VaultException the vault exception
27 */
28 public VaultService(String strAdress, String strVaultToken)throws VaultException {
29 _vault=initDriver(strAdress, strVaultToken);
30
31 }
32
33
34 /**
35 * Gets the all secrets key by path.
36 *
37 * @param strSecretPath the str secret path
38 * @return the all secrets key by path
39 * @throws VaultException the vault exception
40 */
41
42 public List<String> getAllSecretsKeyByPath(String strSecretPath) throws VaultException{
43
44 List<String> listAllSecrets = _vault.logical()
45 .list(strSecretPath).getListData();
46 return listAllSecrets;
47
48 }
49
50
51
52 /**
53 * Gets the secret value.
54 *
55 * @param strSecretPath the str secret path
56 * @param secretKey the secret key
57 * @return the secret value
58 * @throws VaultException the vault exception
59 */
60 public String getSecretValue(String strSecretPath,String secretKey)throws VaultException {
61
62 String secretKV = _vault.logical()
63 .read( strSecretPath+ "/" + secretKey)
64 .getData()
65 .get(secretKey);
66 return secretKV;
67
68
69 }
70
71
72 /**
73 * Inits the driver.
74 *
75 * @param strAdress the str adress
76 * @param strRootToken the str root token
77 * @return the vault
78 * @throws VaultException the vault exception
79 */
80 private Vault initDriver(String strAdress, String strRootToken) throws VaultException {
81
82
83 VaultConfig config = new VaultConfig()
84 .address(strAdress)
85 .token(strRootToken)
86 .build();
87
88 return new Vault(config);
89
90
91 }
92 }
93
94
95