Skip to content

Commit fa630f7

Browse files
committed
Add warning for auth on entity switch at connection build time
1 parent 0021f49 commit fa630f7

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/lib.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ pub type OriginKey = [u8; 40];
301301
pub struct ConnectionBuilder {
302302
port: u16,
303303
host: String,
304-
entity: String,
304+
entity: Option<String>,
305305
auth: Option<(String, String)>,
306306
}
307307

@@ -310,7 +310,7 @@ impl Default for ConnectionBuilder {
310310
Self {
311311
port: 2004,
312312
host: "127.0.0.1".to_owned(),
313-
entity: "default:default".to_owned(),
313+
entity: None,
314314
auth: None,
315315
}
316316
}
@@ -332,8 +332,13 @@ impl ConnectionBuilder {
332332
self
333333
}
334334
/// Set the entity (defaults to `default:default`)
335+
///
336+
/// ## Warning
337+
///
338+
/// If you're using authn/authz on the server side, make sure
339+
/// you set up authentication too using [`ConnectionBuilder::set_auth`]
335340
pub fn set_entity(mut self, entity: String) -> Self {
336-
self.entity = entity;
341+
self.entity = Some(entity);
337342
self
338343
}
339344
/// Set the username and authentication token (defaults to no authentication)
@@ -350,7 +355,9 @@ impl ConnectionBuilder {
350355
if let Some((ref user, ref token)) = self.auth {
351356
con.auth_login(user, token)?;
352357
}
353-
con.switch(&self.entity)?;
358+
if let Some(ref entity) = self.entity {
359+
con.switch(entity)?;
360+
}
354361
Ok(con)
355362
}
356363
cfg_sync_ssl_any! {
@@ -368,7 +375,9 @@ impl ConnectionBuilder {
368375
if let Some((ref user, ref token)) = self.auth {
369376
con.auth_login(user, token)?;
370377
}
371-
con.switch(&self.entity)?;
378+
if let Some(ref entity) = self.entity {
379+
con.switch(entity)?;
380+
}
372381
Ok(con)
373382
}
374383
}
@@ -382,7 +391,9 @@ impl ConnectionBuilder {
382391
if let Some((ref user, ref token)) = self.auth {
383392
con.auth_login(user, token).await?;
384393
}
385-
con.switch(&self.entity).await?;
394+
if let Some(ref entity) = self.entity {
395+
con.switch(entity).await?;
396+
}
386397
Ok(con)
387398
}
388399
cfg_async_ssl_any! {
@@ -401,7 +412,9 @@ impl ConnectionBuilder {
401412
if let Some((ref user, ref token)) = self.auth {
402413
con.auth_login(user, token).await?;
403414
}
404-
con.switch(&self.entity).await?;
415+
if let Some(ref entity) = self.entity {
416+
con.switch(entity).await?;
417+
}
405418
Ok(con)
406419
}
407420
}

0 commit comments

Comments
 (0)