pub struct NifiClient { /* private fields */ }Expand description
Client for the Apache NiFi REST API.
Implementations§
Source§impl NifiClient
impl NifiClient
Sourcepub fn token(&self) -> Option<&str>
pub fn token(&self) -> Option<&str>
Return the current bearer token, if one has been set.
The token is a NiFi-issued JWT. You can persist it between process restarts
and restore it with set_token to avoid re-authenticating.
The token will eventually expire (NiFi default: 12 hours); when it does, any
API call returns NifiError::Api with status == 401. Re-call
login to obtain a fresh token.
Sourcepub fn set_token(&mut self, token: String)
pub fn set_token(&mut self, token: String)
Restore a previously obtained bearer token.
Useful for CLI tools that persist the token in a file between sessions.
If the token has expired, the next API call will return
NifiError::Api with status == 401; re-call login
to obtain a fresh one.
Sourcepub async fn logout(&mut self) -> Result<(), NifiError>
pub async fn logout(&mut self) -> Result<(), NifiError>
Invalidate the current bearer token and clear it from the client.
Sends DELETE /nifi-api/access/logout to invalidate the token server-side,
then clears the local token unconditionally so that subsequent requests are
not sent with a stale credential.
If the server returns an error (e.g. 401 because the token had already
expired) the local token is still cleared and the error is returned to the
caller.
Sourcepub async fn login(
&mut self,
username: &str,
password: &str,
) -> Result<(), NifiError>
pub async fn login( &mut self, username: &str, password: &str, ) -> Result<(), NifiError>
Authenticate with NiFi using single-user credentials.
Obtains a JWT token from /nifi-api/access/token and stores it on the
client for all subsequent requests.
§Token lifetime and expiry
NiFi JWTs expire after 12 hours by default (configurable server-side via
nifi.security.user.login.identity.provider.expiration). Once expired,
any API call returns NifiError::Api with status == 401. The
recommended pattern:
use nifi_rust_client::NifiError;
match client.flow_api().get_about_info().await {
Err(NifiError::Api { status: 401, .. }) => {
client.login("admin", "password").await?;
// retry the call
}
other => { other?; }
}Automatic re-login is not built in: storing credentials on the client would keep plaintext passwords in memory for the lifetime of the process, which is undesirable in most contexts.
Trait Implementations§
Source§impl Clone for NifiClient
impl Clone for NifiClient
Source§fn clone(&self) -> NifiClient
fn clone(&self) -> NifiClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more