readme
All checks were successful
CI / checks (push) Successful in 37s

This commit is contained in:
Robin Appelman 2025-05-22 17:35:02 +02:00
commit 2dd223c249
2 changed files with 26 additions and 1 deletions

25
README.md Normal file
View file

@ -0,0 +1,25 @@
# Secretfile
A small library for helping with loading secrets from files including systemd
service credentials support.
## Usage
Load a value from a file
```rust
fn main() -> Result<(), Box<dyn std::error::Error>> {
let secret = secretfile::load("/path/to/supper/secret/file")?;
println!("{secret}");
Ok(())
}
```
If the provided path includes the `$CREDENTIALS_DIRECTORY` placeholder, it will
be replaced with the systemd service credential directory. Any trailing
whitespace will be stripped from the returned secret.
## Why make this a library?
While the code is simple enough, I found myself copy-pasting it enough times
that it seemed useful to put into a library.

View file

@ -30,7 +30,7 @@ impl Error for SecretError {}
/// If the provided path includes the `$CREDENTIALS_DIRECTORY` placeholder, it will be replaced with the
/// systemd service credential directory.
///
/// any leading whitespace will be stripped from the returned secret.
/// any trailing whitespace will be stripped from the returned secret.
pub fn load(path: &str) -> Result<String, SecretError> {
let file = if path.contains("$CREDENTIALS_DIRECTORY") {
let dir = var("CREDENTIALS_DIRECTORY")