summaryrefslogtreecommitdiff
path: root/src/bin/cli.rs
blob: 64b5734dc2c948d7ca458428a9475506b8db8690 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use clap::{Parser, Subcommand};

#[derive(Parser, Debug)]
#[command(author, version, about = "Authorization CLI for managing policies")]
struct Args {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand, Debug)]
enum Commands {
    Server {
        /// Address to bind to
        #[arg(short, long, env = "BIND_ADDR", default_value = "127.0.0.1:50052")]
        addr: String,
    },
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let args = Args::parse();

    match args.command {
        Commands::Server { addr } => {
            tracing_subscriber::fmt()
                .json()
                .with_ansi(false)
                .with_current_span(true)
                .with_file(true)
                .with_level(false)
                .with_line_number(true)
                .with_max_level(tracing::Level::INFO)
                .with_span_list(true)
                .with_target(false)
                .with_thread_ids(false)
                .with_thread_names(false)
                .init();

            tracing::info!(address = %addr, "Starting");
            authzd::authorization::Server::new(
                authzd::authorization::spice::Authorizer::default(),
            )?
            .serve(addr.parse().unwrap())
            .await?;
        }
    }

    Ok(())
}