aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
114
akode-rs/core/src/config/auth_keyring.rs
Normal file
114
akode-rs/core/src/config/auth_keyring.rs
Normal file
@@ -0,0 +1,114 @@
|
||||
use super::Config;
|
||||
use super::ConfigTomlLoadResult;
|
||||
use super::ManagedFeatures;
|
||||
use super::resolve_bootstrap_auth_route_config;
|
||||
use akode_config::types::AuthKeyringBackendKind;
|
||||
use akode_features::Feature;
|
||||
use akode_features::FeatureConfigSource;
|
||||
use akode_features::FeatureOverrides;
|
||||
use akode_features::Features;
|
||||
use akode_login::AuthConfig;
|
||||
use std::path::Path;
|
||||
|
||||
impl Config {
|
||||
pub fn auth_keyring_backend_kind(&self) -> AuthKeyringBackendKind {
|
||||
auth_keyring_backend_kind_from_secret_auth_storage(
|
||||
self.features.enabled(Feature::SecretAuthStorage),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn auth_config(&self) -> AuthConfig {
|
||||
AuthConfig {
|
||||
codex_home: self.codex_home.to_path_buf(),
|
||||
auth_credentials_store_mode: self.cli_auth_credentials_store_mode,
|
||||
keyring_backend_kind: self.auth_keyring_backend_kind(),
|
||||
forced_login_method: self.forced_login_method,
|
||||
managed_auth_policy: self
|
||||
.config_layer_stack
|
||||
.requirements()
|
||||
.managed_auth_policy()
|
||||
.with_forced_chatgpt_workspaces(self.forced_chatgpt_workspace_id.as_deref()),
|
||||
auth_route_config: self.auth_route_config(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds authentication settings from the locally resolved bootstrap config.
|
||||
///
|
||||
/// Use this before the full configuration is loaded, when a full [`Config`] is not
|
||||
/// yet available. Preserves the configured credential store, keyring backend,
|
||||
/// auth routing, and managed login restrictions.
|
||||
pub fn bootstrap_auth_config(
|
||||
codex_home: &Path,
|
||||
bootstrap_config: &ConfigTomlLoadResult,
|
||||
) -> std::io::Result<AuthConfig> {
|
||||
let config = &bootstrap_config.config_toml;
|
||||
let requirements = bootstrap_config.config_layer_stack.requirements();
|
||||
let mut auth_config = AuthConfig {
|
||||
codex_home: codex_home.to_path_buf(),
|
||||
auth_credentials_store_mode: config.cli_auth_credentials_store.unwrap_or_default(),
|
||||
keyring_backend_kind: resolve_bootstrap_auth_keyring_backend_kind(bootstrap_config)?,
|
||||
forced_login_method: config.forced_login_method,
|
||||
managed_auth_policy: requirements
|
||||
.managed_auth_policy()
|
||||
.with_forced_chatgpt_workspaces(
|
||||
config
|
||||
.forced_chatgpt_workspace_id
|
||||
.clone()
|
||||
.and_then(akode_config::config_toml::ForcedChatgptWorkspaceIds::normalized)
|
||||
.as_deref(),
|
||||
),
|
||||
auth_route_config: resolve_bootstrap_auth_route_config(
|
||||
config,
|
||||
requirements.feature_requirements.as_ref(),
|
||||
)?,
|
||||
};
|
||||
if let Some(required) = requirements.cli_auth_credentials_store.as_ref() {
|
||||
auth_config.auth_credentials_store_mode = required.value;
|
||||
}
|
||||
auth_config.validate()?;
|
||||
Ok(auth_config)
|
||||
}
|
||||
|
||||
/// Resolve the auth keyring backend from a partially loaded bootstrap config.
|
||||
///
|
||||
/// This is intended for startup paths that must read auth before managed cloud
|
||||
/// requirements can be loaded and before a full [`Config`] exists.
|
||||
pub fn resolve_bootstrap_auth_keyring_backend_kind(
|
||||
bootstrap_config: &ConfigTomlLoadResult,
|
||||
) -> std::io::Result<AuthKeyringBackendKind> {
|
||||
let config_toml = &bootstrap_config.config_toml;
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: config_toml.features.as_ref(),
|
||||
experimental_use_unified_exec_tool: config_toml.experimental_use_unified_exec_tool,
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
let managed_features = ManagedFeatures::from_configured(
|
||||
features,
|
||||
bootstrap_config
|
||||
.config_layer_stack
|
||||
.requirements()
|
||||
.feature_requirements
|
||||
.clone(),
|
||||
)?;
|
||||
Ok(auth_keyring_backend_kind_from_secret_auth_storage(
|
||||
managed_features.enabled(Feature::SecretAuthStorage),
|
||||
))
|
||||
}
|
||||
|
||||
fn auth_keyring_backend_kind_from_secret_auth_storage(
|
||||
secret_auth_storage_enabled: bool,
|
||||
) -> AuthKeyringBackendKind {
|
||||
if secret_auth_storage_enabled {
|
||||
AuthKeyringBackendKind::Secrets
|
||||
} else {
|
||||
AuthKeyringBackendKind::Direct
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "auth_keyring_tests.rs"]
|
||||
mod tests;
|
||||
Reference in New Issue
Block a user