Config

Struct Config 

Source
pub struct Config {
    pub api_url: String,
    pub token: Option<String>,
    pub timeout: Duration,
    pub max_retries: u32,
    pub user_agent: String,
    pub verify_ssl: bool,
}
Expand description

Configuration for the Zero Trust SDK

Fields§

§api_url: String

API base URL

§token: Option<String>

Authentication token (JWT)

§timeout: Duration

Request timeout duration

§max_retries: u32

Maximum retry attempts

§user_agent: String

User agent string

§verify_ssl: bool

Whether to verify SSL certificates

Implementations§

Source§

impl Config

Source

pub fn new<S: AsRef<str>>(api_url: S) -> Result<Self>

Create a new configuration with the given API URL

§Arguments
  • api_url - The base URL for the Zero Trust API
§Examples
use zero_trust_sdk::Config;

let config = Config::new("https://api.zerotrust.com").unwrap();
assert_eq!(config.api_url, "https://api.zerotrust.com");
Source

pub fn with_token<S: Into<String>>(self, token: S) -> Self

Set the authentication token

§Arguments
  • token - JWT authentication token
§Examples
use zero_trust_sdk::Config;

let config = Config::new("https://api.zerotrust.com")
    .unwrap()
    .with_token("eyJ0eXAiOiJKV1Q...");
Source

pub fn with_timeout(self, timeout: Duration) -> Self

Set the request timeout

§Arguments
  • timeout - Request timeout duration
§Examples
use zero_trust_sdk::Config;
use std::time::Duration;

let config = Config::new("https://api.zerotrust.com")
    .unwrap()
    .with_timeout(Duration::from_secs(60));
Source

pub fn with_max_retries(self, max_retries: u32) -> Self

Set the maximum retry attempts

§Arguments
  • max_retries - Maximum number of retry attempts
§Examples
use zero_trust_sdk::Config;

let config = Config::new("https://api.zerotrust.com")
    .unwrap()
    .with_max_retries(5);
Source

pub fn with_user_agent<S: Into<String>>(self, user_agent: S) -> Self

Set the user agent string

§Arguments
  • user_agent - User agent string for HTTP requests
§Examples
use zero_trust_sdk::Config;

let config = Config::new("https://api.zerotrust.com")
    .unwrap()
    .with_user_agent("my-app/1.0");
Source

pub fn disable_ssl_verification(self) -> Self

Disable SSL verification (for testing only)

§Examples
use zero_trust_sdk::Config;

let config = Config::new("https://api.zerotrust.com")
    .unwrap()
    .disable_ssl_verification();
Source

pub fn from_env() -> Result<Self>

Load configuration from environment variables

Environment variables:

  • ZEROTRUST_API_URL - API base URL
  • ZEROTRUST_TOKEN - Authentication token
  • ZEROTRUST_TIMEOUT - Request timeout in seconds
  • ZEROTRUST_MAX_RETRIES - Maximum retry attempts
§Examples
use zero_trust_sdk::Config;

// Set environment variable: ZEROTRUST_API_URL=https://api.zerotrust.com
let config = Config::from_env().unwrap();
Source

pub fn from_file(path: &Path) -> Result<Self>

Load configuration from a TOML file

§Arguments
  • path - Path to the TOML configuration file
§Examples
use zero_trust_sdk::Config;
use std::path::Path;

let config = Config::from_file(Path::new("config.toml")).unwrap();
Source

pub fn save_to_file(&self, path: &Path) -> Result<()>

Save configuration to a TOML file

§Arguments
  • path - Path where to save the configuration file
§Examples
use zero_trust_sdk::Config;
use std::path::Path;

let config = Config::new("https://api.zerotrust.com").unwrap();
config.save_to_file(Path::new("config.toml")).unwrap();
Source

pub fn default_config_path() -> Result<PathBuf>

Get the default config file path

Returns ~/.config/zerotrust/config.toml on Unix systems or %APPDATA%/zerotrust/config.toml on Windows

Source

pub fn load_default() -> Result<Self>

Load configuration from the default config file path

§Examples
use zero_trust_sdk::Config;

let config = Config::load_default().unwrap();
Source

pub fn save_default(&self) -> Result<()>

Save configuration to the default config file path

§Examples
use zero_trust_sdk::Config;

let config = Config::new("https://api.zerotrust.com").unwrap();
config.save_default().unwrap();
Source

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

Validate the configuration

Source

pub fn base_url(&self) -> &str

Get the base URL for API requests

Source

pub fn is_authenticated(&self) -> bool

Check if authentication token is present

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config

Source§

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

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

impl Serialize for Config

Source§

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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.

Source§

impl<T> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

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>,

Source§

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