summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-11 13:00:50 -0600
committermo khan <mo@mokhan.ca>2025-07-11 13:00:50 -0600
commit7659e433eb73e1f33ddac49537bfa5dfaa124875 (patch)
treed6c90f4c82b02ded848531c0a08124f1551fd957 /src
parentef572ae666732e87a35417710669ce88233a754a (diff)
refactor: merge the server and cli into a single binary
Diffstat (limited to 'src')
-rw-r--r--src/bin/cli.rs23
-rw-r--r--src/main.rs25
2 files changed, 23 insertions, 25 deletions
diff --git a/src/bin/cli.rs b/src/bin/cli.rs
index fc70ae82..7b18cc3b 100644
--- a/src/bin/cli.rs
+++ b/src/bin/cli.rs
@@ -38,6 +38,11 @@ enum Commands {
)]
host: String,
},
+ Server {
+ /// Address to bind to
+ #[arg(short, long, env = "BIND_ADDR")]
+ addr: String,
+ },
}
#[tokio::main]
@@ -63,6 +68,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
output
);
}
+ Commands::Server { addr } => {
+ tracing_subscriber::fmt()
+ .json()
+ .with_max_level(tracing::Level::INFO)
+ .with_current_span(true)
+ .with_span_list(true)
+ .with_target(true)
+ .with_thread_ids(true)
+ .with_thread_names(true)
+ .with_file(true)
+ .with_line_number(true)
+ .init();
+
+ tracing::info!(address = %addr, "Starting authorization server");
+ let cedar = authzd::authorization::CedarAuthorizer::default();
+ let server = authzd::authorization::Server::new(cedar)?;
+ server.serve(addr.parse().unwrap()).await?;
+ }
}
Ok(())
diff --git a/src/main.rs b/src/main.rs
deleted file mode 100644
index add0d88d..00000000
--- a/src/main.rs
+++ /dev/null
@@ -1,25 +0,0 @@
-#[tokio::main]
-async fn main() -> Result<(), Box<dyn std::error::Error>> {
- tracing_subscriber::fmt()
- .json()
- .with_max_level(tracing::Level::INFO)
- .with_current_span(true)
- .with_span_list(true)
- .with_target(true)
- .with_thread_ids(true)
- .with_thread_names(true)
- .with_file(true)
- .with_line_number(true)
- .init();
-
- let addr = std::env::var("BIND_ADDR")
- .unwrap_or_else(|_| "127.0.0.1:50051".to_string())
- .parse()?;
-
- tracing::info!(address = %addr, "Starting authorization server");
- let cedar = authzd::authorization::CedarAuthorizer::default();
- let server = authzd::authorization::Server::new(cedar)?;
- server.serve(addr).await?;
-
- Ok(())
-}