stdout
This commit is contained in:
@@ -31,7 +31,7 @@ pub struct Cli {
|
||||
pub enum Command {
|
||||
/// Run the control-plane daemon.
|
||||
Serve(ServeArgs),
|
||||
/// Write a control-plane config scaffold.
|
||||
/// Render a control-plane config scaffold.
|
||||
InitConfig(InitConfigArgs),
|
||||
/// Create a new enroll token for provisioning a router.
|
||||
IssueEnrollToken(IssueEnrollTokenArgs),
|
||||
@@ -80,8 +80,11 @@ pub struct ServeArgs {
|
||||
|
||||
#[derive(Args, Clone)]
|
||||
pub struct InitConfigArgs {
|
||||
#[arg(long, default_value = DEFAULT_CONFIG_FILE)]
|
||||
pub config_file: PathBuf,
|
||||
#[arg(long = "config-file", alias = "config")]
|
||||
pub config_file: Option<PathBuf>,
|
||||
|
||||
#[arg(long, conflicts_with = "config_file")]
|
||||
pub stdout: bool,
|
||||
|
||||
#[arg(long)]
|
||||
pub data_dir: Option<PathBuf>,
|
||||
|
||||
@@ -6,12 +6,18 @@ use crate::cli::{InitConfigArgs, ServeArgs};
|
||||
use crate::config::resolve::{normalize_public_url, resolve_path};
|
||||
use crate::config::types::{WritableConfig, WritableTelemetry};
|
||||
|
||||
pub fn write_init_config(args: &InitConfigArgs) -> Result<()> {
|
||||
if args.config_file.exists() && !args.force {
|
||||
anyhow::bail!(
|
||||
"config {} already exists; re-run with --force to overwrite",
|
||||
args.config_file.display()
|
||||
);
|
||||
pub fn write_init_config(args: &InitConfigArgs) -> Result<Option<PathBuf>> {
|
||||
if args.stdout && args.config_file.is_some() {
|
||||
anyhow::bail!("--stdout cannot be used with --config-file");
|
||||
}
|
||||
|
||||
if let Some(config_file) = &args.config_file {
|
||||
if config_file.exists() && !args.force {
|
||||
anyhow::bail!(
|
||||
"config {} already exists; re-run with --force to overwrite",
|
||||
config_file.display()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let bind = args.bind.unwrap_or_else(|| {
|
||||
@@ -61,15 +67,21 @@ pub fn write_init_config(args: &InitConfigArgs) -> Result<()> {
|
||||
},
|
||||
};
|
||||
|
||||
if let Some(parent) = args.config_file.parent() {
|
||||
std::fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create config dir {}", parent.display()))?;
|
||||
let rendered = toml::to_string_pretty(&body).context("failed to render config template")?;
|
||||
|
||||
if let Some(config_file) = &args.config_file {
|
||||
if let Some(parent) = config_file.parent() {
|
||||
std::fs::create_dir_all(parent)
|
||||
.with_context(|| format!("failed to create config dir {}", parent.display()))?;
|
||||
}
|
||||
|
||||
std::fs::write(config_file, rendered)
|
||||
.with_context(|| format!("failed to write config {}", config_file.display()))?;
|
||||
return Ok(Some(config_file.clone()));
|
||||
}
|
||||
|
||||
let rendered = toml::to_string_pretty(&body).context("failed to render config template")?;
|
||||
std::fs::write(&args.config_file, rendered)
|
||||
.with_context(|| format!("failed to write config {}", args.config_file.display()))?;
|
||||
Ok(())
|
||||
print!("{}", rendered);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub fn bootstrap_config_if_missing(args: &ServeArgs) -> Result<bool> {
|
||||
@@ -78,7 +90,8 @@ pub fn bootstrap_config_if_missing(args: &ServeArgs) -> Result<bool> {
|
||||
}
|
||||
|
||||
let init = InitConfigArgs {
|
||||
config_file: args.config_file.clone(),
|
||||
config_file: Some(args.config_file.clone()),
|
||||
stdout: false,
|
||||
data_dir: args.data_dir.clone(),
|
||||
bind: args.bind,
|
||||
public_url: args.public_url.clone(),
|
||||
|
||||
@@ -30,13 +30,10 @@ async fn main() -> Result<()> {
|
||||
runtime::serve(daemon).await
|
||||
}
|
||||
Command::InitConfig(args) => {
|
||||
tracing::init(cli.verbose, &config::TelemetryConfig::default())?;
|
||||
config::write_init_config(&args)?;
|
||||
println!("config={}", args.config_file.display());
|
||||
println!(
|
||||
"next=wakey-control-plane serve --config-file {}",
|
||||
args.config_file.display()
|
||||
);
|
||||
if let Some(path) = config::write_init_config(&args)? {
|
||||
println!("config={}", path.display());
|
||||
println!("next=wakey-control-plane serve --config-file {}", path.display());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Command::IssueEnrollToken(args) => {
|
||||
|
||||
@@ -16,7 +16,7 @@ pub async fn issue_enroll_token(args: IssueEnrollTokenArgs) -> Result<()> {
|
||||
let ttl_seconds = settings.ttl.as_secs().max(1);
|
||||
let endpoint = format!(
|
||||
"{}?ttl_seconds={ttl_seconds}",
|
||||
config::issue_token_endpoint(&base)
|
||||
config::issue_token_endpoint(base)
|
||||
);
|
||||
tracing::info!(endpoint = %endpoint, "requesting live enroll token from running control-plane daemon");
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
Reference in New Issue
Block a user