pub struct AuthConfig {
pub api_key: Secret<String>,
pub base_url: String,
pub timeout_seconds: u64,
pub max_retries: u32,
pub enable_retry: bool,
pub user_agent: String,
}Expand description
Configuration for authentication and client behavior.
AuthConfig holds all the necessary information for authenticating with the Rainy API,
as well as settings for request behavior like timeouts and retries.
§Examples
use rainy_sdk::auth::AuthConfig;
let config = AuthConfig::new("your-api-key")
.with_base_url("https://api.example.com")
.with_timeout(60)
.with_max_retries(5);
assert_eq!(config.base_url, "https://api.example.com");
assert_eq!(config.timeout_seconds, 60);
assert_eq!(config.max_retries, 5);Fields§
§api_key: Secret<String>The API key used for authenticating with the Rainy API.
base_url: StringThe base URL of the Rainy API. Defaults to the official endpoint.
timeout_seconds: u64The timeout for HTTP requests, in seconds.
max_retries: u32The maximum number of times to retry a failed request.
enable_retry: boolA flag to enable or disable automatic retries with exponential backoff.
user_agent: StringThe user agent string to send with each request.
Implementations§
Source§impl AuthConfig
impl AuthConfig
Sourcepub fn new(api_key: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>) -> Self
Creates a new AuthConfig with the given API key and default settings.
§Arguments
api_key- Your Rainy API key.
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
Sourcepub fn with_timeout(self, seconds: u64) -> Self
pub fn with_timeout(self, seconds: u64) -> Self
Sourcepub fn with_max_retries(self, retries: u32) -> Self
pub fn with_max_retries(self, retries: u32) -> Self
Sets the maximum number of retry attempts for failed requests.
§Arguments
retries- The maximum number of retries.
Sourcepub fn with_retry(self, enable: bool) -> Self
pub fn with_retry(self, enable: bool) -> Self
Enables or disables automatic retries.
§Arguments
enable-trueto enable retries,falseto disable.
Sourcepub fn with_user_agent(self, user_agent: impl Into<String>) -> Self
pub fn with_user_agent(self, user_agent: impl Into<String>) -> Self
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validates the AuthConfig settings.
This method checks for common configuration errors, such as an empty API key or an invalid base URL.
§Returns
A Result that is Ok(()) if the configuration is valid, or a RainyError if it’s not.
Sourcepub fn build_headers(&self) -> Result<HeaderMap>
pub fn build_headers(&self) -> Result<HeaderMap>
Builds the necessary HTTP headers for an API request.
This method constructs a HeaderMap containing the Authorization and User-Agent
headers based on the AuthConfig.
§Returns
A Result containing the HeaderMap or a RainyError if header creation fails.
Trait Implementations§
Source§impl Clone for AuthConfig
impl Clone for AuthConfig
Source§fn clone(&self) -> AuthConfig
fn clone(&self) -> AuthConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AuthConfig
impl Debug for AuthConfig
Auto Trait Implementations§
impl Freeze for AuthConfig
impl RefUnwindSafe for AuthConfig
impl Send for AuthConfig
impl Sync for AuthConfig
impl Unpin for AuthConfig
impl UnwindSafe for AuthConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.