Hessra Config
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:
[]
= "0.2.0"
Usage
Creating a Configuration Manually
use ;
let config = new;
Using the Builder Pattern
use ;
let config = builder
.base_url
.port
.protocol
.mtls_cert
.mtls_key
.server_ca
.public_key
.personal_keypair
.build
.unwrap;
Loading from a JSON File
use HessraConfig;
use Path;
let config = from_file.unwrap;
Loading from a TOML File
use HessraConfig;
use Path;
let config = from_toml.unwrap;
Loading from Environment Variables
use 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 = from_env.unwrap;
Automatic Configuration
Automatically attempt to load configuration from environment variables or standard file locations:
use HessraConfig;
let config = from_env_or_file.unwrap;
Global Configuration
Set a global configuration that can be accessed throughout your application:
use ;
// Set the global default config
set_default_config.unwrap;
// Later, retrieve the global config
if let Some = get_default_config
License
This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.