hessra-config

Crates.iohessra-config
lib.rshessra-config
version0.3.0
created_at2025-04-01 19:57:11.292805+00
updated_at2025-08-23 17:09:12.206918+00
descriptionConfiguration management for Hessra SDK
homepage
repositoryhttps://github.com/Hessra-Labs/hessra-sdk.rs
max_upload_size
id1615434
size70,907
Jake (jcorrv)

documentation

https://docs.rs/hessra-config

README

Hessra Config

Crates.io Documentation License

Configuration management for Hessra SDK.

This crate provides structures and utilities for loading and managing configuration for the Hessra authentication system. It supports loading configuration from various sources including environment variables, files, and programmatic configuration.

Features

  • Configuration loading from JSON files
  • Configuration loading from environment variables
  • Optional TOML file support (enabled by default)
  • Builder pattern for programmatic configuration
  • Validation of configuration parameters
  • Global configuration management

Installation

Add this to your Cargo.toml:

[dependencies]
hessra-config = "0.2.0"

Usage

Creating a Configuration Manually

use hessra_config::{HessraConfig, Protocol};

let config = HessraConfig::new(
    "https://test.hessra.net",    // base URL
    Some(443),                     // port (optional)
    Protocol::Http1,               // protocol
    "client-cert-content",         // mTLS certificate
    "client-key-content",          // mTLS key
    "ca-cert-content",             // Server CA certificate
);

Using the Builder Pattern

use hessra_config::{HessraConfig, Protocol};

let config = HessraConfig::builder()
    .base_url("https://test.hessra.net")
    .port(443)
    .protocol(Protocol::Http1)
    .mtls_cert("client-cert-content")
    .mtls_key("client-key-content")
    .server_ca("ca-cert-content")
    .public_key("server-public-key")
    .personal_keypair("personal-keypair-content")
    .build()
    .unwrap();

Loading from a JSON File

use hessra_config::HessraConfig;
use std::path::Path;

let config = HessraConfig::from_file(Path::new("./config.json")).unwrap();

Loading from a TOML File

use hessra_config::HessraConfig;
use std::path::Path;

let config = HessraConfig::from_toml(Path::new("./config.toml")).unwrap();

Loading from Environment Variables

use hessra_config::HessraConfig;

// Using the prefix "HESSRA" for environment variables
// Looks for HESSRA_BASE_URL, HESSRA_PORT, etc.
//
// Note: keys and certificates should be in PEM format encoded as base64 strings
// when stored as environment variables
let config = HessraConfig::from_env("HESSRA").unwrap();

Automatic Configuration

Automatically attempt to load configuration from environment variables or standard file locations:

use hessra_config::HessraConfig;

let config = HessraConfig::from_env_or_file("HESSRA").unwrap();

Global Configuration

Set a global configuration that can be accessed throughout your application:

use hessra_config::{HessraConfig, set_default_config, get_default_config};

// Set the global default config
set_default_config(config).unwrap();

// Later, retrieve the global config
if let Some(config) = get_default_config() {
    println!("Using global config: {}", config.base_url);
}

License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.

Commit count: 157

cargo fmt