mirror of
https://github.com/openai/codex.git
synced 2026-11-29 00:00:54 +00:00
Thread a stable network owner id through managed proxy credentials and use it to resolve the exact active tool call for blocked network requests. This makes concurrent network approvals attribute deterministically and preserves parent tool item ids downstream. Co-authored-by: Codex <noreply@openai.com>
39 lines
1.3 KiB
Rust
39 lines
1.3 KiB
Rust
use rama_core::extensions::Extensions;
|
|
use rama_core::extensions::ExtensionsRef;
|
|
use rama_http::headers::authorization::AuthoritySync;
|
|
use rama_net::user::Basic;
|
|
use rama_net::user::UserId;
|
|
use rama_net::user::authority::AuthorizeResult;
|
|
use rama_net::user::authority::Authorizer;
|
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
|
pub(crate) struct ProxyOwnerAuthorizer;
|
|
|
|
impl AuthoritySync<Basic, ()> for ProxyOwnerAuthorizer {
|
|
fn authorized(&self, ext: &mut Extensions, credentials: &Basic) -> bool {
|
|
ext.insert(UserId::Username(credentials.username().to_string()));
|
|
true
|
|
}
|
|
}
|
|
|
|
impl Authorizer<Basic> for ProxyOwnerAuthorizer {
|
|
type Error = std::convert::Infallible;
|
|
|
|
async fn authorize(&self, credentials: Basic) -> AuthorizeResult<Basic, Self::Error> {
|
|
let mut extensions = Extensions::new();
|
|
extensions.insert(UserId::Username(credentials.username().to_string()));
|
|
AuthorizeResult {
|
|
credentials,
|
|
result: Ok(Some(extensions)),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(crate) fn network_owner_id<T: ExtensionsRef>(input: &T) -> Option<String> {
|
|
match input.extensions().get::<UserId>() {
|
|
Some(UserId::Username(username)) => Some(username.clone()),
|
|
Some(UserId::Token(token)) => String::from_utf8(token.clone()).ok(),
|
|
Some(UserId::Anonymous) | None => None,
|
|
}
|
|
}
|