Package org.kiwiproject.ansible.vault
Class VaultEncryptionHelper
java.lang.Object
org.kiwiproject.ansible.vault.VaultEncryptionHelper
The main class in this package for executing
ansible-vault commands.
While it is possible to use the various command classes directly to build the operating system command,
create a ProcessBuilder and finally a Process, this class wraps all that and makes it relatively
easy to make ansible-vault calls in the operating system.
-
Constructor Summary
ConstructorsConstructorDescriptionVaultEncryptionHelper(VaultConfiguration configuration) Create an instance with the given vault configuration. -
Method Summary
Modifier and TypeMethodDescriptiondecryptFile(String encryptedFilePath) Wraps ansible-vault decrypt command.decryptFile(String encryptedFilePath, String outputFilePath) Wraps ansible-vault decrypt command.decryptFile(Path encryptedFilePath) Wraps ansible-vault decrypt command.decryptFile(Path encryptedFilePath, Path outputFilePath) Wraps ansible-vault decrypt command.decryptString(String encryptedString) Decrypts an encrypted string variable formatted using encrypt_string with a --name option.encryptFile(String plainTextFilePath) Wraps the ansible-vault encrypt command.encryptFile(String plainTextFilePath, String vaultIdLabel) Wraps the ansible-vault encrypt command using a vault ID label.encryptFile(Path plainTextFilePath) Wraps the ansible-vault encrypt command.encryptFile(Path plainTextFilePath, String vaultIdLabel) Wraps the ansible-vault encrypt command using a vault ID label.encryptString(String plainText, String variableName) Wraps the ansible-vault encrypt_string command.encryptString(String vaultIdLabel, String plainText, String variableName) Wraps the ansible-vault encrypt_string command using an optional vault ID label.Wraps ansible-vault rekey command.Wraps ansible-vault rekey command.Wraps ansible-vault view command.Wraps ansible-vault view command.Locate theansible-vaultprogram in the user's path.Locate theansible-vaultprogram in the user's path, returning the result as aPath.
-
Constructor Details
-
VaultEncryptionHelper
Create an instance with the given vault configuration. Makes a copy of the given configuration, such that changes to the supplied object are not seen by this instance.If the configuration needs to change, for example after a re-key operation, then simply construct a new instance passing in the new
VaultConfigurationobject.- Parameters:
configuration- the vault configuration- Implementation Note:
- while the configuration is validated at construction time, it could become invalid if the files in the operating system change. For example, if the vault password file was deleted or renamed. Since these are unlikely scenarios, we don't bother re-checking on every call.
-
-
Method Details
-
whichAnsibleVault
Locate theansible-vaultprogram in the user's path.- Returns:
- an Optional containing the full path to
ansible-vault, or an empty Optional if not found - See Also:
-
whichAnsibleVaultAsPath
Locate theansible-vaultprogram in the user's path, returning the result as aPath.- Returns:
- an Optional containing the full
Pathtoansible-vault, or an empty Optional if not found - See Also:
- Implementation Note:
- This is a convenience wrapper around
Processes.whichAsPath(String)specifically for the ansible-vault program
-
encryptFile
Wraps the ansible-vault encrypt command. Encrypts file in place.- Parameters:
plainTextFilePath- the path to the file to encrypt in place- Returns:
- the
Pathto the encrypted file, which will be the same as the argument
-
encryptFile
Wraps the ansible-vault encrypt command. Encrypts file in place.- Parameters:
plainTextFilePath- the path to the file to encrypt in place- Returns:
- the
Pathto the encrypted file
-
encryptFile
Wraps the ansible-vault encrypt command using a vault ID label. Encrypts file in place.- Parameters:
plainTextFilePath- the path to the file to encrypt in placevaultIdLabel- the label for the--vault-id- Returns:
- the
Pathto the encrypted file, which will be the same as the argument
-
encryptFile
Wraps the ansible-vault encrypt command using a vault ID label. Encrypts file in place.- Parameters:
plainTextFilePath- the path to the file to encrypt in placevaultIdLabel- the label for the--vault-id- Returns:
- the
Pathto the encrypted file
-
decryptFile
Wraps ansible-vault decrypt command. Decrypts file in place.- Parameters:
encryptedFilePath- the path to the file to decrypt in place- Returns:
- the
Pathto the decrypted file, which will be the same as the argument
-
decryptFile
Wraps ansible-vault decrypt command. Decrypts file in place.- Parameters:
encryptedFilePath- the path to the file to decrypt in place- Returns:
- the
Pathto the decrypted file
-
decryptFile
Wraps ansible-vault decrypt command. Decrypts file to a new specified output path. The original encrypted file is not modified.- Parameters:
encryptedFilePath- the path to the file to decrypt in placeoutputFilePath- the path to the new output file where decrypted content will be written- Returns:
- the
Pathto the decrypted file
-
decryptFile
Wraps ansible-vault decrypt command. Decrypts file to a new specified output path. The original encrypted file is not modified.- Parameters:
encryptedFilePath- the path to the file to decrypt in placeoutputFilePath- the path to the new output file where decrypted content will be written- Returns:
- the
Pathto the decrypted file
-
viewFile
Wraps ansible-vault view command. Returns the decrypted contents of the file. The original encrypted file is not modified.- Parameters:
encryptedFilePath- the path to the file to view- Returns:
- the decrypted contents of the given file
-
viewFile
Wraps ansible-vault view command. Returns the decrypted contents of the file. The original encrypted file is not modified.- Parameters:
encryptedFilePath- the path to the file to view- Returns:
- the decrypted contents of the given file
-
rekeyFile
Wraps ansible-vault rekey command. Returns the path of the re-keyed file.- Parameters:
encryptedFilePath- the path to the file to viewnewVaultPasswordFilePath- path to the file containing the new password- Returns:
- the
Pathto the re-keyed file
-
rekeyFile
Wraps ansible-vault rekey command. Returns the path of the re-keyed file.- Parameters:
encryptedFilePath- the path to the file to viewnewVaultPasswordFilePath- path to the file containing the new password- Returns:
- the
Pathto the re-keyed file
-
encryptString
Wraps the ansible-vault encrypt_string command.- Parameters:
plainText- the plain text to encryptvariableName- the name of the variable- Returns:
- the encrypted variable
-
encryptString
Wraps the ansible-vault encrypt_string command using an optional vault ID label.- Parameters:
vaultIdLabel- the label of the vault (for use with the--vault-idargumentplainText- the plain text to encryptvariableName- the name of the variable- Returns:
- the encrypted variable
-
decryptString
Decrypts an encrypted string variable formatted using encrypt_string with a --name option.- Parameters:
encryptedString- the encrypted variable- Returns:
- the decrypted content of the encrypted content
-