Source commit: f70e47af061d8f7ba27cd769c8cd2e2f8707dc72 Public tree identity: sha256:03a43db60d295811688bedaa5ad6460df0dbde27fbf37033997f4d8100f83ab2
62 lines
2.2 KiB
Rust
62 lines
2.2 KiB
Rust
use std::io::Write;
|
|
|
|
use clusterflux_coordinator::{service::bind_listener, CoordinatorService};
|
|
use clusterflux_core::{ProjectId, TenantId, UserId};
|
|
use serde_json::json;
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let mut listen = "127.0.0.1:0".to_owned();
|
|
let mut allow_local_trusted = std::env::var("CLUSTERFLUX_ALLOW_LOCAL_TRUSTED_LOOPBACK")
|
|
.ok()
|
|
.as_deref()
|
|
== Some("1");
|
|
let mut args = std::env::args().skip(1);
|
|
while let Some(arg) = args.next() {
|
|
if arg == "--listen" {
|
|
listen = args.next().ok_or("--listen requires an address")?;
|
|
} else if arg == "--allow-local-trusted-loopback" {
|
|
allow_local_trusted = true;
|
|
}
|
|
}
|
|
|
|
let (listener, addr) = bind_listener(&listen)?;
|
|
let database_url = std::env::var("DATABASE_URL").ok();
|
|
let mut service = CoordinatorService::new_with_database_url(1, database_url.as_deref())?;
|
|
let self_hosted_session_secret = std::env::var("CLUSTERFLUX_SELF_HOSTED_SESSION_SECRET")
|
|
.ok()
|
|
.filter(|secret| !secret.trim().is_empty());
|
|
if let Some(session_secret) = self_hosted_session_secret.as_deref() {
|
|
service.issue_cli_session(
|
|
TenantId::new(
|
|
std::env::var("CLUSTERFLUX_SELF_HOSTED_TENANT")
|
|
.unwrap_or_else(|_| "tenant".to_owned()),
|
|
),
|
|
ProjectId::new(
|
|
std::env::var("CLUSTERFLUX_SELF_HOSTED_PROJECT")
|
|
.unwrap_or_else(|_| "project".to_owned()),
|
|
),
|
|
UserId::new(
|
|
std::env::var("CLUSTERFLUX_SELF_HOSTED_USER").unwrap_or_else(|_| "user".to_owned()),
|
|
),
|
|
session_secret,
|
|
None,
|
|
)?;
|
|
}
|
|
println!(
|
|
"{}",
|
|
json!({
|
|
"listen": addr.to_string(),
|
|
"client_authority": if allow_local_trusted { "local_trusted_loopback" } else { "strict" },
|
|
"self_hosted_session_bootstrapped": self_hosted_session_secret.is_some(),
|
|
"durable_store": service.durable_store_kind(),
|
|
})
|
|
);
|
|
std::io::stdout().flush()?;
|
|
|
|
if allow_local_trusted {
|
|
service.serve_tcp_local_trusted(listener)?;
|
|
} else {
|
|
service.serve_tcp(listener)?;
|
|
}
|
|
Ok(())
|
|
}
|