LCOV - code coverage report
Current view: top level - proxy/src/auth/backend - local.rs (source / functions) Coverage Total Hit
Test: 07bee600374ccd486c69370d0972d9035964fe68.info Lines: 0.0 % 38 0
Test Date: 2025-02-20 13:11:02 Functions: 0.0 % 3 0

            Line data    Source code
       1              : use std::net::SocketAddr;
       2              : 
       3              : use arc_swap::ArcSwapOption;
       4              : use tokio::sync::Semaphore;
       5              : 
       6              : use super::jwt::{AuthRule, FetchAuthRules};
       7              : use crate::auth::backend::jwt::FetchAuthRulesError;
       8              : use crate::compute::ConnCfg;
       9              : use crate::compute_ctl::ComputeCtlApi;
      10              : use crate::context::RequestContext;
      11              : use crate::control_plane::messages::{ColdStartInfo, EndpointJwksResponse, MetricsAuxInfo};
      12              : use crate::control_plane::NodeInfo;
      13              : use crate::http;
      14              : use crate::intern::{BranchIdTag, EndpointIdTag, InternId, ProjectIdTag};
      15              : use crate::types::EndpointId;
      16              : use crate::url::ApiUrl;
      17              : 
      18              : pub struct LocalBackend {
      19              :     pub(crate) initialize: Semaphore,
      20              :     pub(crate) compute_ctl: ComputeCtlApi,
      21              :     pub(crate) node_info: NodeInfo,
      22              : }
      23              : 
      24              : impl LocalBackend {
      25            0 :     pub fn new(postgres_addr: SocketAddr, compute_ctl: ApiUrl) -> Self {
      26            0 :         LocalBackend {
      27            0 :             initialize: Semaphore::new(1),
      28            0 :             compute_ctl: ComputeCtlApi {
      29            0 :                 api: http::Endpoint::new(compute_ctl, http::new_client()),
      30            0 :             },
      31            0 :             node_info: NodeInfo {
      32            0 :                 config: ConnCfg::new(postgres_addr.ip().to_string(), postgres_addr.port()),
      33            0 :                 // TODO(conrad): make this better reflect compute info rather than endpoint info.
      34            0 :                 aux: MetricsAuxInfo {
      35            0 :                     endpoint_id: EndpointIdTag::get_interner().get_or_intern("local"),
      36            0 :                     project_id: ProjectIdTag::get_interner().get_or_intern("local"),
      37            0 :                     branch_id: BranchIdTag::get_interner().get_or_intern("local"),
      38            0 :                     cold_start_info: ColdStartInfo::WarmCached,
      39            0 :                 },
      40            0 :             },
      41            0 :         }
      42            0 :     }
      43              : }
      44              : 
      45              : #[derive(Clone, Copy)]
      46              : pub(crate) struct StaticAuthRules;
      47              : 
      48              : pub static JWKS_ROLE_MAP: ArcSwapOption<EndpointJwksResponse> = ArcSwapOption::const_empty();
      49              : 
      50              : impl FetchAuthRules for StaticAuthRules {
      51            0 :     async fn fetch_auth_rules(
      52            0 :         &self,
      53            0 :         _ctx: &RequestContext,
      54            0 :         _endpoint: EndpointId,
      55            0 :     ) -> Result<Vec<AuthRule>, FetchAuthRulesError> {
      56            0 :         let mappings = JWKS_ROLE_MAP.load();
      57            0 :         let role_mappings = mappings
      58            0 :             .as_deref()
      59            0 :             .ok_or(FetchAuthRulesError::RoleJwksNotConfigured)?;
      60            0 :         let mut rules = vec![];
      61            0 :         for setting in &role_mappings.jwks {
      62            0 :             rules.push(AuthRule {
      63            0 :                 id: setting.id.clone(),
      64            0 :                 jwks_url: setting.jwks_url.clone(),
      65            0 :                 audience: setting.jwt_audience.clone(),
      66            0 :                 role_names: setting.role_names.clone(),
      67            0 :             });
      68            0 :         }
      69              : 
      70            0 :         Ok(rules)
      71            0 :     }
      72              : }
        

Generated by: LCOV version 2.1-beta