Skip to main content

ToolContext

Struct ToolContext 

Source
pub struct ToolContext {
    pub local: Arc<dyn LocalBackend>,
    pub redactor: Redactor,
    pub max_result_bytes: usize,
    pub identity: Identity,
    pub cli_version: Option<Version>,
    pub paths: PathPolicy,
    pub devices: DeviceCache,
    pub max_tier: Tier,
    /* private fields */
}
Expand description

Everything a handler may reach.

Fields§

§local: Arc<dyn LocalBackend>

The local node. Present even when the local surface is disabled, in which case it is a backend that reports the binary as missing.

§redactor: Redactor

Removes secrets from anything on its way out.

§max_result_bytes: usize

The size above which a result is refused rather than truncated.

§identity: Identity

Who we are on the tailnet, when we could find out.

§cli_version: Option<Version>

The version the local CLI reports, when it could be read.

§paths: PathPolicy

Where the tools that take a path are allowed to write.

§devices: DeviceCache

The tailnet’s device list, cached for a few seconds.

The only mutable state a session holds. It exists because two features ask the same question repeatedly — which device did you mean, and which could you have meant — and neither should cost a request each time.

§max_tier: Tier

The most dangerous tier this session permits.

The gate is what normally applies this, before a handler is reached, so no typed tool has to look at it. The passthrough does: its row carries a floor rather than its real tier, so it is the one tool that has to make the same decision the gate makes, against the command it was given.

Implementations§

Source§

impl ToolContext

Source

pub async fn tailnet_devices(&self) -> ToolResult<Arc<[Device]>>

The tailnet’s devices, from the cache when it is warm enough.

The error is the one the caller would have got anyway: without a credential this is the missing-credential sentence, and a control-plane failure is reported as itself rather than as an absent device.

Source

pub async fn names_us(&self, target: &str) -> bool

Whether target names the node this server runs on.

Two sources, because the control plane accepts two identifiers for the same device and the local node only knows one of them. Status gives the node id, the addresses and the name, and is re-read as it ages. The numeric id has to be asked of the control plane — and is, only when the answer could turn on it: a target that is not all digits is not a numeric id, so the overwhelming majority of calls cost nothing extra, and the one that does costs one request per process (Q87).

Source

pub fn tailnet(&self) -> ToolResult<&Client>

The control plane, or the reason there is none.

Trait Implementations§

Source§

impl Clone for ToolContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ToolContext

Source§

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

Formats the value using the given formatter. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

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

impl<T> Instrument for T

Source§

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

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

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.

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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