pub struct OnePasswordBuilder { /* private fields */ }Expand description
Builder for configuring and creating a OnePassword client.
Use OnePassword::from_env() or OnePassword::from_token() to create a builder,
then configure it and call connect() to establish
the connection.
§Examples
use corteq_onepassword::OnePassword;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// From environment variable
let client = OnePassword::from_env()?
.integration("my-app", "1.0.0")
.connect()
.await?;
// From explicit token (use env var in production)
let token = std::env::var("MY_TOKEN")?;
let client = OnePassword::from_token(&token)?
.integration("my-app", "1.0.0")
.connect()
.await?;
Ok(())
}Implementations§
Source§impl OnePasswordBuilder
impl OnePasswordBuilder
Sourcepub fn integration(self, name: &str, version: &str) -> Self
pub fn integration(self, name: &str, version: &str) -> Self
Set the integration name and version for 1Password audit logs.
This metadata appears in 1Password’s audit logs, helping identify which application is accessing secrets.
If not set, defaults to corteq-onepassword and the crate version.
§Examples
use corteq_onepassword::OnePassword;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = OnePassword::from_env()?
.integration("contact-guard", "2.1.0")
.connect()
.await?;
Ok(())
}Sourcepub async fn connect(self) -> Result<OnePassword>
pub async fn connect(self) -> Result<OnePassword>
Connect to 1Password and create the client.
This establishes a session with 1Password using the configured service account token.
§Errors
Returns an error if:
- The native library cannot be loaded
- Authentication fails (invalid or expired token)
- Network issues prevent connection
§Examples
use corteq_onepassword::OnePassword;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = OnePassword::from_env()?
.connect()
.await?;
Ok(())
}Sourcepub fn connect_blocking(self) -> Result<OnePassword>
pub fn connect_blocking(self) -> Result<OnePassword>
Connect to 1Password synchronously (blocking).
This is equivalent to connect() but blocks the current thread
instead of returning a future.
§Feature Flag
This method requires the blocking feature to be enabled.
§Examples
use corteq_onepassword::OnePassword;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = OnePassword::from_env()?
.connect_blocking()?;
Ok(())
}