From 96e78394f5b24bb2116f1e326e0d11c4138f1df0 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Thu, 2 Feb 2023 23:56:15 +0300 Subject: [PATCH] [proxy] Fix project (aka endpoint) init in the password hack handler (#3529) The project/endpoint should be set in the original (non-as_ref'd) creds, because we call `wake_compute` not only in `try_password_hack` but also later in the connection retry logic. This PR also removes the obsolete `as_ref` method and makes the code simpler because we no longer need this complication after a recent refactoring. Further action points: finally introduce typestate in creds (planned). --- proxy/src/auth/backend.rs | 22 +++++++++------------- proxy/src/auth/credentials.rs | 12 ------------ 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/proxy/src/auth/backend.rs b/proxy/src/auth/backend.rs index 60460e6722..50afbd2a27 100644 --- a/proxy/src/auth/backend.rs +++ b/proxy/src/auth/backend.rs @@ -149,36 +149,32 @@ impl<'l> BackendType<'l, ClientCredentials<'_>> { }; // TODO: find a proper way to merge those very similar blocks. - let (mut node, payload) = match self { + let (mut node, password) = match self { Console(api, creds) if creds.project.is_none() => { let payload = fetch_magic_payload(client).await?; + creds.project = Some(payload.project.into()); + let node = api.wake_compute(extra, creds).await?; - let mut creds = creds.as_ref(); - creds.project = Some(payload.project.as_str().into()); - let node = api.wake_compute(extra, &creds).await?; - - (node, payload) + (node, payload.password) } // This is a hack to allow cleartext password in secure connections (wss). Console(api, creds) if creds.use_cleartext_password_flow => { let payload = fetch_plaintext_password(client).await?; let node = api.wake_compute(extra, creds).await?; - (node, payload) + (node, payload.password) } Postgres(api, creds) if creds.project.is_none() => { let payload = fetch_magic_payload(client).await?; + creds.project = Some(payload.project.into()); + let node = api.wake_compute(extra, creds).await?; - let mut creds = creds.as_ref(); - creds.project = Some(payload.project.as_str().into()); - let node = api.wake_compute(extra, &creds).await?; - - (node, payload) + (node, payload.password) } _ => return Ok(None), }; - node.config.password(payload.password); + node.config.password(password); Ok(Some(AuthSuccess { reported_auth_ok: false, value: node, diff --git a/proxy/src/auth/credentials.rs b/proxy/src/auth/credentials.rs index e1943fe44c..66ca8be73e 100644 --- a/proxy/src/auth/credentials.rs +++ b/proxy/src/auth/credentials.rs @@ -47,18 +47,6 @@ impl ClientCredentials<'_> { } } -impl<'a> ClientCredentials<'a> { - #[inline] - pub fn as_ref(&'a self) -> ClientCredentials<'a> { - Self { - user: self.user, - dbname: self.dbname, - project: self.project().map(Cow::Borrowed), - use_cleartext_password_flow: self.use_cleartext_password_flow, - } - } -} - impl<'a> ClientCredentials<'a> { pub fn parse( params: &'a StartupMessageParams,