RootCommandContext during CLI initialization, which then governs the behavior of all subsequent commands.
Connection Profiles
A Profile is a named set of configuration parameters that defines how the CLI communicates with apalyrad gateway. Profiles are stored in a TOML registry, typically located at cli/profiles.toml within the state root crates/palyra-cli/src/app/mod.rs#26-26.
Profile Structure
TheCliConnectionProfile struct defines the schema for these entries:
| Field | Description |
|---|---|
daemon_url | The HTTP URL of the gateway (e.g., http://127.0.0.1:7142) crates/palyra-cli/src/app/mod.rs#96-96. |
grpc_url | The gRPC endpoint for high-performance RPC calls crates/palyra-cli/src/app/mod.rs#97-97. |
admin_token_env | Environment variable name holding the administrative bearer token crates/palyra-cli/src/app/mod.rs#99-99. |
risk_level | Categorization of the environment (e.g., low, elevated, high) crates/palyra-cli/src/app/mod.rs#106-106. |
strict_mode | Boolean flag enabling aggressive safety guardrails crates/palyra-cli/src/app/mod.rs#108-108. |
state_root | Custom filesystem path for profile-specific data crates/palyra-cli/src/app/mod.rs#95-95. |
Profile Data Flow
The following diagram illustrates how a profile is selected and transformed into an active runtime context. Profile Resolution and Context Injection Sources: crates/palyra-cli/src/app/mod.rs#145-161, crates/palyra-cli/src/lib.rs#76-89Root Context Initialization
Theapp::install_root_context function is the entry point for CLI lifecycle management crates/palyra-cli/src/app/mod.rs#151-157. It consumes RootOptions (global flags like --profile, --config, and --state-root) and produces a RootCommandContext.
Initialization Logic
- Profile Selection: If
--profileis provided, it loads that specific profile from the registry. If not, it checks thePALYRA_CLI_PROFILEenvironment variable, falling back to thedefault_profiledefined inprofiles.tomlcrates/palyra-cli/src/app/mod.rs#24-26. - Configuration Merging: It merges profile-specific URLs and tokens with any command-line overrides (e.g.,
--daemon-url). - Trace ID Generation: A unique ULID
trace_idis generated for the context to provide request correlation across gateway logs crates/palyra-cli/src/app/mod.rs#41-41. - Global Storage: The resulting context is stored in a
OnceLock<Mutex<Option<RootCommandContext>>>crates/palyra-cli/src/app/mod.rs#145-145, allowing any downstream command to access it viacurrent_root_context()crates/palyra-cli/src/app/mod.rs#159-161.
Guardrails and Strict Mode
Palyra implements “Guardrails” to prevent accidental destructive actions on sensitive environments. This is controlled by therisk_level and strict_mode fields.
Risk Levels
Profiles can be assigned one of the following risk levels crates/palyra-cli/src/args/profile.rs#101-101:- Low: Local development or ephemeral sandboxes.
- Elevated: Shared staging or QA environments.
- High: Production clusters or sensitive data environments.
Strict Mode Enforcement
Whenstrict_mode is enabled (standard for high risk profiles), the CLI activates the enforce_profile_guardrails mechanism. This results in:
- Mandatory Confirmation: Destructive commands (like
resetordelete) require the--yesflag AND the--allow-strict-profile-actionsglobal flag crates/palyra-cli/src/args/mod.rs#135-135. - Profile Expectation Check: Users can pass
--expect-profile <NAME>to ensure the command only executes if the active profile matches the expectation, preventing “wrong terminal” accidents crates/palyra-cli/tests/help_snapshots/root-help-unix.txt#65-65. - Credential Isolation: Strict profiles often use
admin_token_envinstead of storing tokens in plaintext, forcing the use of secure environment secret injection crates/palyra-cli/src/app/mod.rs#99-99.
Profile Lifecycle Management
Thepalyra profile command family manages the registry crates/palyra-cli/src/commands/profile.rs#215-216.
Clone, Import, and Export
Palyra supports portable profile bundles for team onboarding and environment synchronization.- Clone: Creates a new profile by copying an existing one, allowing for quick derivation (e.g.,
prod->prod-read-only) crates/palyra-cli/src/commands/profile.rs#186-197. - Export: Serializes a profile into a
ProfilePortabilityBundlecrates/palyra-cli/src/commands/profile.rs#141-149.- Encrypted Mode: Uses
AES-256-GCMwithPBKDF2-HMAC-SHA256key derivation (120,000 iterations) to protect sensitive URLs and configuration snippets during transit crates/palyra-cli/src/commands/profile.rs#24-32.
- Encrypted Mode: Uses
- Import: Reconstitutes a profile from a bundle, validating the schema and ensuring that local
state_rootpaths do not conflict with existing data crates/palyra-cli/src/commands/profile.rs#206-213.
Implementation Detail: Portability
Sources: crates/palyra-cli/src/commands/profile.rs#107-161Implementation Mapping
| System Concept | Code Entity | File Location |
|---|---|---|
| Profile Registry | CliProfilesDocument | crates/palyra-cli/src/app/mod.rs#84-89 |
| Active Context | RootCommandContext | crates/palyra-cli/src/app/mod.rs#34-45 |
| Global State Storage | ROOT_CONTEXT | crates/palyra-cli/src/app/mod.rs#145-145 |
| Guardrail Logic | RootCommandContext::allow_strict_profile_actions | crates/palyra-cli/src/app/mod.rs#192-194 |
| Profile CLI | run_profile | crates/palyra-cli/src/commands/profile.rs#215-216 |
| Encryption Params | PROFILE_EXPORT_PBKDF2_ITERATIONS | crates/palyra-cli/src/commands/profile.rs#27-27 |