pub struct AnsibleVault { /* private fields */ }
Expand description
Ansible Vault encryption and decryption utility.
The AnsibleVault
struct provides a comprehensive interface for managing
encrypted files and strings using Ansible Vault. It supports all major
vault operations including encryption, decryption, viewing, editing, and rekeying.
§Examples
§Basic File Operations
use ansible::AnsibleVault;
let mut vault = AnsibleVault::new();
vault.set_vault_password_file("vault_pass.txt");
// Encrypt a file
vault.encrypt("secrets.yml")?;
// Decrypt a file
vault.decrypt("secrets.yml")?;
// View encrypted content
let content = vault.view("secrets.yml")?;
println!("Content: {}", content);
§String Encryption
use ansible::AnsibleVault;
let mut vault = AnsibleVault::new();
vault.set_vault_password_file("vault_pass.txt");
// Encrypt a string
let encrypted = vault.encrypt_string("my_secret_password")?;
println!("Encrypted: {}", encrypted);
§Multiple Vault IDs
use ansible::AnsibleVault;
let mut vault = AnsibleVault::new();
vault.set_vault_id("prod@vault_pass.txt");
// Operations will use the specified vault ID
vault.encrypt("production_secrets.yml")?;
§Rekeying Files
use ansible::AnsibleVault;
let mut vault = AnsibleVault::new();
vault
.set_vault_password_file("old_pass.txt")
.set_new_vault_password_file("new_pass.txt");
// Change the encryption key
vault.rekey("secrets.yml")?;
Implementations§
Source§impl AnsibleVault
impl AnsibleVault
Sourcepub fn set_vault_id(&mut self, vault_id: impl Into<String>) -> &mut Self
pub fn set_vault_id(&mut self, vault_id: impl Into<String>) -> &mut Self
Set vault ID for encryption/decryption
Sourcepub fn set_vault_password_file(
&mut self,
file_path: impl Into<String>,
) -> &mut Self
pub fn set_vault_password_file( &mut self, file_path: impl Into<String>, ) -> &mut Self
Set vault password file
Sourcepub fn set_new_vault_password_file(
&mut self,
file_path: impl Into<String>,
) -> &mut Self
pub fn set_new_vault_password_file( &mut self, file_path: impl Into<String>, ) -> &mut Self
Set new vault password file for rekeying operations
Sourcepub fn set_system_envs(&mut self) -> &mut Self
pub fn set_system_envs(&mut self) -> &mut Self
Set environment variables from the system
Sourcepub fn add_env(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> &mut Self
pub fn add_env( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> &mut Self
Add an environment variable
Sourcepub fn create(&self, file_path: impl Into<String>) -> Result<String>
pub fn create(&self, file_path: impl Into<String>) -> Result<String>
Create and encrypt a new file
Sourcepub fn view(&self, file_path: impl Into<String>) -> Result<String>
pub fn view(&self, file_path: impl Into<String>) -> Result<String>
Decrypt and view a file without modifying it
Sourcepub fn rekey(&self, file_path: impl Into<String>) -> Result<String>
pub fn rekey(&self, file_path: impl Into<String>) -> Result<String>
Re-encrypt a file with a new password
Sourcepub fn encrypt_string(
&self,
string_to_encrypt: impl Into<String>,
) -> Result<String>
pub fn encrypt_string( &self, string_to_encrypt: impl Into<String>, ) -> Result<String>
Encrypt a string and output it in a format suitable for inclusion in YAML
Sourcepub fn encrypt_string_with_name(
&self,
string_to_encrypt: impl Into<String>,
var_name: impl Into<String>,
) -> Result<String>
pub fn encrypt_string_with_name( &self, string_to_encrypt: impl Into<String>, var_name: impl Into<String>, ) -> Result<String>
Encrypt a string with a variable name
Sourcepub fn encrypt_string_prompt(&self) -> Result<String>
pub fn encrypt_string_prompt(&self) -> Result<String>
Encrypt a string and prompt for input
Sourcepub fn encrypt_string_stdin(
&self,
stdin_name: impl Into<String>,
) -> Result<String>
pub fn encrypt_string_stdin( &self, stdin_name: impl Into<String>, ) -> Result<String>
Encrypt a string with stdin input
Sourcepub fn decrypt_to_file(
&self,
input_file: impl Into<String>,
output_file: impl Into<String>,
) -> Result<String>
pub fn decrypt_to_file( &self, input_file: impl Into<String>, output_file: impl Into<String>, ) -> Result<String>
Decrypt a file to a specific output location
Sourcepub fn encrypt_to_file(
&self,
input_file: impl Into<String>,
output_file: impl Into<String>,
) -> Result<String>
pub fn encrypt_to_file( &self, input_file: impl Into<String>, output_file: impl Into<String>, ) -> Result<String>
Encrypt a file to a specific output location
Sourcepub fn set_encrypt_vault_id(&mut self, vault_id: impl Into<String>) -> &mut Self
pub fn set_encrypt_vault_id(&mut self, vault_id: impl Into<String>) -> &mut Self
Set the vault ID used for encryption (when multiple vault IDs are available)
Sourcepub fn ask_vault_password(&mut self) -> &mut Self
pub fn ask_vault_password(&mut self) -> &mut Self
Ask for vault password interactively
Sourcepub fn get_config(&self) -> &CommandConfig
pub fn get_config(&self) -> &CommandConfig
Get a reference to the command configuration (for testing)
Trait Implementations§
Source§impl Clone for AnsibleVault
impl Clone for AnsibleVault
Source§fn clone(&self) -> AnsibleVault
fn clone(&self) -> AnsibleVault
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more