pub fn run(args: Args) -> Result<(), Error> {
    // Create a new blocking http client to make use of connection pooling.
    let http = reqwest::blocking::Client::new();

    // Key-value store for the environment variable downloaded from Vault.
    let mut vars: HashMap<String, String> = HashMap::new();

    let mut paths = args.paths;

    // Reverse the order of paths so that latter paths with a duplicate variable name are overwritten.
    paths.reverse();

    for path in paths {
        // Build the Vault API url.
        let url = args.vault_address.join("v1/")?;
        let url = url.join(path.as_str())?;

        debug!("making request to \"{}\"", url);

        let req = http.get(url).header(
            reqwest::header::AUTHORIZATION,
            format!("Bearer {}", args.vault_token),
        );

        let resp = req.send()?;

        if !resp.status().is_success() {
            return Err(VaultResponseError {
                status: resp.status(),
                path,
            }
            .into());
        }

        let resp: serde_json::Value = resp.json()?;
        let data = &resp["data"];

        // Handle the diffrent data formats for version 1 and 2 of the key-value secrets engine.
        let data = if data["metadata"]["version"].is_number() {
            data["data"].as_object().unwrap()
        } else {
            data.as_object().unwrap()
        };

        for (name, value) in data {
            let name = name.to_string();
            let value = match stringify_json_value(&value) {
                Some(value) => value,
                None => {
                    warn!(
                        "the value for {} in {} is an array or object and will be ignored",
                        name, path
                    );
                    continue;
                }
            };

            vars.insert(name, value);
        }
    }

    save_dotenv(args.output, vars)
}
/// Use the given command line arguments to run vdot.
///
/// # Examples
///
/// ```
/// use log::error;
/// use std::path::PathBuf;
/// use std::process;
/// use vdot::Args;
/// use reqwest::Url;
///
/// let args = Args {
///     paths: vec![],
///     output: PathBuf::from(".env"),
///     vault_token: "hunter2".to_string(),
///     vault_address: Url::parse("http://127.0.0.1:8200").unwrap(),
///     vault_kv_version: 2,
///     verbose: false
/// };
///
/// if let Err(err) = vdot::run(args) {
///     error!("{}", err);
///     process::exit(1);
/// }
/// ```
///
/// # Errors
///
/// Returns an error if anything goes wrong, and exits the process with a status code of 1.
Use the given command line arguments to run vdot.
Use the given command line arguments to run vdot .
pub fn run(args: Args) -> Result<(), Error> {
    // Create a new blocking http client to make use of connection pooling.
    let http = reqwest::blocking::Client::new();
    // Key-value store for the environment variable downloaded from Vault.
    let mut vars: HashMap<String, String> = HashMap::new();
    let mut paths = args.paths;
    // Reverse the order of paths so that latter paths with a duplicate variable name are overwritten.
    paths.reverse();
    for path in paths {
        // Build the Vault API url.
        let url = args.vault_address.join("v1/")?;
        let url = url.join(path.as_str())?;
        debug!("making request to \"{}\"", url);
        let req = http.get(url).header(
            reqwest::header::AUTHORIZATION,
            format!("Bearer {}", args.vault_token),
        );
        let resp = req.send()?;
        if !resp.status().is_success() {
            return Err(VaultResponseError {
                status: resp.status(),
                path,
            }
            .into());
        }
        let resp: serde_json::Value = resp.json()?;
        let data = &resp["data"];
        // Handle the diffrent data formats for version 1 and 2 of the key-value secrets engine.
        let data = if data["metadata"]["version"].is_number() {
            data["data"].as_object().unwrap()
        } else {
            data.as_object().unwrap()
        };
        for (name, value) in data {
            let name = name.to_string();
            let value = match stringify_json_value(&value) {
                Some(value) => value,
                None => {
                    warn!(
                        "the value for {} in {} is an array or object and will be ignored",
                        name, path
                    );
                    continue;
                }
            };
            vars.insert(name, value);
        }
    }
    save_dotenv(args.output, vars)
}
pub fn run ( args : Args ) -> Result < ( ) , Error > { // Create a new blocking http client to make use of connection pooling. let http = reqwest :: blocking :: Client :: new ( ) ; // Key-value store for the environment variable downloaded from Vault. let mut vars : HashMap < String , String > = HashMap :: new ( ) ; let mut paths = args . paths ; // Reverse the order of paths so that latter paths with a duplicate variable name are overwritten. paths . reverse ( ) ; for path in paths { // Build the Vault API url. let url = args . vault_address . join ( " " ) ? ; let url = url . join ( path . as_str ( ) ) ? ; debug ! ( " \" \" " url ) ; let req = http . get ( url ) . header ( reqwest :: header :: AUTHORIZATION , format ! ( " " args vault_token ) , ) ; let resp = req . send ( ) ? ; if ! resp . status ( ) . is_success ( ) { return Err ( VaultResponseError { status : resp . status ( ) , path , } . into ( ) ) ; } let resp : serde_json :: Value = resp . json ( ) ? ; let data = & resp [ " " ] ; // Handle the diffrent data formats for version 1 and 2 of the key-value secrets engine. let data = if data [ " " ] [ " " ] . is_number ( ) { data [ " " ] . as_object ( ) . unwrap ( ) } else { data . as_object ( ) . unwrap ( ) } ; for ( name , value ) in data { let name = name . to_string ( ) ; let value = match stringify_json_value ( & value ) { Some ( value ) => value , None => { warn ! ( " " name path ) ; continue ; } } ; vars . insert ( name , value ) ; } } save_dotenv ( args . output , vars ) }
Use the given command line arguments to run vdot.
Use the given command line arguments to run vdot .
args
Args
args
Args
examples
None
errors
Returns an error if anything goes wrong, and exits the process with a status code of 1.
Returns an error if anything goes wrong and exits the process with a status code of 1 .