Skip to content

Commit 63318b8

Browse files
committed
allow to pass in ansible vault password in method signatures
1 parent 16ea1d6 commit 63318b8

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

tooling/conga-aem-crypto-cli/src/main/java/io/wcm/devops/conga/plugins/aem/tooling/crypto/cli/AnsibleVault.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,19 @@ private AnsibleVault() {
4444
* @throws IOException I/O exception
4545
*/
4646
public static void encrypt(File file) throws IOException {
47+
encrypt(file, AnsibleVaultPassword.get());
48+
}
49+
50+
/**
51+
* Encrypts file with Ansible vault.
52+
* @param file File to encrypt
53+
* @param ansibleVaultPassword Ansible Vault Password
54+
* @throws IOException I/O exception
55+
*/
56+
public static void encrypt(File file, String ansibleVaultPassword) throws IOException {
4757
handleFile(file, data -> {
4858
try {
49-
return VaultHandler.encrypt(data, AnsibleVaultPassword.get());
59+
return VaultHandler.encrypt(data, ansibleVaultPassword);
5060
}
5161
catch (IOException ex) {
5262
throw new RuntimeException("Unable to encrypt file " + file.getPath(), ex);
@@ -60,9 +70,19 @@ public static void encrypt(File file) throws IOException {
6070
* @throws IOException I/O exception
6171
*/
6272
public static void decrypt(File file) throws IOException {
73+
decrypt(file, AnsibleVaultPassword.get());
74+
}
75+
76+
/**
77+
* Decrypts file with Ansible vault.
78+
* @param file File to decrypt
79+
* @param ansibleVaultPassword Ansible Vault Password
80+
* @throws IOException I/O exception
81+
*/
82+
public static void decrypt(File file, String ansibleVaultPassword) throws IOException {
6383
handleFile(file, data -> {
6484
try {
65-
return VaultHandler.decrypt(data, AnsibleVaultPassword.get());
85+
return VaultHandler.decrypt(data, ansibleVaultPassword);
6686
}
6787
catch (IOException ex) {
6888
throw new RuntimeException("Unable to decrypt file " + file.getPath(), ex);

tooling/conga-aem-crypto-cli/src/main/java/io/wcm/devops/conga/plugins/aem/tooling/crypto/cli/CryptoKeys.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,29 @@ private CryptoKeys() {
4949
* @throws GeneralSecurityException Security exception
5050
*/
5151
public static Stream<File> generate(File targetDir, boolean ansibleVaultEncrypt) throws GeneralSecurityException {
52+
return generate(targetDir, ansibleVaultEncrypt, AnsibleVaultPassword.get());
53+
}
54+
55+
/**
56+
* Generates AES and HMAC crypto keys for AEM.
57+
* @param targetDir Target directory
58+
* @param ansibleVaultEncrypt If true, the crypto keys are encrypted with Ansible Vault.
59+
* @param ansibleVaultPassword Ansible Vault Password
60+
* @return Generated files
61+
* @throws GeneralSecurityException Security exception
62+
*/
63+
public static Stream<File> generate(File targetDir, boolean ansibleVaultEncrypt,
64+
String ansibleVaultPassword) throws GeneralSecurityException {
5265
Stream<KeyItem> keys = Stream.of(
5366
new KeyItem("master", new AesCryptoSupport().generateKey().getEncoded()),
5467
new KeyItem("hmac", new HmacCryptoKeySupport().generateKey().getEncoded()));
5568
if (ansibleVaultEncrypt) {
56-
keys = encryptKeys(keys);
69+
keys = encryptKeys(keys, ansibleVaultPassword);
5770
}
5871
return writeKeys(keys, targetDir);
5972
}
6073

61-
private static Stream<KeyItem> encryptKeys(Stream<KeyItem> keys) {
62-
String password = AnsibleVaultPassword.get();
74+
private static Stream<KeyItem> encryptKeys(Stream<KeyItem> keys, String password) {
6375
return keys.map(key -> {
6476
try {
6577
return new KeyItem(key.getName(), VaultHandler.encrypt(key.getData(), password));

0 commit comments

Comments
 (0)