Rename access-related keys to prevent collisions (#4589)

This commit is contained in:
Gerard Guillemas Martos 2024-08-23 12:49:28 +02:00 committed by GitHub
parent 382e88bac7
commit d2354caf8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 48 additions and 45 deletions

View file

@ -34,7 +34,7 @@ impl<'a> Access<'a> {
ns,
_b: b'*',
db,
_c: b'*',
_c: b'&',
ac,
}
}
@ -52,7 +52,7 @@ mod tests {
"testac",
);
let enc = Access::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testac\0");
assert_eq!(enc, b"/*testns\0*testdb\0&testac\0");
let dec = Access::decode(&enc).unwrap();
assert_eq!(val, dec);

View file

@ -50,7 +50,7 @@ impl<'a> Gr<'a> {
ns,
_b: b'*',
db,
_c: b'*',
_c: b'&',
ac,
_d: b'!',
_e: b'g',
@ -73,7 +73,7 @@ mod tests {
"testgr",
);
let enc = Gr::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testac\0!grtestgr\0");
assert_eq!(enc, b"/*testns\0*testdb\0&testac\0!grtestgr\0");
let dec = Gr::decode(&enc).unwrap();
assert_eq!(val, dec);
@ -82,12 +82,12 @@ mod tests {
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testdb", "testac");
assert_eq!(val, b"/*testns\0*testdb\0*testac\0!gr\0");
assert_eq!(val, b"/*testns\0*testdb\0&testac\0!gr\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testdb", "testac");
assert_eq!(val, b"/*testns\0*testdb\0*testac\0!gr\xff");
assert_eq!(val, b"/*testns\0*testdb\0&testac\0!gr\xff");
}
}

View file

@ -1,3 +1,2 @@
pub mod ac;
pub mod all;
pub mod gr;

View file

@ -1,3 +1,4 @@
pub mod ac;
pub mod access;
pub mod all;
pub mod az;

View file

@ -3,9 +3,7 @@
/// crate::key::version !v
///
/// crate::key::root::all /
/// crate::key::root::access::all /*{ac}
/// crate::key::root::access::ac /!ac{ac}
/// crate::key::root::access::gr /*{ac}!gr{gr}
/// crate::key::root::ac /!ac{ac}
/// crate::key::root::hb /!hb{ts}/{nd}
/// crate::key::root::nd /!nd{nd}
/// crate::key::root::ni /!ni
@ -15,19 +13,21 @@
/// crate::key::node::all /${nd}
/// crate::key::node::lq /${nd}!lq{lq}{ns}{db}
///
/// crate::key::root::access::all /&{ac}
/// crate::key::root::access::gr /&{ac}!gr{gr}
///
/// crate::key::namespace::all /*{ns}
/// crate::key::namespace::access::all /*{ns}*{ac}
/// crate::key::namespace::access::ac /*{ns}!ac{ac}
/// crate::key::namespace::access::gr /*{ns}*{ac}!gr{gr}
/// crate::key::namespace::ac /*{ns}!ac{ac}
/// crate::key::namespace::db /*{ns}!db{db}
/// crate::key::namespace::di /+{ns id}!di
/// crate::key::namespace::lg /*{ns}!lg{lg}
/// crate::key::namespace::us /*{ns}!us{us}
///
/// crate::key::namespace::access::all /*{ns}&{ac}
/// crate::key::namespace::access::gr /*{ns}&{ac}!gr{gr}
///
/// crate::key::database::all /*{ns}*{db}
/// crate::key::database::access::all /*{ns}*{db}*{ac}
/// crate::key::database::access::ac /*{ns}*{db}!ac{ac}
/// crate::key::database::access::gr /*{ns}*{db}*{ac}!gr{gr}
/// crate::key::database::ac /*{ns}*{db}!ac{ac}
/// crate::key::database::az /*{ns}*{db}!az{az}
/// crate::key::database::fc /*{ns}*{db}!fn{fc}
/// crate::key::database::ml /*{ns}*{db}!ml{ml}{vn}
@ -38,6 +38,9 @@
/// crate::key::database::us /*{ns}*{db}!us{us}
/// crate::key::database::vs /*{ns}*{db}!vs
///
/// crate::key::database::access::all /*{ns}*{db}&{ac}
/// crate::key::database::access::gr /*{ns}*{db}&{ac}!gr{gr}
///
/// crate::key::table::all /*{ns}*{db}*{tb}
/// crate::key::table::ev /*{ns}*{db}*{tb}!ev{ev}
/// crate::key::table::fd /*{ns}*{db}*{tb}!fd{fd}

View file

@ -30,7 +30,7 @@ impl<'a> Access<'a> {
__: b'/',
_a: b'*',
ns,
_b: b'*',
_b: b'&',
ac,
}
}
@ -47,7 +47,7 @@ mod tests {
"testac",
);
let enc = Access::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testac\0");
assert_eq!(enc, b"/*testns\0&testac\0");
let dec = Access::decode(&enc).unwrap();
assert_eq!(val, dec);

View file

@ -46,7 +46,7 @@ impl<'a> Gr<'a> {
__: b'/',
_a: b'*',
ns,
_b: b'*',
_b: b'&',
ac,
_c: b'!',
_d: b'g',
@ -68,7 +68,7 @@ mod tests {
"testgr",
);
let enc = Gr::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testac\0!grtestgr\0");
assert_eq!(enc, b"/*testns\0&testac\0!grtestgr\0");
let dec = Gr::decode(&enc).unwrap();
assert_eq!(val, dec);
@ -77,12 +77,12 @@ mod tests {
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testac");
assert_eq!(val, b"/*testns\0*testac\0!gr\0");
assert_eq!(val, b"/*testns\0&testac\0!gr\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testac");
assert_eq!(val, b"/*testns\0*testac\0!gr\xff");
assert_eq!(val, b"/*testns\0&testac\0!gr\xff");
}
}

View file

@ -1,3 +1,2 @@
pub mod ac;
pub mod all;
pub mod gr;

View file

@ -1,3 +1,4 @@
pub mod ac;
pub mod access;
pub mod all;
pub mod db;

View file

@ -26,7 +26,7 @@ impl<'a> Access<'a> {
pub fn new(ac: &'a str) -> Self {
Self {
__: b'/',
_a: b'*',
_a: b'&',
ac,
}
}
@ -42,7 +42,7 @@ mod tests {
"testac",
);
let enc = Access::encode(&val).unwrap();
assert_eq!(enc, b"/*testac\0");
assert_eq!(enc, b"/&testac\0");
let dec = Access::decode(&enc).unwrap();
assert_eq!(val, dec);

View file

@ -42,7 +42,7 @@ impl<'a> Gr<'a> {
pub fn new(ac: &'a str, gr: &'a str) -> Self {
Self {
__: b'/',
_a: b'*',
_a: b'&',
ac,
_b: b'!',
_c: b'g',
@ -63,7 +63,7 @@ mod tests {
"testgr",
);
let enc = Gr::encode(&val).unwrap();
assert_eq!(enc, b"/*testac\0!grtestgr\0");
assert_eq!(enc, b"/&testac\0!grtestgr\0");
let dec = Gr::decode(&enc).unwrap();
assert_eq!(val, dec);
@ -72,12 +72,12 @@ mod tests {
#[test]
fn test_prefix() {
let val = super::prefix("testac");
assert_eq!(val, b"/*testac\0!gr\0");
assert_eq!(val, b"/&testac\0!gr\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testac");
assert_eq!(val, b"/*testac\0!gr\xff");
assert_eq!(val, b"/&testac\0!gr\xff");
}
}

View file

@ -1,3 +1,2 @@
pub mod ac;
pub mod all;
pub mod gr;

View file

@ -1,3 +1,4 @@
pub mod ac;
pub mod access;
pub mod all;
pub mod nd;

View file

@ -347,12 +347,12 @@ impl Transaction {
/// Retrieve all ROOT level accesses in a datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_root_accesses(&self) -> Result<Arc<[DefineAccessStatement]>, Error> {
let key = crate::key::root::access::ac::prefix();
let key = crate::key::root::ac::prefix();
let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
Ok(val) => val,
Err(cache) => {
let end = crate::key::root::access::ac::suffix();
let end = crate::key::root::ac::suffix();
let val = self.getr(key..end).await?;
let val = val.convert().into();
let val = Entry::Ras(Arc::clone(&val));
@ -423,12 +423,12 @@ impl Transaction {
/// Retrieve all namespace access definitions for a specific namespace.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_ns_accesses(&self, ns: &str) -> Result<Arc<[DefineAccessStatement]>, Error> {
let key = crate::key::namespace::access::ac::prefix(ns);
let key = crate::key::namespace::ac::prefix(ns);
let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
Ok(val) => val,
Err(cache) => {
let end = crate::key::namespace::access::ac::suffix(ns);
let end = crate::key::namespace::ac::suffix(ns);
let val = self.getr(key..end).await?;
let val = val.convert().into();
let val = Entry::Nas(Arc::clone(&val));
@ -511,12 +511,12 @@ impl Transaction {
ns: &str,
db: &str,
) -> Result<Arc<[DefineAccessStatement]>, Error> {
let key = crate::key::database::access::ac::prefix(ns, db);
let key = crate::key::database::ac::prefix(ns, db);
let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
Ok(val) => val,
Err(cache) => {
let end = crate::key::database::access::ac::suffix(ns, db);
let end = crate::key::database::ac::suffix(ns, db);
let val = self.getr(key..end).await?;
let val = val.convert().into();
let val = Entry::Das(Arc::clone(&val));
@ -825,7 +825,7 @@ impl Transaction {
/// Retrieve a specific root access definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_root_access(&self, ra: &str) -> Result<Arc<DefineAccessStatement>, Error> {
let key = crate::key::root::access::ac::new(ra).encode()?;
let key = crate::key::root::ac::new(ra).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
Ok(val) => val,
@ -916,7 +916,7 @@ impl Transaction {
ns: &str,
na: &str,
) -> Result<Arc<DefineAccessStatement>, Error> {
let key = crate::key::namespace::access::ac::new(ns, na).encode()?;
let key = crate::key::namespace::ac::new(ns, na).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
Ok(val) => val,
@ -1017,7 +1017,7 @@ impl Transaction {
db: &str,
da: &str,
) -> Result<Arc<DefineAccessStatement>, Error> {
let key = crate::key::database::access::ac::new(ns, db, da).encode()?;
let key = crate::key::database::ac::new(ns, db, da).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
Ok(val) => val,

View file

@ -83,7 +83,7 @@ impl DefineAccessStatement {
}
}
// Process the statement
let key = crate::key::root::access::ac::new(&self.name);
let key = crate::key::root::ac::new(&self.name);
txn.set(
key,
DefineAccessStatement {
@ -115,7 +115,7 @@ impl DefineAccessStatement {
}
}
// Process the statement
let key = crate::key::namespace::access::ac::new(opt.ns()?, &self.name);
let key = crate::key::namespace::ac::new(opt.ns()?, &self.name);
txn.get_or_add_ns(opt.ns()?, opt.strict).await?;
txn.set(
key,
@ -149,7 +149,7 @@ impl DefineAccessStatement {
}
}
// Process the statement
let key = crate::key::database::access::ac::new(opt.ns()?, opt.db()?, &self.name);
let key = crate::key::database::ac::new(opt.ns()?, opt.db()?, &self.name);
txn.get_or_add_ns(opt.ns()?, opt.strict).await?;
txn.get_or_add_db(opt.ns()?, opt.db()?, opt.strict).await?;
txn.set(

View file

@ -33,7 +33,7 @@ impl RemoveAccessStatement {
// Get the definition
let ac = txn.get_root_access(&self.name).await?;
// Delete the definition
let key = crate::key::root::access::ac::new(&ac.name);
let key = crate::key::root::ac::new(&ac.name);
txn.del(key).await?;
// Delete any associated data including access grants.
let key = crate::key::root::access::all::new(&ac.name);
@ -49,7 +49,7 @@ impl RemoveAccessStatement {
// Get the definition
let ac = txn.get_ns_access(opt.ns()?, &self.name).await?;
// Delete the definition
let key = crate::key::namespace::access::ac::new(opt.ns()?, &ac.name);
let key = crate::key::namespace::ac::new(opt.ns()?, &ac.name);
txn.del(key).await?;
// Delete any associated data including access grants.
let key = crate::key::namespace::access::all::new(opt.ns()?, &ac.name);
@ -65,7 +65,7 @@ impl RemoveAccessStatement {
// Get the definition
let ac = txn.get_db_access(opt.ns()?, opt.db()?, &self.name).await?;
// Delete the definition
let key = crate::key::database::access::ac::new(opt.ns()?, opt.db()?, &ac.name);
let key = crate::key::database::ac::new(opt.ns()?, opt.db()?, &ac.name);
txn.del(key).await?;
// Delete any associated data including access grants.
let key =