mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
fix: satisfy vertex transport lint checks
This commit is contained in:
@@ -206,10 +206,7 @@ impl LocalOAuthRefreshAdapter for VertexServiceAccountRefreshAdapter {
|
||||
let now = aether_oauth::core::current_unix_secs();
|
||||
let assertion = build_vertex_service_account_assertion(&auth_config, now)?;
|
||||
let body = form_urlencoded::Serializer::new(String::new())
|
||||
.append_pair(
|
||||
"grant_type",
|
||||
"urn:ietf:params:oauth:grant-type:jwt-bearer",
|
||||
)
|
||||
.append_pair("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
|
||||
.append_pair("assertion", &assertion)
|
||||
.finish();
|
||||
let response = executor
|
||||
@@ -236,13 +233,12 @@ impl LocalOAuthRefreshAdapter for VertexServiceAccountRefreshAdapter {
|
||||
body_excerpt: body_excerpt(&response.body_text),
|
||||
});
|
||||
}
|
||||
let body_json: Value =
|
||||
serde_json::from_str(&response.body_text).map_err(|err| {
|
||||
LocalOAuthRefreshError::InvalidResponse {
|
||||
provider_type: VERTEX_SERVICE_ACCOUNT_PROVIDER_TYPE,
|
||||
message: format!("vertex service account token response is not JSON: {err}"),
|
||||
}
|
||||
})?;
|
||||
let body_json: Value = serde_json::from_str(&response.body_text).map_err(|err| {
|
||||
LocalOAuthRefreshError::InvalidResponse {
|
||||
provider_type: VERTEX_SERVICE_ACCOUNT_PROVIDER_TYPE,
|
||||
message: format!("vertex service account token response is not JSON: {err}"),
|
||||
}
|
||||
})?;
|
||||
let access_token = json_string(body_json.get("access_token")).ok_or_else(|| {
|
||||
LocalOAuthRefreshError::InvalidResponse {
|
||||
provider_type: VERTEX_SERVICE_ACCOUNT_PROVIDER_TYPE,
|
||||
@@ -300,7 +296,7 @@ fn decode_vertex_service_account_private_key(
|
||||
private_key_pem: &str,
|
||||
) -> Result<RsaPrivateKey, LocalOAuthRefreshError> {
|
||||
match RsaPrivateKey::from_pkcs8_pem(private_key_pem) {
|
||||
Ok(private_key) => return Ok(private_key),
|
||||
Ok(private_key) => Ok(private_key),
|
||||
Err(pkcs8_err) => RsaPrivateKey::from_pkcs1_pem(private_key_pem).map_err(|pkcs1_err| {
|
||||
LocalOAuthRefreshError::InvalidResponse {
|
||||
provider_type: VERTEX_SERVICE_ACCOUNT_PROVIDER_TYPE,
|
||||
@@ -447,7 +443,10 @@ mod tests {
|
||||
assert_eq!(config.project_id, "demo-project");
|
||||
assert_eq!(config.region.as_deref(), Some("global"));
|
||||
assert_eq!(
|
||||
config.model_regions.get("gemini-2.0-flash").map(String::as_str),
|
||||
config
|
||||
.model_regions
|
||||
.get("gemini-2.0-flash")
|
||||
.map(String::as_str),
|
||||
Some("us-central1")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,9 +7,8 @@ pub use auth::{
|
||||
parse_vertex_service_account_auth_config, resolve_local_vertex_api_key_query_auth,
|
||||
resolve_local_vertex_service_account_auth_config,
|
||||
supports_local_vertex_service_account_auth_resolution, VertexApiKeyQueryAuth,
|
||||
VertexServiceAccountAuthConfig, VertexServiceAccountRefreshAdapter,
|
||||
VERTEX_API_KEY_QUERY_PARAM, VERTEX_SERVICE_ACCOUNT_AUTH_HEADER,
|
||||
VERTEX_SERVICE_ACCOUNT_PROVIDER_TYPE,
|
||||
VertexServiceAccountAuthConfig, VertexServiceAccountRefreshAdapter, VERTEX_API_KEY_QUERY_PARAM,
|
||||
VERTEX_SERVICE_ACCOUNT_AUTH_HEADER, VERTEX_SERVICE_ACCOUNT_PROVIDER_TYPE,
|
||||
};
|
||||
pub use context::{
|
||||
is_vertex_api_key_transport_context, is_vertex_service_account_transport_context,
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use super::super::snapshot::GatewayProviderTransportSnapshot;
|
||||
use super::super::{
|
||||
body_rules_are_locally_supported, header_rules_are_locally_supported,
|
||||
supports_local_oauth_request_auth_resolution,
|
||||
resolve_transport_profile, transport_profile_is_configured,
|
||||
transport_proxy_is_locally_supported,
|
||||
resolve_transport_profile, supports_local_oauth_request_auth_resolution,
|
||||
transport_profile_is_configured, transport_proxy_is_locally_supported,
|
||||
};
|
||||
use super::auth::{
|
||||
resolve_local_vertex_api_key_query_auth, supports_local_vertex_service_account_auth_resolution,
|
||||
@@ -58,9 +57,8 @@ fn local_vertex_gemini_transport_unsupported_reason_with_network_impl(
|
||||
return Some("transport_body_rules_unsupported");
|
||||
}
|
||||
let has_api_key_auth = resolve_local_vertex_api_key_query_auth(transport).is_some();
|
||||
let has_service_account_auth =
|
||||
supports_local_vertex_service_account_auth_resolution(transport)
|
||||
&& supports_local_oauth_request_auth_resolution(transport);
|
||||
let has_service_account_auth = supports_local_vertex_service_account_auth_resolution(transport)
|
||||
&& supports_local_oauth_request_auth_resolution(transport);
|
||||
if require_api_key {
|
||||
if !has_api_key_auth {
|
||||
return Some("transport_auth_unavailable");
|
||||
@@ -295,9 +293,7 @@ mod tests {
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
assert!(!supports_local_vertex_api_key_gemini_transport_with_network(
|
||||
&transport
|
||||
));
|
||||
assert!(!supports_local_vertex_api_key_gemini_transport_with_network(&transport));
|
||||
assert!(supports_local_vertex_gemini_transport_with_network(
|
||||
&transport
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user