Skip to content

Commit

Permalink
1.6.1 pass creds as args cli
Browse files Browse the repository at this point in the history
  • Loading branch information
mbecker20 committed Jun 3, 2024
1 parent 38d9495 commit 5f6fabd
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 13 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["bin/*", "lib/*", "client/core/rs", "client/periphery/rs"]

[workspace.package]
version = "1.6.0"
version = "1.6.1"
edition = "2021"
authors = ["mbecker20 <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down
6 changes: 6 additions & 0 deletions bin/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ secret = "YOUR-API-SECRET"
```

Note. You can specify a different creds file by using `--creds ./other/path.toml`.
You can also bypass using any file and pass the information using `--url`, `--key`, `--secret`:

```sh
monitor --url "https://your.monitor.address" --key "YOUR-API-KEY" --secret "YOUR-API-SECRET" ...
```

### Run Syncs

Expand Down Expand Up @@ -51,6 +56,7 @@ Options:
### Run Executions

```sh
# Triggers an example build
monitor execute run-build test_build
```

Expand Down
15 changes: 15 additions & 0 deletions bin/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,24 @@ pub struct CliArgs {
/// Sync or Exec
#[command(subcommand)]
pub command: Command,

/// The path to a creds file.
///
/// Note: If each of `url`, `key` and `secret` are passed,
/// no file is required at this path.
#[arg(long, default_value_t = default_creds())]
pub creds: String,

/// Pass url in args instead of creds file
#[arg(long)]
pub url: Option<String>,
/// Pass api key in args instead of creds file
#[arg(long)]
pub key: Option<String>,
/// Pass api secret in args instead of creds file
#[arg(long)]
pub secret: Option<String>,

/// Always continue on user confirmation prompts.
#[arg(long, short, default_value_t = false)]
pub yes: bool,
Expand Down
29 changes: 27 additions & 2 deletions bin/cli/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,34 @@ pub fn cli_args() -> &'static crate::args::CliArgs {
pub fn monitor_client() -> &'static MonitorClient {
static MONITOR_CLIENT: OnceLock<MonitorClient> = OnceLock::new();
MONITOR_CLIENT.get_or_init(|| {
let args = cli_args();
let crate::args::CredsFile { url, key, secret } =
crate::helpers::parse_toml_file(&cli_args().creds)
.expect("failed to parse monitor credentials");
match (&args.url, &args.key, &args.secret) {
(Some(url), Some(key), Some(secret)) => {
crate::args::CredsFile {
url: url.clone(),
key: key.clone(),
secret: secret.clone(),
}
}
(url, key, secret) => {
let mut creds: crate::args::CredsFile =
crate::helpers::parse_toml_file(&cli_args().creds)
.expect("failed to parse monitor credentials");

if let Some(url) = url {
creds.url.clone_from(url);
}
if let Some(key) = key {
creds.key.clone_from(key);
}
if let Some(secret) = secret {
creds.secret.clone_from(secret);
}

creds
}
};
futures::executor::block_on(MonitorClient::new(url, key, secret))
.expect("failed to initialize monitor client")
})
Expand Down

0 comments on commit 5f6fabd

Please sign in to comment.