1use onepassword_shared::types::{Invocation, InvocationWrapper};
2
3pub mod wrappers;
4
5pub use onepassword_shared::types::ClientConfig;
6pub use onepassword_sys::{Error as FfiError, version};
7pub use wrappers::Client;
8
9pub async fn invoke<T: serde::de::DeserializeOwned>(invocation: Invocation) -> Result<T, FfiError> {
10 let serialized_config = serde_json::to_string(&InvocationWrapper { invocation }).unwrap();
11 let result = onepassword_sys::invoke(&serialized_config).await?;
12 let value = serde_json::from_reader(result.as_ref()).unwrap();
13 Ok(value)
14}
15
16#[cfg(test)]
17mod tests {
18 use super::*;
19
20 const ONEPASS_SERVICE_ACCOUNT_TOKEN: &str =
21 "https://developer.1password.com/docs/service-accounts/get-started";
22
23 #[tokio::test]
24 async fn connect() {
25 let vaults = Client::new(ClientConfig {
26 service_account_token: ONEPASS_SERVICE_ACCOUNT_TOKEN.to_owned(),
27 integration_name: env!("CARGO_PKG_NAME"),
28 integration_version: env!("CARGO_PKG_VERSION"),
29 ..Default::default()
30 })
31 .await
32 .unwrap()
33 .vaults()
34 .await
35 .unwrap();
36
37 eprintln!("{vaults:?}");
38 }
39}