(&self, client: &mut C, message: PgWireFrontendMessage)
| 215 | for PgSpacetimeDB<T> |
| 216 | { |
| 217 | async fn on_startup<C>(&self, client: &mut C, message: PgWireFrontendMessage) -> PgWireResult<()> |
| 218 | where |
| 219 | C: ClientInfo + Sink<PgWireBackendMessage> + Unpin + Send, |
| 220 | C::Error: Debug, |
| 221 | PgWireError: From<<C as Sink<PgWireBackendMessage>>::Error>, |
| 222 | { |
| 223 | match message { |
| 224 | PgWireFrontendMessage::Startup(ref startup) => { |
| 225 | protocol_negotiation(client, startup).await?; |
| 226 | save_startup_parameters_to_metadata(client, startup); |
| 227 | client.set_state(PgWireConnectionState::AuthenticationInProgress); |
| 228 | |
| 229 | let login_info = LoginInfo::from_client_info(client); |
| 230 | |
| 231 | if login_info.database().is_none() { |
| 232 | return Err(PgError::DatabaseNameRequired.into()); |
| 233 | } |
| 234 | |
| 235 | client |
| 236 | .send(PgWireBackendMessage::Authentication(Authentication::CleartextPassword)) |
| 237 | .await?; |
| 238 | } |
| 239 | PgWireFrontendMessage::PasswordMessageFamily(pwd) => { |
| 240 | let params = client.metadata(); |
| 241 | let param = |param: &str| { |
| 242 | params |
| 243 | .get(param) |
| 244 | .map(String::from) |
| 245 | .ok_or_else(|| PgError::MetadataError(anyhow::anyhow!("Missing parameter: {param}"))) |
| 246 | }; |
| 247 | |
| 248 | // We don't support `METADATA_USER` because we don't have a user management system. |
| 249 | let database = param(METADATA_DATABASE)?; |
| 250 | let pwd = pwd.into_password()?; |
| 251 | match param("application_name") { |
| 252 | Ok(application_name) => { |
| 253 | log::info!("PG: Connecting to database: {database}, by {application_name}",); |
| 254 | } |
| 255 | _ => { |
| 256 | log::info!("PG: Connecting to database: {database}"); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | let name = database::NameOrIdentity::Name(DatabaseName(database.clone())); |
| 261 | match response(name.resolve(&self.ctx).await, &database).await { |
| 262 | Ok(identity) => identity, |
| 263 | Err(PgError::Pg(PgWireError::UserError(err))) => { |
| 264 | return close_client(client, *err).await; |
| 265 | } |
| 266 | Err(err) => { |
| 267 | return Err(err.into()); |
| 268 | } |
| 269 | }; |
| 270 | |
| 271 | let claims = match validate_token(&self.ctx, &pwd.password).await { |
| 272 | Ok(claims) => claims, |
| 273 | Err(err) => { |
| 274 | log::error!( |
nothing calls this directly
no test coverage detected