From a80825af40c032592ab0b4e5c9dc18060c798857 Mon Sep 17 00:00:00 2001 From: Adam Marcus Date: Thu, 18 Jan 2024 04:33:59 +0000 Subject: [PATCH] Return entity slug with confirmation endpoint --- README.md | 2 +- src/bin/ayb.rs | 4 ++-- src/http/endpoints/confirm.rs | 1 + src/http/structs.rs | 1 + tests/utils/mod.rs | 4 ++-- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 03e7a0a3..f5ebb313 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ $ curl -w "\n" -X POST http://127.0.0.1:5433/v1/register -H "entity-type: user" $ curl -w "\n" -X POST http://127.0.0.1:5433/v1/confirm -H "authentication-token: TOKEN_FROM_EMAIL" -{"token":""} +{"entity":"marcua","token":""} $ curl -w "\n" -X POST http://127.0.0.1:5433/v1/marcua/test.sqlite/create -H "db-type: sqlite" -H "authorization: Bearer " diff --git a/src/bin/ayb.rs b/src/bin/ayb.rs index 42ce8560..2ea2c84a 100644 --- a/src/bin/ayb.rs +++ b/src/bin/ayb.rs @@ -265,8 +265,8 @@ async fn main() -> std::io::Result<()> { .insert(url.clone(), api_token.token.clone()); config.to_file(&config_path)?; println!( - "Successfully authenticated and saved token {}", - api_token.token + "Successfully authenticated {} and saved token {}", + api_token.entity, api_token.token ); } Err(err) => { diff --git a/src/http/endpoints/confirm.rs b/src/http/endpoints/confirm.rs index 60daf5b1..851f97bb 100644 --- a/src/http/endpoints/confirm.rs +++ b/src/http/endpoints/confirm.rs @@ -69,6 +69,7 @@ async fn confirm( let (api_token, token_string) = generate_api_token(&created_entity)?; let _ = ayb_db.create_api_token(&api_token).await?; let returned_token = APIAPIToken { + entity: created_entity.slug, token: token_string, }; diff --git a/src/http/structs.rs b/src/http/structs.rs index 4e134524..42317fda 100644 --- a/src/http/structs.rs +++ b/src/http/structs.rs @@ -214,6 +214,7 @@ pub struct AuthenticationDetails { #[derive(Debug, Serialize, Deserialize)] pub struct APIToken { + pub entity: String, pub token: String, } diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index cca39637..9da90817 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -19,10 +19,10 @@ pub struct EmailEntry { pub fn extract_api_key(output: &Output) -> Result { let output_str = std::str::from_utf8(&output.stdout)?; - let re = Regex::new(r"^Successfully authenticated and saved token (\S+)\n").unwrap(); + let re = Regex::new(r"^Successfully authenticated (\S+) and saved token (\S+)\n").unwrap(); if re.is_match(output_str) { let captures = re.captures(output_str).unwrap(); - Ok(captures.get(1).map_or("", |m| m.as_str()).to_string()) + Ok(captures.get(2).map_or("", |m| m.as_str()).to_string()) } else { Err(AybError::Other { message: "No API key".to_string(),