pub struct Galaxy { /* private fields */ }Expand description
A Galaxy is the storage engine for one TuGraph instance. It manages a set of
User/Role/GraphDBs.
A galaxy can be opened in async mode, in which case ALL write transactions will be treated as async, whether they declare async or not. This can come in handy if we are performing a lot of writing, but can cause data loss for online processing.
Implementations§
Source§impl Galaxy
impl Galaxy
Sourcepub fn open<P: AsRef<Path>>(
dir: P,
username: &str,
password: &str,
) -> Result<Galaxy>
pub fn open<P: AsRef<Path>>( dir: P, username: &str, password: &str, ) -> Result<Galaxy>
Open Galaxy at dir with username and password
If more options are need to open, use OpenOptions instead.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/galaxy_open", "admin", "73@TuGraph")?;Sourcepub fn set_user_without_auth(&self, user: &str) -> Result<()>
pub fn set_user_without_auth(&self, user: &str) -> Result<()>
Switch current user without authorization.
Note: It is you user’s responsibility to make sure the current user have right permissions to switch.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/set_user_without_auth", "admin", "73@TuGraph")?;
galaxy.set_user_without_auth("test_user1");Sourcepub fn create_graph(
&self,
name: &str,
desc: &str,
max_size: usize,
) -> Result<bool>
pub fn create_graph( &self, name: &str, desc: &str, max_size: usize, ) -> Result<bool>
Create graph with name, description and max size in bytes of graph stored in filesystem.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::{OpenOptions, MINIMUM_GRAPH_MAX_SIZE}, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/create_graph", "admin", "73@TuGraph")?;
let _ = galaxy.create_graph(
"test_create_graph",
"graph created in test_create_graph",
MINIMUM_GRAPH_MAX_SIZE,
)?;Sourcepub fn delete_graph(&self, graph: &str) -> Result<bool>
pub fn delete_graph(&self, graph: &str) -> Result<bool>
Create graph with name, description and max size in bytes of graph stored in filesystem.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::{OpenOptions, MINIMUM_GRAPH_MAX_SIZE}, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/delete_graph", "admin", "73@TuGraph")?;
let _ = galaxy.create_graph(
"test_create_graph",
"graph created in test_create_graph",
MINIMUM_GRAPH_MAX_SIZE,
)?;Sourcepub fn mod_graph(&self) -> ModGraphOptions<'_>
pub fn mod_graph(&self) -> ModGraphOptions<'_>
Modify graph info.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/mod_graph", "admin", "73@TuGraph")?;
let modified = galaxy
.mod_graph()
.mod_desc("The new description of default graph".to_string())
.apply("default")?;Sourcepub fn list_graphs(&self) -> Result<Vec<ListGraph>>
pub fn list_graphs(&self) -> Result<Vec<ListGraph>>
Sourcepub fn delete_user(&self, username: &str) -> Result<bool>
pub fn delete_user(&self, username: &str) -> Result<bool>
Delete a user.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/delete_user", "admin", "73@TuGraph")?;
galaxy.create_user("test_user1", "test_password1", "user one")?;
let deleted = galaxy.delete_user("test_user1")?;
assert!(deleted);Sourcepub fn set_password(
&self,
username: &str,
old_password: &str,
new_password: &str,
) -> Result<bool>
pub fn set_password( &self, username: &str, old_password: &str, new_password: &str, ) -> Result<bool>
Set the password of the specified user.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/set_password", "admin", "73@TuGraph")?;
galaxy.set_password("test_user1", "test_password1", "new_password1")?;Sourcepub fn set_user_roles<'a, R>(&self, username: &str, roles: R) -> Result<bool>where
R: IntoIterator<Item = &'a str>,
pub fn set_user_roles<'a, R>(&self, username: &str, roles: R) -> Result<bool>where
R: IntoIterator<Item = &'a str>,
Set the roles of the specified user. If you need to add or delete a role, you will need to use GetUserInfo to get the roles first.
Note: Only admin can set user roles.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/set_user_roles", "admin", "73@TuGraph")?;
galaxy.create_user("test_user1", "test_password1", "test user one")?;
galaxy.create_role("operator", "A good operator")?;
galaxy.create_role("crud_boy", "Create, retrieve, update and delete data all day")?;
galaxy.set_user_roles("test_user1", ["operator", "crud_boy"])?;Sourcepub fn set_user_graph_access(
&self,
username: &str,
graph: &str,
access: AccessLevel,
) -> Result<bool>
pub fn set_user_graph_access( &self, username: &str, graph: &str, access: AccessLevel, ) -> Result<bool>
Sets user access rights on a graph.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, types::AccessLevel, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/set_user_graph_access", "admin", "73@TuGraph")?;
galaxy
.set_user_graph_access("test_user1", "default", AccessLevel::Full)?;Sourcepub fn disable_user(&self, username: &str) -> Result<bool>
pub fn disable_user(&self, username: &str) -> Result<bool>
Disable a user. A disabled user is not able to login or perform any operation. A user cannot disable itself.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/disable_user", "admin", "73@TuGraph")?;
galaxy.create_user("test_user1", "test_password1", "user one")?;
galaxy.disable_user("test_user1")?;Sourcepub fn enable_user(&self, username: &str) -> Result<bool>
pub fn enable_user(&self, username: &str) -> Result<bool>
Enable a user.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/enable_user", "admin", "73@TuGraph")?;
galaxy.create_user("test_user1", "test_password1", "user one")?;
galaxy.disable_user("test_user1")?;
galaxy.enable_user("test_user1")?;Sourcepub fn list_users(&self) -> Result<Vec<ListUser>>
pub fn list_users(&self) -> Result<Vec<ListUser>>
List all users
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/list_users", "admin", "73@TuGraph")?;
galaxy
.create_user("test_user1", "test_password1", "user one")?;
galaxy
.create_user("test_user2", "test_password2", "user two")?;
let users = galaxy.list_users()?;Sourcepub fn get_user_info(&self, username: &str) -> Result<UserInfo>
pub fn get_user_info(&self, username: &str) -> Result<UserInfo>
Get user information
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/get_user_info", "admin", "73@TuGraph")?;
galaxy
.create_user("test_user1", "test_password1", "user one")?;
let info = galaxy.get_user_info("test_user1")?;Sourcepub fn create_role(&self, role: &str, desc: &str) -> Result<bool>
pub fn create_role(&self, role: &str, desc: &str) -> Result<bool>
Create a role. A role has different access levels to different graphs. Every user must be assigned some role to get access to graphs.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/create_role", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;Sourcepub fn delete_role(&self, role: &str) -> Result<bool>
pub fn delete_role(&self, role: &str) -> Result<bool>
Deletes the role.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/delete_role", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
galaxy.delete_role("operator")?;Sourcepub fn disable_role(&self, role: &str) -> Result<bool>
pub fn disable_role(&self, role: &str) -> Result<bool>
Disable a role.
A disabled role still has the data, but is not effective. i.e., users will not have access rights to graphs that are obtained by having this role.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/disable_role", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
galaxy.disable_role("operator")?;Sourcepub fn enable_role(&self, role: &str) -> Result<bool>
pub fn enable_role(&self, role: &str) -> Result<bool>
Enable the role.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/enable_role", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
galaxy.disable_role("operator")?;
galaxy.enable_role("operator")?;Sourcepub fn set_role_desc(&self, role: &str, desc: &str) -> Result<bool>
pub fn set_role_desc(&self, role: &str, desc: &str) -> Result<bool>
Set the description of the specified role
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/set_role_desc", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
galaxy.set_role_desc("operator", "a good operator")?;Sourcepub fn set_role_access_rights<'a, T>(
&self,
role: &str,
graph_access: T,
) -> Result<bool>where
T: IntoIterator<Item = &'a GraphAccess>,
pub fn set_role_access_rights<'a, T>(
&self,
role: &str,
graph_access: T,
) -> Result<bool>where
T: IntoIterator<Item = &'a GraphAccess>,
Set access of the role to graphs.
If you need to add or remove access to part of the graphs, you need to get full graph_access map by using GetRoleInfo first.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{
db::{OpenOptions, GraphAccess},
types::AccessLevel,
Error,
};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/set_role_access_rights", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
galaxy.set_role_access_rights(
"operator",
&[GraphAccess {
name: "default".to_string(),
access_level: AccessLevel::Full,
}],
)?;Sourcepub fn set_role_access_rights_incremental<'a, T>(
&self,
role: &str,
graph_access: T,
) -> Result<bool>where
T: IntoIterator<Item = &'a GraphAccess>,
pub fn set_role_access_rights_incremental<'a, T>(
&self,
role: &str,
graph_access: T,
) -> Result<bool>where
T: IntoIterator<Item = &'a GraphAccess>,
Incrementally modify the access right of the specified role.
For example, for a role that has access right {graph1:READ, graph2:WRITE}, calling this function with graph_access={graph2:READ, graph3:FULL} will set the access right of this role to {graph1:READ, graph2:READ, graph3:FULL}
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{
db::{OpenOptions, GraphAccess, MINIMUM_GRAPH_MAX_SIZE},
types::AccessLevel,
Error,
};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/set_role_access_rights_incremental", "admin", "73@TuGraph")?;
galaxy
.create_graph("test_graph1", "test graph one", MINIMUM_GRAPH_MAX_SIZE)?;
galaxy.create_role("operator", "a operator role")?;
galaxy.set_role_access_rights_incremental(
"operator",
&[GraphAccess {
name: "default".to_string(),
access_level: AccessLevel::Write,
}],
)?;
galaxy.set_role_access_rights_incremental(
"operator",
&[GraphAccess {
name: "test_graph1".to_string(),
access_level: AccessLevel::Read,
}],
)?;Sourcepub fn get_role_info(&self, role: &str) -> Result<RoleInfo>
pub fn get_role_info(&self, role: &str) -> Result<RoleInfo>
Gets role information.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::{OpenOptions, GraphAccess}, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/get_role_info", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
let info = galaxy.get_role_info("operator")?;Sourcepub fn list_roles(&self) -> Result<Vec<ListRole>>
pub fn list_roles(&self) -> Result<Vec<ListRole>>
List all the roles.
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::{OpenOptions, GraphAccess}, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/list_roles", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
let roles: Vec<_> = galaxy.list_roles()?;Sourcepub fn get_access_level(
&self,
username: &str,
graph: &str,
) -> Result<AccessLevel>
pub fn get_access_level( &self, username: &str, graph: &str, ) -> Result<AccessLevel>
Get the access level that the specified user have to the graph
§Errors
TODO(eadrenking@outlook.com)
§Examples
use tugraph::{db::{OpenOptions, GraphAccess}, Error};
let galaxy = OpenOptions::new()
.create(true)
.open("/tmp/rust_tugraph/doc/get_access_level", "admin", "73@TuGraph")?;
galaxy.get_access_level("admin", "default")?;