mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
cloud_requirements PAC support
This commit is contained in:
@@ -6,6 +6,8 @@ use codex_config::CloudConfigFragment;
|
||||
use codex_config::CloudConfigTomlBundle;
|
||||
use codex_config::CloudRequirementsFragment;
|
||||
use codex_config::CloudRequirementsTomlBundle;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::AuthRouteConfig;
|
||||
use codex_login::CodexAuth;
|
||||
use std::future::Future;
|
||||
|
||||
@@ -46,24 +48,34 @@ pub(crate) trait BundleClient: Send + Sync {
|
||||
|
||||
pub(crate) struct BackendBundleClient {
|
||||
base_url: String,
|
||||
auth_route_config: Option<AuthRouteConfig>,
|
||||
}
|
||||
|
||||
impl BackendBundleClient {
|
||||
pub(crate) fn new(base_url: String) -> Self {
|
||||
Self { base_url }
|
||||
pub(crate) fn from_auth_manager(base_url: String, auth_manager: &AuthManager) -> Self {
|
||||
Self {
|
||||
base_url,
|
||||
auth_route_config: auth_manager.auth_route_config().cloned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BundleClient for BackendBundleClient {
|
||||
async fn get_bundle(&self, auth: &CodexAuth) -> Result<CloudConfigBundle, BundleRequestError> {
|
||||
let client = BackendClient::from_auth(self.base_url.clone(), auth)
|
||||
.inspect_err(|err| {
|
||||
tracing::warn!(
|
||||
error = %err,
|
||||
"Failed to construct backend client for cloud config bundle"
|
||||
);
|
||||
})
|
||||
.map_err(|_| BundleRequestError::Retryable(RetryableFailureKind::BackendClientInit))?;
|
||||
let client = BackendClient::from_auth_for_config_bundle(
|
||||
self.base_url.clone(),
|
||||
auth,
|
||||
self.auth_route_config
|
||||
.as_ref()
|
||||
.and_then(AuthRouteConfig::route_config),
|
||||
)
|
||||
.inspect_err(|err| {
|
||||
tracing::warn!(
|
||||
error = %err,
|
||||
"Failed to construct backend client for cloud config bundle"
|
||||
);
|
||||
})
|
||||
.map_err(|_| BundleRequestError::Retryable(RetryableFailureKind::BackendClientInit))?;
|
||||
|
||||
let response = client
|
||||
.get_config_bundle()
|
||||
@@ -134,3 +146,7 @@ fn requirements_fragment_from_delivered(
|
||||
contents: fragment.contents,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "backend_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
use super::*;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_login::AuthRouteConfig;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn cloud_bundle_client_preserves_auto_proxy_config() {
|
||||
let codex_home = tempfile::tempdir().expect("create temp dir");
|
||||
let auth_manager = AuthManager::new_with_auth_route_config(
|
||||
codex_home.path().to_path_buf(),
|
||||
/*enable_codex_api_key_env*/ false,
|
||||
AuthCredentialsStoreMode::File,
|
||||
Some("https://chatgpt.com/backend-api/".to_string()),
|
||||
Some(AuthRouteConfig::auto()),
|
||||
)
|
||||
.await;
|
||||
|
||||
let client = BackendBundleClient::from_auth_manager(
|
||||
"https://chatgpt.com/backend-api/".to_string(),
|
||||
&auth_manager,
|
||||
);
|
||||
|
||||
assert_eq!(client.auth_route_config, Some(AuthRouteConfig::auto()));
|
||||
}
|
||||
@@ -23,9 +23,10 @@ pub fn cloud_config_bundle_loader(
|
||||
chatgpt_base_url: String,
|
||||
codex_home: PathBuf,
|
||||
) -> CloudConfigBundleLoader {
|
||||
let backend_client = BackendBundleClient::from_auth_manager(chatgpt_base_url, &auth_manager);
|
||||
let service = CloudConfigBundleService::new(
|
||||
auth_manager,
|
||||
Arc::new(BackendBundleClient::new(chatgpt_base_url)),
|
||||
Arc::new(backend_client),
|
||||
codex_home,
|
||||
CLOUD_CONFIG_BUNDLE_TIMEOUT,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user