summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 8eb7b5efd206ec1d47d5a0212facee9aa339d49a (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
use envoy_types::ext_authz::v3::pb::AuthorizationServer;
use std::sync::Arc;
use tonic::transport::Server;

pub mod authorization;
use authorization::{CedarAuthorizer, CheckService};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let addr = "[::1]:50051".parse()?;

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

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

    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(),
        )
        .serve(addr)
        .await?;

    Ok(())
}