Skip to main content

RuntimeContext

Struct RuntimeContext 

Source
pub struct RuntimeContext {
Show 27 fields pub is_ssh: bool, pub is_root: bool, pub root_via_sudo: bool, pub root_via: Option<String>, pub k8s_switch_attempt: Option<String>, pub git_branch: Option<String>, pub git_branch_switched: bool, pub git_unknown: bool, pub git_targets: Vec<String>, pub git_ignore_current_branch: bool, pub git_push_all: bool, pub git_target_unknown: bool, pub k8s_context: Option<String>, pub k8s_unknown: bool, pub k8s_not_checked: bool, pub k8s_namespace: Option<String>, pub aws_profile: Option<String>, pub tf_workspace: Option<String>, pub tf_unknown: bool, pub gcp_project: Option<String>, pub azure_subscription: Option<String>, pub cluster: Option<String>, pub remote_hosts: Vec<String>, pub sensitive_paths: Vec<String>, pub env_signals: Vec<String>, pub risk_level: RiskLevel, pub labels: Vec<String>,
}
Expand description

Snapshot of environment context at the time a command is evaluated.

Fields§

§is_ssh: bool§is_root: bool§root_via_sudo: bool

true when root comes from a sudo/doas prefix in the command rather than from the process’ effective uid.

§root_via: Option<String>

The wrapper that runs the command as root (sudo, doas, su, pkexec, runuser, nsenter), when Self::root_via_sudo.

§k8s_switch_attempt: Option<String>

The k8s context a switch earlier in the line tried to select when Self::k8s_context was kept because that switch may have failed (kubectx dev; kubectl delete …).

§git_branch: Option<String>

The branch the command runs on: the checked-out branch, or the branch an earlier git checkout|switch B in the same line switches to.

§git_branch_switched: bool

true when Self::git_branch comes from a git checkout|switch earlier in the same command line.

§git_unknown: bool

true when the checked-out branch could not be determined (git did not answer in time). Treated as RiskLevel::Elevated — never silently “normal”.

§git_targets: Vec<String>

Branches the command explicitly targets (push destination, git branch -D <name>, …).

§git_ignore_current_branch: bool

true when the checked-out branch is irrelevant for protected-branch escalation: every git invocation names its targets explicitly (e.g. git push -f origin feature/x while sitting on main) or only does local work that neither rewrites, pushes nor deletes the branch (cherry-pick, rebase -i, stash clear, gc, …).

§git_push_all: bool

The command pushes every branch (git push --all / --mirror).

§git_target_unknown: bool

A push target that is only known when the line runs (origin $B with B unset, $(cat file), "$@"), in a repository that has a protected branch: it may be one of them. Shown as target=unknown (never as a branch name it may not be) and escalated like a protected branch.

§k8s_context: Option<String>§k8s_unknown: bool

true when the k8s context could not be determined (kubectl timed out). Treated as RiskLevel::Elevated — never silently “normal”.

§k8s_not_checked: bool

true when the k8s context was not checked (--no-context and no kubeconfig file to read). Shown as k8s=not checked.

§k8s_namespace: Option<String>

k8s namespace named by the command (-n prod, kubens prod).

§aws_profile: Option<String>

AWS profile (--profile, AWS_PROFILE).

§tf_workspace: Option<String>

Terraform workspace (TF_WORKSPACE, terraform workspace select).

§tf_unknown: bool

true when the terraform working directory is only known when the command runs (terraform -chdir=$ENV destroy), so its workspace is unknown. Treated as RiskLevel::Elevated.

§gcp_project: Option<String>

gcloud project (--project, gcloud config set project, CLOUDSDK_CORE_PROJECT).

§azure_subscription: Option<String>

Azure subscription (--subscription, az account set).

§cluster: Option<String>

A Kubernetes cluster the command deletes or changes by name (eksctl delete cluster --name prod, gcloud container clusters delete prod-gke).

§remote_hosts: Vec<String>

Hosts the command runs on remotely (ssh host ...).

§sensitive_paths: Vec<String>

context.sensitive_paths entries that the command deletes or overwrites (or deletes a parent of).

§env_signals: Vec<String>§risk_level: RiskLevel§labels: Vec<String>

Human-readable labels shown in the banner (e.g. “branch=main”).

Implementations§

Source§

impl RuntimeContext

Source

pub fn filter_for_groups( &self, matched_groups: &HashSet<&str>, config: &ContextConfig, ) -> Self

Return a filtered copy that only contains signals relevant to the matched check groups.

Global signals (is_ssh, is_root, env_signals, remote hosts and sensitive paths) are always kept — they apply regardless of what command matched.

Domain signals are kept only when the corresponding group is present in matched_groups:

  • git branch / targets / push-all → "git"
  • k8s context / namespace → "kubernetes"
  • AWS profile → "aws", terraform workspace → "terraform", gcloud project → "gcp", Azure subscription → "azure" (the cloud signals are also kept for "terraform": IaC runs against them)

Labels and risk_level are recomputed from the kept signals.

Source

pub fn refresh(&mut self, config: &ContextConfig)

Recompute labels and risk_level from the signal fields.

Source

pub fn risk_reasons(&self, config: &ContextConfig) -> Vec<(RiskLevel, String)>

Human-readable reasons behind the risk level, each tagged with the level it contributes. Empty when the context is RiskLevel::Normal.

Trait Implementations§

Source§

impl Clone for RuntimeContext

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 RuntimeContext

Source§

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

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

impl Default for RuntimeContext

Source§

fn default() -> Self

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.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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