mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
backend-client: route requests through HTTP client factory
This commit is contained in:
@@ -12,6 +12,7 @@ base64 = { workspace = true }
|
||||
chrono = { workspace = true, features = ["serde"] }
|
||||
codex-backend-client = { workspace = true }
|
||||
codex-config = { workspace = true }
|
||||
codex-http-client = { workspace = true }
|
||||
codex-core = { workspace = true }
|
||||
codex-login = { workspace = true }
|
||||
codex-otel = { workspace = true }
|
||||
|
||||
@@ -6,6 +6,7 @@ use codex_config::CloudConfigFragment;
|
||||
use codex_config::CloudConfigTomlBundle;
|
||||
use codex_config::CloudRequirementsFragment;
|
||||
use codex_config::CloudRequirementsTomlBundle;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_login::CodexAuth;
|
||||
use std::future::Future;
|
||||
|
||||
@@ -46,24 +47,32 @@ pub(crate) trait BundleClient: Send + Sync {
|
||||
|
||||
pub(crate) struct BackendBundleClient {
|
||||
base_url: String,
|
||||
http_client_factory: HttpClientFactory,
|
||||
}
|
||||
|
||||
impl BackendBundleClient {
|
||||
pub(crate) fn new(base_url: String) -> Self {
|
||||
Self { base_url }
|
||||
pub(crate) fn new(base_url: String, http_client_factory: HttpClientFactory) -> Self {
|
||||
Self {
|
||||
base_url,
|
||||
http_client_factory,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
self.base_url.clone(),
|
||||
auth,
|
||||
self.http_client_factory.clone(),
|
||||
)
|
||||
.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()
|
||||
|
||||
@@ -5,6 +5,8 @@ use codex_config::CloudConfigBundleLoadError;
|
||||
use codex_config::CloudConfigBundleLoadErrorCode;
|
||||
use codex_config::CloudConfigBundleLoader;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
use codex_login::AuthKeyringBackendKind;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::AuthRouteConfig;
|
||||
@@ -23,10 +25,14 @@ pub fn cloud_config_bundle_loader(
|
||||
auth_manager: Arc<AuthManager>,
|
||||
chatgpt_base_url: String,
|
||||
codex_home: PathBuf,
|
||||
http_client_factory: HttpClientFactory,
|
||||
) -> CloudConfigBundleLoader {
|
||||
let service = CloudConfigBundleService::new(
|
||||
auth_manager,
|
||||
Arc::new(BackendBundleClient::new(chatgpt_base_url)),
|
||||
Arc::new(BackendBundleClient::new(
|
||||
chatgpt_base_url,
|
||||
http_client_factory,
|
||||
)),
|
||||
codex_home,
|
||||
CLOUD_CONFIG_BUNDLE_TIMEOUT,
|
||||
);
|
||||
@@ -61,6 +67,10 @@ pub async fn cloud_config_bundle_loader_for_storage(
|
||||
chatgpt_base_url: String,
|
||||
auth_route_config: Option<AuthRouteConfig>,
|
||||
) -> CloudConfigBundleLoader {
|
||||
let http_client_factory = auth_route_config.as_ref().map_or_else(
|
||||
|| HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
|config| config.http_client_factory().clone(),
|
||||
);
|
||||
let auth_manager = AuthManager::shared(
|
||||
codex_home.clone(),
|
||||
enable_codex_api_key_env,
|
||||
@@ -71,5 +81,10 @@ pub async fn cloud_config_bundle_loader_for_storage(
|
||||
auth_route_config,
|
||||
)
|
||||
.await;
|
||||
cloud_config_bundle_loader(auth_manager, chatgpt_base_url, codex_home)
|
||||
cloud_config_bundle_loader(
|
||||
auth_manager,
|
||||
chatgpt_base_url,
|
||||
codex_home,
|
||||
http_client_factory,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user