Struct HessraConfig

pub struct HessraConfig {
    pub base_url: String,
    pub port: Option<u16>,
    pub mtls_cert: String,
    pub mtls_key: String,
    pub server_ca: String,
    pub protocol: Protocol,
    pub public_key: Option<String>,
    pub personal_keypair: Option<String>,
}
Expand description

Configuration for Hessra SDK client

This structure contains all the configuration parameters needed to create a Hessra client. It can be created manually or loaded from various sources.

§Examples

§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
);

§Loading from a JSON file

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

let config = HessraConfig::from_file(Path::new("./config.json"))
    .expect("Failed to load configuration");

§Loading from environment variables

use hessra_config::HessraConfig;

// Assuming the following environment variables are set:
// HESSRA_BASE_URL=https://test.hessra.net
// HESSRA_PORT=443
// HESSRA_MTLS_CERT=<certificate content>
// HESSRA_MTLS_KEY=<key content>
// HESSRA_SERVER_CA=<CA certificate content>
let config = HessraConfig::from_env("HESSRA")
    .expect("Failed to load configuration from environment");

§Using the global configuration

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

// Set up the global configuration
let config = HessraConfig::new(
    "https://test.hessra.net",
    Some(443),
    Protocol::Http1,
    "<certificate content>",
    "<key content>",
    "<CA certificate content>",
);

// Set as the default configuration
set_default_config(config).expect("Failed to set default configuration");

// Later in your code, get the default configuration
let default_config = get_default_config()
    .expect("No default configuration set");

Fields§

§base_url: String§port: Option<u16>§mtls_cert: String§mtls_key: String§server_ca: String§protocol: Protocol§public_key: Option<String>

The server’s public key for token verification as a PEM formatted string

§personal_keypair: Option<String>

The personal keypair for the user as a PEM formatted string

This is used for service chain attestations. When acting as a node in a service chain, this keypair is used to sign attestations that this node has processed the request. The private key should be kept secret and only the public key should be shared with the authorization service.

Implementations§

§

impl HessraConfig

pub fn new( base_url: impl Into<String>, port: Option<u16>, protocol: Protocol, mtls_cert: impl Into<String>, mtls_key: impl Into<String>, server_ca: impl Into<String>, ) -> HessraConfig

Create a new HessraConfig with the given parameters

§Arguments
  • base_url - The base URL for the Hessra service, e.g. “test.hessra.net”
  • port - Optional port to use for the Hessra service, e.g. 443
  • protocol - The protocol to use (HTTP/1.1 or HTTP/3)
  • mtls_cert - The client certificate in PEM format, e.g. “—–BEGIN CERTIFICATE—–\nENV CERT\n—–END CERTIFICATE—–”
  • mtls_key - The client private key in PEM format, e.g. “—–BEGIN PRIVATE KEY—–\nENV KEY\n—–END PRIVATE KEY—–”
  • server_ca - The server CA certificate in PEM format, e.g. “—–BEGIN CERTIFICATE—–\nENV CA\n—–END CERTIFICATE—–”

pub fn builder() -> HessraConfigBuilder

Create a new HessraConfigBuilder

pub fn to_builder(&self) -> HessraConfigBuilder

Convert this config to a builder for modification

pub fn from_file(path: impl AsRef<Path>) -> Result<HessraConfig, ConfigError>

Load configuration from a JSON file

§Arguments
  • path - Path to the JSON configuration file

pub fn from_toml(path: impl AsRef<Path>) -> Result<HessraConfig, ConfigError>

Load configuration from a TOML file

§Arguments
  • path - Path to the TOML configuration file

pub fn from_env(prefix: &str) -> Result<HessraConfig, ConfigError>

Load configuration from environment variables

§Arguments
  • prefix - Prefix for environment variables (e.g., “HESSRA”)
§Environment Variables

The following environment variables are used (with the given prefix):

  • {PREFIX}_BASE_URL - Base URL for the Hessra service
  • {PREFIX}_PORT - Port for the Hessra service (optional)
  • {PREFIX}_PROTOCOL - Protocol to use (“http1” or “http3”)
  • {PREFIX}_MTLS_CERT - Base64-encoded client certificate in PEM format
  • {PREFIX}_MTLS_KEY - Base64-encoded client private key in PEM format
  • {PREFIX}_SERVER_CA - Base64-encoded server CA certificate in PEM format
  • {PREFIX}_PUBLIC_KEY - Base64-encoded server’s public key for token verification (optional)
  • {PREFIX}_PERSONAL_KEYPAIR - Base64-encoded personal keypair in PEM format (optional)

The certificate and key values can also be loaded from files by using:

  • {PREFIX}_MTLS_CERT_FILE - Path to client certificate file
  • {PREFIX}_MTLS_KEY_FILE - Path to client private key file
  • {PREFIX}_SERVER_CA_FILE - Path to server CA certificate file
  • {PREFIX}_PUBLIC_KEY_FILE - Path to server’s public key file
  • {PREFIX}_PERSONAL_KEYPAIR_FILE - Path to personal keypair file

Note: When using environment variables for certificates and keys, the PEM content should be base64-encoded to avoid issues with newlines and special characters in environment variables.

pub fn from_env_or_file(prefix: &str) -> Result<HessraConfig, ConfigError>

Load configuration from environment variables or fall back to a config file

This method will first attempt to load the configuration from environment variables. If that fails, it will look for a configuration file in the following locations:

  1. Path specified in the {PREFIX}_CONFIG_FILE environment variable
  2. ./hessra.json in the current directory
  3. ~/.config/hessra/config.json in the user’s home directory
§Arguments
  • prefix - Prefix for environment variables (e.g., “HESSRA”)

pub fn validate(&self) -> Result<(), ConfigError>

Validate the current configuration

Checks that all required fields are present and have valid values.

Trait Implementations§

§

impl Clone for HessraConfig

§

fn clone(&self) -> HessraConfig

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for HessraConfig

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for HessraConfig

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<HessraConfig, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Serialize for HessraConfig

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T