# envlet
Pull your Envlet environment at runtime. The host platform holds one secret,
an Envlet token, and your app loads everything else at boot.
```rust
use envlet::{inject, Error, Options};
fn main() -> Result<(), Error> {
inject(&Options::default())?;
Ok(())
}
```
`inject` fetches every value the token identity may read and sets the process
environment. Values already set by the host are never overwritten. Set
`override_existing` to replace existing values.
```rust
use envlet::{inject, Error, Options};
fn main() -> Result<(), Error> {
let options = Options {
override_existing: true,
..Options::default()
};
inject(&options)?;
Ok(())
}
```
Use `load` to fetch all values or `get` to fetch one value. Each call fetches
current values from Envlet, with no cache or partial result.
```rust
use envlet::{get, load, Error, Options};
fn read_values() -> Result<(), Error> {
let options = Options::default();
let _values = load(&options)?;
let _stripe_key = get("STRIPE_KEY", &options)?;
Ok(())
}
```
Configuration comes from `ENVLET_TOKEN` or `Options::token`. The API URL comes
from `ENVLET_API_URL`, then defaults to `https://api.envlet.dev`. Set
`Options::api_url` to select another URL. Network failures and 5xx responses
retry up to three total attempts. Set `Options::retry` to `false` to send one
request.
Errors use the `Error` enum. `Error::Auth { code }` carries API codes such as
`token_expired` and `unauthorized`. Missing values use `Error::NotFound`,
network failures use `Error::Network`, an absent token uses
`Error::ConfigMissing`, a bad token or API URL uses `Error::ConfigInvalid`,
and other API failures use `Error::Api { code, status }`. `Error::code()`
returns the API code or the fixed code for fieldless variants.
The crate depends on `ureq` with `rustls` and nothing else. The Rust standard
library has no HTTP client or TLS, so this is the one SDK with a dependency.
Use version 0.1.0 from crates.io after it is released:
```toml
[dependencies]
envlet = "0.1.0"
```
The crate is licensed under MIT. Source:
https://github.com/selcor/envlet.