Skip to content

Commit

Permalink
should be configurable with environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Sep 15, 2023
1 parent 7af885a commit 966e579
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 11 additions & 2 deletions omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ use uuid::Uuid;
#[derive(Debug, Args)]
pub struct DbArgs {
/// URL of the database SQL interface
db_url: PostgresConfigWithUrl,
#[clap(long, env("OMDB_DB_URL"))]
db_url: Option<PostgresConfigWithUrl>,

/// limit to apply to queries that fetch rows
#[clap(
Expand Down Expand Up @@ -126,7 +127,15 @@ impl DbArgs {
&self,
log: &slog::Logger,
) -> Result<(), anyhow::Error> {
let db_config = db::Config { url: self.db_url.clone() };
// This is a little goofy. The database URL is required, but can come
// from the environment, in which case it won't be on the command line.
let Some(db_url) = &self.db_url else {
bail!(
"database URL must be specified with --db-url or OMDB_DB_URL"
);
};

let db_config = db::Config { url: db_url.clone() };
let pool = Arc::new(db::Pool::new(&log.clone(), &db_config));

// Being a dev tool, we want to try this operation even if the schema
Expand Down
15 changes: 12 additions & 3 deletions omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

//! omdb commands that query or update specific Nexus instances
use anyhow::bail;
use anyhow::Context;
use chrono::SecondsFormat;
use chrono::Utc;
Expand All @@ -22,7 +23,8 @@ use uuid::Uuid;
#[derive(Debug, Args)]
pub struct NexusArgs {
/// URL of the Nexus internal API
nexus_internal_url: String,
#[clap(long, env("OMDB_NEXUS_URL"))]
nexus_internal_url: Option<String>,

#[command(subcommand)]
command: NexusCommands,
Expand Down Expand Up @@ -57,8 +59,15 @@ impl NexusArgs {
&self,
log: &slog::Logger,
) -> Result<(), anyhow::Error> {
let client =
nexus_client::Client::new(&self.nexus_internal_url, log.clone());
// This is a little goofy. The database URL is required, but can come
// from the environment, in which case it won't be on the command line.
let Some(nexus_url) = &self.nexus_internal_url else {
bail!(
"nexus URL must be specified with --nexus-internal-url or \
OMDB_NEXUS_URL"
);
};
let client = nexus_client::Client::new(nexus_url, log.clone());

match &self.command {
NexusCommands::BackgroundTask(BackgroundTaskArgs {
Expand Down

0 comments on commit 966e579

Please sign in to comment.