1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! [`envio`](https://envio-cli.github.io/) is a modern and secure CLI tool that
//! simplifies the management of environment variables.
//!
//! It is recommended to first visit the [official
//! website](https://envio-cli.github.io/) and learn more about how `envio`
//! works before using the library or else some of the terms used in the
//! documentation won't make much sense.
//!
//! Along with the CLI tool, `envio` also provides a library that can be used to
//! integrate the functionality provided by envio into your own Rust projects.
//!
//! The library provides a simple API that allows you to easily load environment
//! variables from a profile and use them in your Rust programs. Here is a
//! simple example:
//!
//! ```rust
//! envio::load!("my_profile");
//! println!("{}", std::env::var("MY_ENV_VAR").unwrap());
//! ```
//!
//! This will load all the environment variables in the `my_profile` profile and
//! set them in the current environment. You can then use them in your program.
//!
//! The interface is similar to the `dotenv` crate, but `envio` provides a more
//! secure way to load these environment variables ensuring that they aren't
//! stored in plaintext.
//!
//! envio currently supports two encryption methods:
//! - `passkey`
//! - `gpg`
//!
//! The `passkey` method is also known as `age` method since it uses the `age`
//! encryption library.
//!
//! Depending on what encryption method you use, you will have to provide a key
//! when loading the profile. So if `my_profile` was encrypted using the `age`
//! method, you would have to provide a key when loading the profile:
//!
//! ```rust
//! envio::load!("my_profile", || "mysecretkey".to_string()); // The load macro expects a closure that returns the key
//! println!("{}", std::env::var("MY_ENV_VAR").unwrap());
//! ```
//!
//! For the `gpg` method, you only need to provide the name of the profile,
//! envio retrives the key fingerprint itself and uses it to decrypt the
//! profile.
//!
//! For more information on how envio's encryption process work, you can take a
//! look at the documentation for the [crypto](crate::crypto) module.
//!
//! 90% of the time, a user will only use the `load` macro to load profiles.
//! However, if you require more control or need to use some other
//! functionality, you can browse the documentation to see what fits your use
//! case.
//!
//! A suggestion would be to take a look at the
//! [Profile](crate::profile::Profile) struct and the
//! [load_profile](crate::load_profile) macro.
//!
//! The CLI tool makes use of the library and also has some additional
//! functionality which is specific to the CLI tool only. However the building
//! blocks were provided by the library.
pub use Env;
pub use EnvVec; // Re-export EnvVec so that users don't have to use envio::profile::EnvVec
pub use Profile; // Re-export Profile so that users don't have to use envio::profile::Profile // Re-export Env so that users don't have to use envio::profile::Env
/// Main macro used to load profiles
///
/// It takes the name of the profile and an optional closure that returns the
/// key. This is only required if the profile was encrypted using the `age`
/// method.
///
/// # Example
///
/// ```rust
/// // Assuming the profile was encrypted using the `gpg` method
/// envio::load!("my_profile");
/// println!("{}", std::env::var("MY_ENV_VAR").unwrap());
/// ```