summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 1a3ff00c634471d41e21ad50d11eceac91ffd09a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
pub mod authorization;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    use envoy_types::ext_authz::v3::pb::AuthorizationServer;
    use std::sync::Arc;
    use tonic::transport::Server;

    tracing_subscriber::fmt().json().init();

    let addr = std::env::var("BIND_ADDR")
        .unwrap_or_else(|_| "[::1]:50051".to_string())
        .parse()?;

    let (_health_reporter, health_service) = tonic_health::server::health_reporter();

    let authorizer = Arc::new(authorization::CedarAuthorizer::default());
    let check_service = authorization::CheckService::new(authorizer);

    let server = Server::builder()
        .add_service(AuthorizationServer::new(check_service))
        .add_service(health_service)
        .add_service(
            tonic_reflection::server::Builder::configure()
                .register_encoded_file_descriptor_set(tonic_health::pb::FILE_DESCRIPTOR_SET)
                .build_v1()
                .unwrap(),
        );

    log::info!("Listening on... {addr}");
    server.serve(addr).await?;

    Ok(())
}