athena_rs 3.22.1

Hyper performant polyglot Database driver
Documentation
//! Clients-list response orchestration for schema routes.
//!
//! This module owns schema-read authorization and payload building for
//! client-list endpoints so route handlers stay thin.

use actix_web::{HttpRequest, HttpResponse};

use crate::AppState;

use super::context_auth::authorize_schema_read;
use super::response_contracts::SchemaClients;

/// Builds the configured clients payload response.
fn schema_clients_response(app_state: &AppState) -> HttpResponse {
    let clients: Vec<String> = app_state.pg_registry.list_clients();
    HttpResponse::Ok().json(SchemaClients { clients })
}

/// Authorizes schema-read access and returns the clients payload response.
pub(super) async fn authorized_schema_clients_response(
    req: &HttpRequest,
    app_state: &AppState,
) -> HttpResponse {
    if let Err(resp) = authorize_schema_read(req, app_state, None).await {
        return resp;
    }

    schema_clients_response(app_state)
}