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. The returned String is a clone that is
not zeroized on drop — it is your responsibility to persist or destroy
it securely. The in-client copy is zeroized when cleared or when the
client is dropped.
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 an
AuthProvider on the builder to enable
automatic token refresh on 401 responses.
Sourcepub async fn authenticate(&self) -> Result<(), NifiError>
pub async fn authenticate(&self) -> Result<(), NifiError>
Authenticate using the configured AuthProvider.
Returns NifiError::Auth if no auth provider has been configured.