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: booltrue 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: booltrue when Self::git_branch comes from a git checkout|switch
earlier in the same command line.
git_unknown: booltrue 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: booltrue 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: boolThe command pushes every branch (git push --all / --mirror).
git_target_unknown: boolA 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: booltrue when the k8s context could not be determined (kubectl timed
out). Treated as RiskLevel::Elevated — never silently “normal”.
k8s_not_checked: booltrue 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: booltrue 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
impl RuntimeContext
Sourcepub fn filter_for_groups(
&self,
matched_groups: &HashSet<&str>,
config: &ContextConfig,
) -> Self
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":IaCruns against them)
Labels and risk_level are recomputed from the kept signals.
Sourcepub fn refresh(&mut self, config: &ContextConfig)
pub fn refresh(&mut self, config: &ContextConfig)
Recompute labels and risk_level from the signal fields.
Sourcepub fn risk_reasons(&self, config: &ContextConfig) -> Vec<(RiskLevel, String)>
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
impl Clone for RuntimeContext
Source§impl Debug for RuntimeContext
impl Debug for RuntimeContext
Auto Trait Implementations§
impl Forget for RuntimeContext
impl Freeze for RuntimeContext
impl Move for RuntimeContext
impl RefUnwindSafe for RuntimeContext
impl Send for RuntimeContext
impl Sync for RuntimeContext
impl Unpin for RuntimeContext
impl UnsafeUnpin for RuntimeContext
impl UnwindSafe for RuntimeContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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