tapis-core 0.3.1

Shared traits and types for the Tapis Rust SDK.
Documentation
  • Coverage
  • 75%
    3 out of 4 items documented1 out of 2 items with examples
  • Size
  • Source code size: 7.69 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.11 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 40s Average build duration of successful builds.
  • all releases: 57s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • zhangwei217245

tapis-core

Crates.io Documentation License

Shared traits and types for the Tapis Rust SDK.

This crate is intentionally small and has no HTTP or network dependencies. It exists solely to break the circular-dependency problem that would arise if service crates directly referenced tapis-authenticator for token refresh.

What's in this crate

TokenProvider

An async trait that defines the contract for obtaining a fresh Tapis JWT:

#[async_trait::async_trait]
pub trait TokenProvider: Send + Sync {
    async fn get_token(&self) -> Option<String>;
}

Return Some(jwt_string) to supply a fresh token, or None to leave the current token unchanged (e.g., on a transient error).

Dependency graph

tapis-jobs ──dep──> tapis-core <──impl── tapis-authenticator
tapis-systems ────>     ▲
tapis-apps ───────>     │
...                (no service crate depends on tapis-authenticator)

tapis-authenticator can implement TokenProvider and pass it into any service client without creating a cycle.

Usage

Add to your Cargo.toml:

[dependencies]
tapis-core = "0.3.1"
async-trait = "0.1"

Implement the trait on any type that can produce a token:

use std::sync::Arc;
use async_trait::async_trait;
use tapis_core::TokenProvider;

struct StaticToken(String);

#[async_trait]
impl TokenProvider for StaticToken {
    async fn get_token(&self) -> Option<String> {
        Some(self.0.clone())
    }
}

Then pass it to any service client constructor:

use tapis_jobs::TapisJobs;

let provider: Arc<dyn TokenProvider> = Arc::new(StaticToken("my-jwt".into()));
let jobs = TapisJobs::with_token_provider(&base_url, None, provider)?;

Note: If you are using the umbrella crate, TokenProvider is re-exported as tapis_sdk::core::TokenProvider — you do not need to add tapis-core as a direct dependency.

Infinite-loop protection

RefreshMiddleware (in each service crate) skips the refresh call when the outgoing request URL contains /oauth2/tokens or /v3/tokens, preventing the token provider from recursively triggering itself.

License

BSD-3-Clause. See LICENSE.