Skip to content

refactor!: isolate Signer::with_context cache and pass Context to default_signer - #974

Merged
Xuanwo merged 2 commits into
mainfrom
xuanwo/explicit-context-and-cache-isolation
Nov 20, 2026
Merged

Xuanwo merged 2 commits into
mainfrom
xuanwo/explicit-context-and-cache-isolation

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Nov 20, 2026

Copy link
Copy Markdown
Member

Summary

Two breaking API refinements around Context ownership and lifecycle in reqsign-core and the reqsign facade:

  1. Isolate and clear credential cache on Signer::with_context (core/src/signer.rs):

    • Signer::with_context now creates a new isolated empty credential cache (Arc::new(Mutex::new(None))), matching Granter::with_context and Signer::with_credential_provider.
    • Because Context carries Env, FileRead, CommandExecute, and HttpSend, replacing it can change the resolved identity; sharing the previous cache risked reusing stale credentials or writing refreshed credentials back into the original Signer.
    • Replacing only the signing operation (with_request_signer / with_credential_granter) continues to share the credential cache.
  2. Pass Context explicitly to facade default_signer and remove the default-context feature gate (reqsign/src/*.rs):

    • Every per-service reqsign::<service>::default_signer now accepts ctx: Context as its first parameter (aws::default_signer(ctx, service, region), aws::v4a::default_signer(ctx, service, region_set), azure::default_signer(ctx), google::default_signer(ctx, service), aliyun::default_signer(ctx, bucket), huaweicloud::default_signer(ctx, bucket), openstack::default_signer(ctx), oracle::default_signer(ctx), tencent::default_signer(ctx), volcengine::default_signer(ctx, region)).
    • Both DefaultSigner and default_signer are now available whenever the corresponding service feature is enabled, without requiring default-context (including WASM and custom runtime builds).
    • Callers can share a single Context (and its HTTP client / connection pool) across multiple signers and granters instead of implicitly constructing a new reqwest::Client per default_signer call.

Migration

Before:

use reqsign::aws;

let signer = aws::default_signer("s3", "us-east-1");

After:

use reqsign::{aws, default_context};

let ctx = default_context();
let signer = aws::default_signer(ctx, "s3", "us-east-1");

Callers who relied on Signer::with_context reusing the previous cached credential should either configure Context before constructing Signer or expect the replacement Signer to load fresh credentials under the new Context.

Validation

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --no-fail-fast
  • cargo test -p reqsign --no-default-features --features full
  • cargo test --doc --all-features --workspace
  • cargo test --doc -p reqsign --no-default-features --features full
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace --all-features
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p reqsign --no-default-features --features full
  • cargo check -p reqsign --examples --all-features
  • cargo check -p reqsign-core --target wasm32-unknown-unknown
  • cargo build --manifest-path reqsign/Cargo.toml --target wasm32-unknown-unknown --no-default-features --features=aws,aws-v4a,azure,aliyun,tencent
  • cargo build --manifest-path reqsign/Cargo.toml --target wasm32-unknown-unknown --no-default-features --features=default-context,aws,aws-v4a,azure,aliyun,tencent
  • node website/scripts/validate-providers.mjs
  • hawkeye check

Explain that replacing a signer's Context clears its credential cache, and document that with_request_signer retains the shared cache.
@Xuanwo
Xuanwo merged commit 0a62343 into main Nov 20, 2026
63 checks passed
@Xuanwo
Xuanwo deleted the xuanwo/explicit-context-and-cache-isolation branch November 20, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants