pub struct NifiClient { /* private fields */ }Expand description
Client for the Apache NiFi REST API.
Implementations§
Source§impl NifiClient
impl NifiClient
Sourcepub async fn token(&self) -> Option<String>
pub async fn token(&self) -> Option<String>
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::Unauthorized. Re-call
login to obtain a fresh token.
Sourcepub async fn set_token(&self, token: String)
pub async fn set_token(&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::Unauthorized; re-call login
to obtain a fresh one.
Sourcepub async fn logout(&self) -> Result<(), NifiError>
pub async fn logout(&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(
&self,
username: &str,
password: &str,
) -> Result<(), NifiError>
pub async fn login( &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::Unauthorized. Configure a
CredentialProvider on the builder to enable
automatic token refresh on 401 responses.
Sourcepub async fn login_with_provider(&self) -> Result<(), NifiError>
pub async fn login_with_provider(&self) -> Result<(), NifiError>
Authenticate using the configured CredentialProvider.
Returns NifiError::Auth if no credential provider has been configured.