Skip to content

Commit

Permalink
feat: expose improved auth utils (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante authored May 1, 2024
1 parent a9b2c9f commit 333ea1c
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 148 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ tokio = { version = "1", features = ["full"] }
log = { version = "0.4.19" }
chrono = { version = "0.4.26" }
marzano-util = { path = "../util" }

[features]
test-utils = []
1 change: 1 addition & 0 deletions crates/auth/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod auth0;
pub mod env;
pub mod info;
#[cfg(any(test, feature = "test-utils"))]
pub mod testing;
32 changes: 28 additions & 4 deletions crates/auth/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,33 @@ use crate::{
info::AuthInfo,
};

/// Attempts to read a variable, first from the environment, then from Doppler.
///
/// If neither source has the variable, an error is returned.
fn get_config_var(var_name: &str) -> Result<String> {
if let Ok(value) = env::var(var_name) {
return Ok(value);
}

use std::process::Command;
let output = Command::new("doppler")
.args(["secrets", "get", var_name, "--plain"])
.output();

match output {
Ok(output) if output.status.success() => {
let value = String::from_utf8_lossy(&output.stdout).trim().to_string();
Ok(value)
}
_ => Err(anyhow::anyhow!(
"Variable {} not found in environment or Doppler",
var_name
)),
}
}

fn get_existing_token() -> Result<AuthInfo> {
let existing_token = env::var("API_TESTING_TOKEN")?;
let existing_token = get_config_var("API_TESTING_TOKEN")?;
let info = AuthInfo {
access_token: existing_token,
};
Expand All @@ -24,8 +49,8 @@ fn get_existing_token() -> Result<AuthInfo> {

fn get_new_tokens() -> Result<AuthInfo> {
// Exchange client tokens for a test token
let client_id = env::var("API_TESTING_CLIENT_ID")?;
let client_secret = env::var("API_TESTING_CLIENT_SECRET")?;
let client_id = get_config_var("API_TESTING_CLIENT_ID")?;
let client_secret = get_config_var("API_TESTING_CLIENT_SECRET")?;

let client = reqwest::blocking::Client::new();

Expand Down Expand Up @@ -68,7 +93,6 @@ mod tests {
#[ignore = "eats up auth tokens, only enable when explicitly testing"]
fn test_token_refresh() -> Result<()> {
let auth_info = get_testing_auth_info().unwrap();
println!("auth_info: {}", auth_info);
assert!(!auth_info.is_expired()?);
Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions crates/cli/src/commands/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ pub(crate) async fn run_apply(
) -> Result<()> {
#[cfg(feature = "workflows_v2")]
{
if args.apply_migration_args.remote {
println!("Apply {} remotely", args.pattern_or_workflow);
anyhow::bail!("Remote workflows are not yet supported");
}
let current_dir = current_dir()?;
let custom_workflow = find_workflow_file_from(current_dir, &args.pattern_or_workflow).await;
if let Some(custom_workflow) = custom_workflow {
Expand Down
6 changes: 6 additions & 0 deletions crates/cli/src/commands/apply_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ pub struct ApplyMigrationArgs {
help = "JSON input parameter to pass to the workflow"
)]
input: Option<String>,
#[clap(
long,
help_heading = "Workflow options",
help = "Run the workflow remotely on Grit Cloud"
)]
pub(crate) remote: bool,
/// Print verbose output
#[clap(long)]
verbose: bool,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ similar = "2.2.1"
lazy_static = "1.4.0"
insta = { version = "1.30.0", features = ["yaml", "redactions"] }
trim-margin = "0.1.0"
marzano-auth = { path = "../auth" }
marzano-auth = { path = "../auth", features = ["test-utils"] }
walkdir = "2.3.3"

[features]
Expand Down
21 changes: 0 additions & 21 deletions crates/graphql/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion crates/graphql/src/lib.rs

This file was deleted.

108 changes: 0 additions & 108 deletions crates/graphql/src/rules.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/test_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rust.unused_crate_dependencies = "warn"

[dependencies]
anyhow = { version = "1.0.70" }
marzano-auth = { path = "../auth" }
marzano-auth = { path = "../auth", features = ["test-utils"] }
assert_cmd = { version = "2.0.12" }
tempfile = { version = "3.1" }
fs_extra = { version = "1.3" }
Expand Down

0 comments on commit 333ea1c

Please sign in to comment.