Skip to main content

CallerContext

Struct CallerContext 

Source
pub struct CallerContext {
    pub key_id: Option<String>,
    pub allowed_acc_ids: Option<Arc<HashSet<u64>>>,
}
Expand description

REST caller scope 快照 (一次 build, 多次透传).

触发位置: route handler 入口, 从 Extension<Arc<KeyRecord>> 抽取.

下游消费者 (统一来源, 防漂移):

  • adapter::proto_request_with_ctxIncomingRequest.caller_* 填充
  • adapter::proto_request_with_ctxFilterRegistry::apply 响应过滤
  • routes::trd::extract_and_resolve_card_num_into_acc_id 共用
  • routes::trd::sub_acc_push / routes::sys::unsub_acc_push 的 per-acc check_full_skip_rate 共用

legacy 模式: key_id = None + allowed_acc_ids = None (无 keys.json / 未鉴权), handler 不 filter / 不审 per-key.

Fields§

§key_id: Option<String>

调用方 API key id (来自 KeyRecord.id). None = legacy mode.

§allowed_acc_ids: Option<Arc<HashSet<u64>>>

调用方 allowed_acc_ids 硬限额快照 (来自 KeyRecord.allowed_acc_ids, SIGHUP-aware, route handler build CallerContext 时一次性 clone). None = 无限制 (legacy / 未配此白名单); Some(non_empty_set) = 受限。Some(empty)futu-auth::RuntimeCounters 历史契约等同 不限制;card_num fail-closed 使用 sentinel {0} 表达 deny-all, 不用 空集合表达 deny-all。

Implementations§

Source§

impl CallerContext

Source

pub fn legacy() -> Self

Legacy mode: 无 caller key, 无 allowed_acc_ids 限制. 用于 unauthenticated route 或 legacy 模式的 fallback 路径.

Source

pub fn from_key_record(rec: Option<&KeyRecord>) -> Self

KeyRecord 构 CallerContext (route handler 入口主用).

rec = None (Extension 缺失, legacy 模式) → 等价 legacy().

Source

pub fn allowed_acc_ids_borrow(&self) -> Option<&HashSet<u64>>

allowed_acc_ids 借引用 (let FilterRegistry::apply 等 borrow 接 API 直接吃). 跟 Arc::as_ref 等价但省 caller 写 .as_ref().map(|a| a.as_ref()).

Source

pub fn caller_allowed_acc_ids_arc(&self) -> Option<Arc<HashSet<u64>>>

caller_allowed_acc_ids 直接 clone Arc 供 IncomingRequest 字段填充 (Arc::clone 成本极低, 不深拷贝 set).

Source

pub fn caller_key_id(&self) -> Option<String>

caller_key_id 直接 clone String 供 IncomingRequest 字段填充.

Source

pub fn key_id_for_audit(&self) -> String

audit log 用的 key_id (None → “” 占位, 与 routes 层惯例一致).

Trait Implementations§

Source§

impl Clone for CallerContext

Source§

fn clone(&self) -> CallerContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CallerContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CallerContext

Source§

fn default() -> CallerContext

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more