From ae2f1666ceb8bd8cc8182cf2719b90061fb3763a Mon Sep 17 00:00:00 2001 From: rashad Date: Wed, 5 Apr 2023 18:58:17 -0400 Subject: [PATCH] chore: small auth devx updates (#733) chore: small authentication updates Co-authored-by: Rashad Alston --- config.yaml | 2 +- packages/fuel-indexer-lib/src/config/auth.rs | 2 +- packages/fuel-indexer-lib/src/config/mod.rs | 2 +- plugins/forc-index/src/ops/forc_index_auth.rs | 16 ++++++++++------ plugins/forc-index/src/ops/forc_index_deploy.rs | 12 ++++++++---- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/config.yaml b/config.yaml index 86395efc9..5464d3651 100644 --- a/config.yaml +++ b/config.yaml @@ -78,7 +78,7 @@ # enabled: false # # Which authentication scheme to use. -# strategy: JWT +# strategy: jwt # # Secret used if JWT authentication is specified. # jwt_secret: abcdefghijklmnopqrstuvwxyz1234567890* diff --git a/packages/fuel-indexer-lib/src/config/auth.rs b/packages/fuel-indexer-lib/src/config/auth.rs index e227bdfec..1c4b8d050 100644 --- a/packages/fuel-indexer-lib/src/config/auth.rs +++ b/packages/fuel-indexer-lib/src/config/auth.rs @@ -80,8 +80,8 @@ impl Env for AuthenticationConfig { } #[derive(Serialize, Deserialize, EnumString, AsRefStr, Clone, Debug, Eq, PartialEq)] -#[serde(rename_all = "snake_case")] pub enum AuthenticationStrategy { + #[strum(ascii_case_insensitive)] JWT, } diff --git a/packages/fuel-indexer-lib/src/config/mod.rs b/packages/fuel-indexer-lib/src/config/mod.rs index 6ab6deb18..9f205d722 100644 --- a/packages/fuel-indexer-lib/src/config/mod.rs +++ b/packages/fuel-indexer-lib/src/config/mod.rs @@ -267,7 +267,7 @@ pub struct ApiServerArgs { pub auth_enabled: bool, /// Authentication scheme used. - #[clap(long, help = "Authentication scheme used.")] + #[clap(long, help = "Authentication scheme used.", value_parser(["jwt"]))] pub auth_strategy: Option, /// Secret used for JWT scheme (if JWT scheme is specified). diff --git a/plugins/forc-index/src/ops/forc_index_auth.rs b/plugins/forc-index/src/ops/forc_index_auth.rs index 3a1a5507a..25b843942 100644 --- a/plugins/forc-index/src/ops/forc_index_auth.rs +++ b/plugins/forc-index/src/ops/forc_index_auth.rs @@ -41,11 +41,15 @@ pub fn init(command: AuthCommand) -> anyhow::Result<()> { .expect("Failed to deploy indexer."); if res.status() != StatusCode::OK { - error!( - "\n❌ {} returned a non-200 response code: {:?}", - &target, - res.status() - ); + if verbose { + error!( + "\n❌ {} returned a non-200 response code: {:?}", + &target, + res.status() + ); + } else { + error!("\n❌ Action failed (Status({}))", res.status()); + } return Ok(()); } @@ -105,7 +109,7 @@ pub fn init(command: AuthCommand) -> anyhow::Result<()> { token ); } else { - info!("\n✅ Authenticated successfully."); + info!("\n✅ Authenticated successfully.\n\nToken: {}", token); } } else { error!("\n❌ Failed to produce a token."); diff --git a/plugins/forc-index/src/ops/forc_index_deploy.rs b/plugins/forc-index/src/ops/forc_index_deploy.rs index 147ede321..d87897a1d 100644 --- a/plugins/forc-index/src/ops/forc_index_deploy.rs +++ b/plugins/forc-index/src/ops/forc_index_deploy.rs @@ -66,12 +66,12 @@ pub fn init(command: DeployCommand) -> anyhow::Result<()> { if verbose { info!( - "Deploying indexer at {} to {}", + "Deploying indexer at {} to {}.", manifest_path.display(), target ); } else { - info!("Deploying indexer"); + info!("Deploying indexer..."); } let mut headers = HeaderMap::new(); @@ -109,9 +109,13 @@ pub fn init(command: DeployCommand) -> anyhow::Result<()> { .expect("Failed to read JSON response."); if status != StatusCode::OK { - error!("\n❌ {target} returned a non-200 response code: {status:?}",); + if verbose { + error!("\n❌ {target} returned a non-200 response code: {status:?}",); - println!("\n{}", to_string_pretty(&res_json)?); + info!("\n{}", to_string_pretty(&res_json)?); + } else { + info!("\n{}", to_string_pretty(&res_json)?); + } return Ok(()); }