pub struct TrustGate { /* private fields */ }Expand description
Checks integrations and AI profiles against the trust store.
File-backed gates re-read trust.toml on every use, so a trust run in
another process (or the TUI’s dialog) takes effect at once.
Implementations§
Source§impl TrustGate
impl TrustGate
Sourcepub async fn verify_account(
&self,
integration: &Integration,
client: &dyn HostingClient,
reason: VerifyReason,
) -> Result<()>
pub async fn verify_account( &self, integration: &Integration, client: &dyn HostingClient, reason: VerifyReason, ) -> Result<()>
Compares the account client’s token belongs to with the recorded
one, when VerifyReason says it is due. The id is compared, not
the login (a login can be renamed or re-registered). A record with no
account yet (a migrated one) learns it here.
Sourcepub fn check_account(
&self,
integration: &Integration,
new: &Account,
) -> Result<()>
pub fn check_account( &self, integration: &Integration, new: &Account, ) -> Result<()>
Compares new with the recorded account and, when it is the same one
(or none was recorded yet), refreshes the record. The part of
Self::verify_account for a caller that already holds the account,
from a token check it just ran.
Source§impl TrustGate
impl TrustGate
Sourcepub fn load(paths: &ConfigPaths) -> Self
pub fn load(paths: &ConfigPaths) -> Self
The gate over <private>/trust.toml of paths.
Sourcepub fn ambient() -> Self
pub fn ambient() -> Self
Self::load over the real config directory; with none to be found
the gate keeps its records in memory only.
Sourcepub fn admit(&self, integration: &Integration) -> Result<Admitted>
pub fn admit(&self, integration: &Integration) -> Result<Admitted>
The first two checks, before anything (a token included) is resolved:
plain http, then origin. A record that does not exist yet is made from
the config as it stands: written at once for an integration that was
connected before (the migration: it keeps today’s level of trust),
held in memory for one that never was, until
Self::record_after_check writes it.
Sourcepub fn adopt(&self, integration: &Integration) -> Result<()>
pub fn adopt(&self, integration: &Integration) -> Result<()>
Writes the record of integration now if there is none: for a caller
that holds a token for it (stored, from the environment or from the
credential helper), which is the migration case.
Sourcepub fn preflight(&self, integration: &Integration) -> Result<()>
pub fn preflight(&self, integration: &Integration) -> Result<()>
Self::admit, for a caller that only wants to know it passes
before it resolves a token.
Sourcepub fn record_of(&self, id: &str) -> Option<IntegrationRecord>
pub fn record_of(&self, id: &str) -> Option<IntegrationRecord>
The record of id, if one was written.
Sourcepub fn update_record<R>(
&self,
integration: &Integration,
change: impl FnOnce(&mut IntegrationRecord) -> R,
) -> Result<R>
pub fn update_record<R>( &self, integration: &Integration, change: impl FnOnce(&mut IntegrationRecord) -> R, ) -> Result<R>
Changes the record of integration (made from the config first when
there is none) and writes it. The one door every acceptance goes
through.
Sourcepub fn record_after_check(
&self,
integration: &Integration,
account: &Account,
) -> Result<()>
pub fn record_after_check( &self, integration: &Integration, account: &Account, ) -> Result<()>
Records (or refreshes) the trust of integration after a check that
succeeded: its current address, and the account the token belongs to.
Does not widen anything by itself: Self::admit has already passed
for this address.
Sourcepub fn trust_origin(&self, integration: &Integration) -> Result<()>
pub fn trust_origin(&self, integration: &Integration) -> Result<()>
Accepts the integration’s current address as the trusted one. The account is forgotten with it: another server has other ids.
Sourcepub fn trust_account(
&self,
integration: &Integration,
account: &Account,
) -> Result<()>
pub fn trust_account( &self, integration: &Integration, account: &Account, ) -> Result<()>
Accepts account as the owner of the token.
Sourcepub fn trust_certificate(
&self,
integration: &Integration,
cert: &CertInfo,
mode: TlsMode,
) -> Result<()>
pub fn trust_certificate( &self, integration: &Integration, cert: &CertInfo, mode: TlsMode, ) -> Result<()>
Pins the certificate key of the integration’s host.
Sourcepub fn set_strict(
&self,
integration: &Integration,
strict: bool,
) -> Result<bool>
pub fn set_strict( &self, integration: &Integration, strict: bool, ) -> Result<bool>
Switches the pin between tofu and strict (it needs a pinned key).
pub fn set_allow_plain_http( &self, integration: &Integration, on: bool, ) -> Result<()>
Sourcepub fn admit_ai(
&self,
profile: &str,
base_url: &str,
has_key: bool,
) -> Result<Vec<String>>
pub fn admit_ai( &self, profile: &str, base_url: &str, has_key: bool, ) -> Result<Vec<String>>
The checks of Self::admit for an API-key AI profile bound to
base_url. has_key: a key is stored, so a missing record is written
now (migration); without one it is held in memory until the key is
stored and Self::record_ai runs. Returns the origins a request may
reach.
Sourcepub fn ai_record_of(&self, profile: &str) -> Option<AiRecord>
pub fn ai_record_of(&self, profile: &str) -> Option<AiRecord>
The AI record of profile, if one was written.
Sourcepub fn update_ai_record<R>(
&self,
profile: &str,
base_url: &str,
change: impl FnOnce(&mut AiRecord) -> R,
) -> Result<R>
pub fn update_ai_record<R>( &self, profile: &str, base_url: &str, change: impl FnOnce(&mut AiRecord) -> R, ) -> Result<R>
Changes the AI record of profile (made from base_url first when
there is none) and writes it.