pub struct Client { /* private fields */ }Expand description
Synchronous client for communicating with the whoami daemon.
§Example
use getmyid::Client;
let client = Client::new();
let identity = client.get_identity()?;
println!("Identity: {}", identity.identity);Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new client with default settings.
Uses the default socket path /var/run/whoami.sock.
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Create a client builder for custom configuration.
Sourcepub fn get_identity(&self) -> Result<Identity>
pub fn get_identity(&self) -> Result<Identity>
Get the identity of the current process.
Connects to the whoami daemon, which uses SO_PEERCRED to identify
this process, then matches against configured rules to return the
application-level identity.
§Errors
Returns an error if:
- The socket does not exist or cannot be connected to
- The daemon returns an error (e.g., no matching rule)
- The response cannot be parsed
Sourcepub fn get_identity_with_runner(
&self,
runner: Option<RunnerRequest>,
) -> Result<Identity>
pub fn get_identity_with_runner( &self, runner: Option<RunnerRequest>, ) -> Result<Identity>
Get the identity with client-provided runner context.
The runner request allows you to send context (like instance_id, timestamp)
that will be merged with server-injected identity in the response’s runner object.
§Example
use getmyid::{Client, RunnerRequest};
let client = Client::new();
let runner_req = RunnerRequest::new()
.with_instance_id(42)
.with_current_timestamp();
let identity = client.get_identity_with_runner(Some(runner_req))?;
println!("Instance: {:?}", identity.runner.instance_id);Sourcepub fn socket_path(&self) -> &Path
pub fn socket_path(&self) -> &Path
Get the configured socket path.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnwindSafe for Client
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
Mutably borrows from an owned value. Read more