Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept some settings as environment variables. #15

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ debug = ['serde_json']
[dependencies]
anyhow = "1.0"
bincode = "1.3.1"
clap = { version = "3.0", default_features = false, features = ["std", "derive"] }
clap = { version = "3.0", default_features = false, features = ["std", "derive", "env"] }
humantime = "2.1.0"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ frequently than the `--ttl` would suggest, which in turn can create unexpected
load. If the backing command is failing due to an outage or bug (such as an
overloaded website) triggering additional calls can exacerbate the issue and
effectively DDoS the hampered system. It is generally safer *not* to set this
flag and instead make the client robust to occasional failures.
flag and instead make the client robust to occasional failures.

<a name="cache_dir"></a>
### Changing the Cache Directory
Expand All @@ -169,6 +169,16 @@ Note that the choice of directory can affect `bkt`'s performance: if the cache
is stored under a [`tmpfs`](https://en.wikipedia.org/wiki/Tmpfs) or solid-state
partition it will be significantly faster than caching to a spinning disk.

### Environment Variables
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to document these variables alongside their sibling flags, rather than in a separate section. If you feel this is preferable each variable here should at least link to the relevant section of the readme, and call out which flag it's replacing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to document these variables alongside their sibling flags

I fear adding this to the main usage section would be overwhelming. Using environment variables instead of command line flags is a niche usage, don't need to bother everyone with this.


Some settings can be passed via the following environment variables:

- `BKT_SCOPE` for [`--scope`](#setting-a-cache-scope)
- `BKT_TMPDIR` for [`--cache-dir`](#changing-the-cache-directory)
- `BKT_TTL` for [`--ttl`](#cache-lifespan)
- `BKT_STALE` for [`--stale`](#cache-lifespan)


## Security and Privacy

The default cache directory is potentially world-readable. On Unix the cache
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ struct Cli {
command: Vec<OsString>,

/// Duration the cached result will be valid for
#[clap(long, default_value = "60s", visible_alias = "time-to-live")]
#[clap(long, default_value = "60s", visible_alias = "time-to-live", env = "BKT_TTL")]
ttl: humantime::Duration,

/// Duration after which the result will be asynchronously refreshed
#[clap(long, conflicts_with = "warm")]
#[clap(long, conflicts_with = "warm", env = "BKT_STALE")]
stale: Option<humantime::Duration>,

/// Asynchronously execute and cache the given command, even if it's already cached
Expand Down Expand Up @@ -142,14 +142,14 @@ struct Cli {

/// If set, all cached data will be scoped to this value,
/// preventing collisions with commands cached with different scopes
#[clap(long)]
#[clap(long, env = "BKT_SCOPE")]
scope: Option<String>,

/// The directory under which to persist cached invocations;
/// defaults to the system's temp directory.
/// Setting this to a directory backed by RAM or an SSD, such as a tmpfs partition,
/// will significantly reduce caching overhead.
#[clap(long)]
#[clap(long, env = "BKT_TMPDIR")]
cache_dir: Option<PathBuf>,
}

Expand Down