| Crates.io | hessra-config |
| lib.rs | hessra-config |
| version | 0.3.0 |
| created_at | 2025-04-01 19:57:11.292805+00 |
| updated_at | 2025-08-23 17:09:12.206918+00 |
| description | Configuration management for Hessra SDK |
| homepage | |
| repository | https://github.com/Hessra-Labs/hessra-sdk.rs |
| max_upload_size | |
| id | 1615434 |
| size | 70,907 |
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.
Add this to your Cargo.toml:
[dependencies]
hessra-config = "0.2.0"
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
);
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();
use hessra_config::HessraConfig;
use std::path::Path;
let config = HessraConfig::from_file(Path::new("./config.json")).unwrap();
use hessra_config::HessraConfig;
use std::path::Path;
let config = HessraConfig::from_toml(Path::new("./config.toml")).unwrap();
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();
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();
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);
}
This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.