ClientConfig

Struct ClientConfig 

Source
pub struct ClientConfig { /* private fields */ }
Expand description

Gmail client configuration containing OAuth2 credentials and persistence settings.

This struct holds all necessary configuration for Gmail API authentication and client setup, including OAuth2 application secrets, configuration directory paths, and token persistence settings.

§Fields

The struct contains private fields that are accessed through getter methods to ensure proper encapsulation and prevent accidental mutation of sensitive configuration data.

§Security

The secret field contains sensitive OAuth2 credentials including client secrets. These values are never logged or exposed in debug output beyond their type information.

§Thread Safety

ClientConfig is safe to clone and use across threads. All contained data is either immutable or safely clonable.

§Examples

use cull_gmail::ClientConfig;

// Create configuration with builder pattern
let config = ClientConfig::builder()
    .with_client_id("test-client-id")
    .with_client_secret("test-secret")
    .build();

// Access configuration values
assert_eq!(config.secret().client_id, "test-client-id");
assert!(config.persist_path().contains("gmail1"));

Implementations§

Source§

impl ClientConfig

Source

pub fn builder() -> ConfigBuilder

Creates a new configuration builder for constructing ClientConfig instances.

The builder pattern allows for flexible configuration construction with method chaining. This is the preferred way to create new configurations as it provides compile-time guarantees about required fields and allows for incremental configuration building.

§Returns

A new ConfigBuilder instance initialized with sensible defaults.

§Examples
use cull_gmail::ClientConfig;

let config = ClientConfig::builder()
    .with_client_id("your-client-id")
    .with_client_secret("your-secret")
    .build();
Source

pub fn new_from_configuration(configs: Config) -> Result<Self>

Creates a new ClientConfig from an external configuration source.

This method supports hierarchical configuration loading with the following priority:

  1. Direct OAuth2 parameters (client_id, client_secret, token_uri, auth_uri)
  2. Credential file specified via credential_file parameter
§Configuration Parameters
§Required Parameters (one of these sets):

Direct OAuth2 Configuration:

  • client_id: OAuth2 client identifier
  • client_secret: OAuth2 client secret
  • token_uri: Token exchange endpoint URL
  • auth_uri: Authorization endpoint URL

OR

File-based Configuration:

  • credential_file: Path to JSON credential file (relative to config_root)
§Always Required:
  • config_root: Base directory for configuration files (supports path prefixes)
§Arguments
  • configs - Configuration object containing OAuth2 and path settings
§Returns

Returns Ok(ClientConfig) on successful configuration loading, or an error if:

  • Required configuration parameters are missing
  • Credential file cannot be read or parsed
  • OAuth2 credential structure is invalid
§Errors

This method can return errors for:

  • Missing required configuration keys
  • File I/O errors when reading credential files
  • JSON parsing errors for malformed credential files
  • Invalid OAuth2 credential structure
§Examples
use cull_gmail::ClientConfig;
use config::Config;

// Configuration with credential file
let app_config = Config::builder()
    .set_default("credential_file", "client_secret.json")?
    .set_default("config_root", "h:.cull-gmail")?
    .build()?;

let client_config = ClientConfig::new_from_configuration(app_config)?;
use cull_gmail::ClientConfig;
use config::Config;

// Configuration with direct OAuth2 parameters
let app_config = Config::builder()
    .set_default("client_id", "your-client-id")?
    .set_default("client_secret", "your-secret")?
    .set_default("token_uri", "https://oauth2.googleapis.com/token")?
    .set_default("auth_uri", "https://accounts.google.com/o/oauth2/auth")?
    .set_default("config_root", "h:.cull-gmail")?
    .build()?;

let client_config = ClientConfig::new_from_configuration(app_config)?;
Source

pub fn secret(&self) -> &ApplicationSecret

Returns a reference to the OAuth2 application secret.

This provides access to the OAuth2 credentials including client ID, client secret, and endpoint URLs required for Gmail API authentication.

§Security Note

The returned ApplicationSecret contains sensitive information including the OAuth2 client secret. Handle this data carefully and avoid logging or exposing it.

§Examples
use cull_gmail::ClientConfig;

let config = ClientConfig::builder()
    .with_client_id("test-client-id")
    .build();

let secret = config.secret();
assert_eq!(secret.client_id, "test-client-id");
Source

pub fn persist_path(&self) -> &str

Returns the full path where OAuth2 tokens should be persisted.

This path is used by the OAuth2 library to store and retrieve cached tokens, enabling automatic token refresh without requiring user re-authentication.

§Path Format

The path typically follows the pattern: {config_root}/gmail1

For example:

  • ~/.cull-gmail/gmail1 (when config_root is h:.cull-gmail)
  • /etc/cull-gmail/gmail1 (when config_root is r:etc/cull-gmail)
§Examples
use cull_gmail::ClientConfig;

let config = ClientConfig::builder().build();
let persist_path = config.persist_path();
assert!(persist_path.contains("gmail1"));
Source

pub fn config_root(&self) -> &ConfigRoot

Returns a reference to the configuration root path resolver.

The ConfigRoot handles path resolution with support for different base directories including home directory, system root, and current working directory.

§Examples
use cull_gmail::ClientConfig;

let config = ClientConfig::builder()
    .with_config_path(".cull-gmail")
    .build();

let config_root = config.config_root();
// config_root can be used to resolve additional paths
Source

pub fn full_path(&self) -> String

Returns the fully resolved configuration directory path as a string.

This method resolves the configuration root path to an absolute path string, applying any path prefix resolution (home directory, system root, etc.).

§Examples
use cull_gmail::ClientConfig;

let config = ClientConfig::builder()
    .with_config_path(".cull-gmail")
    .build();

let full_path = config.full_path();
// Returns the absolute path to the configuration directory

Trait Implementations§

Source§

impl Debug for ClientConfig

Source§

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

Formats the value using the given formatter. 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> 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, 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<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> ErasedDestructor for T
where T: 'static,