A small library for helping with loading secrets from files including systemd service credentials support
  • Rust 80.9%
  • Nix 19.1%
Find a file
Robin Appelman 2dd223c249
All checks were successful
CI / checks (push) Successful in 37s
readme
2025-05-22 17:36:19 +02:00
.forgejo/workflows ci 2025-05-22 17:25:28 +02:00
src readme 2025-05-22 17:36:19 +02:00
.envrc init 2024-02-29 23:18:13 +01:00
.gitignore init 2024-02-29 23:18:13 +01:00
Cargo.lock 0.1.1 2025-05-22 17:16:20 +02:00
Cargo.toml 0.1.1 2025-05-22 17:16:20 +02:00
flake.lock flake reorg 2025-05-22 17:07:12 +02:00
flake.nix flake reorg 2025-05-22 17:07:12 +02:00
README.md readme 2025-05-22 17:36:19 +02:00

Secretfile

A small library for helping with loading secrets from files including systemd service credentials support.

Usage

Load a value from a file

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.