MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / on_startup

Method on_startup

crates/pg/src/pg_server.rs:217–311  ·  view source on GitHub ↗
(&self, client: &mut C, message: PgWireFrontendMessage)

Source from the content-addressed store, hash-verified

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!(

Callers

nothing calls this directly

Calls 15

NameFunction · 0.85
DatabaseNameClass · 0.85
responseFunction · 0.85
close_clientFunction · 0.85
set_stateMethod · 0.80
databaseMethod · 0.80
lockMethod · 0.80
sendMethod · 0.65
ErrFunction · 0.50
validate_tokenFunction · 0.50
newFunction · 0.50
OkFunction · 0.50

Tested by

no test coverage detected