Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for surrealdb 2.0 #112

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ authors = ["Maxwell Flitton <[email protected]>"]
edition = "2018"

[dependencies]
surrealdb = { version = "1.2.0", features = ["protocol-ws", "protocol-http", "kv-mem"] }
surrealdb = { version = "2.0.2", features = [
"protocol-ws",
"protocol-http",
"kv-mem",
] }
serde = "^1.0.164"
futures = { version="0.3.30", features = ["executor"] }
futures = { version = "0.3.30", features = ["executor"] }
once_cell = "1.19.0"
serde_json = "^1.0.97"
crossbeam-channel = "^0.5"
Expand All @@ -20,7 +24,7 @@ futures-util-preview = "0.2.2"

[lib]
name = "rust_surrealdb"
crate-type=["cdylib"]
crate-type = ["cdylib"]

[dependencies.pyo3]
version = "0.20.0"
Expand Down
61 changes: 38 additions & 23 deletions src/operations/auth/core.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,70 @@
//! Defines the core functions for the auth operations against the database.
use surrealdb::opt::auth::Scope;
use serde_json::value::Value;
use surrealdb::opt::auth::Record;

use super::interface::WrappedJwt;
use crate::connection::interface::WrappedConnection;


/// Signs up to a specific authentication scope in an async manner.
///
///
/// # Arguments
/// * `connection` - The connection that will be performing the signup
/// * `params` - The auth parameters to be used for the signup such as email and password
/// * `namespace` - The namespace to be used for the signup
/// * `database` - The database to be used for the signup
///
///
/// # Returns
/// * `Ok(String)` - The token for the signup
pub async fn sign_up(connection: WrappedConnection, params: Value, namespace: String, database: String, scope: String) -> Result<WrappedJwt, String> {
let token = connection.connection.signup(Scope {
namespace: namespace.as_str(),
database: database.as_str(),
scope: scope.as_str(),
params: params,
}).await.map_err(|e| e.to_string())?;
let token = WrappedJwt {jwt: token};
return Ok(token)
pub async fn sign_up(
connection: WrappedConnection,
params: Value,
namespace: String,
database: String,
access: String,
) -> Result<WrappedJwt, String> {
let token = connection
.connection
.signup(Record {
namespace: namespace.as_str(),
database: database.as_str(),
access: access.as_str(),
params: params,
})
.await
.map_err(|e| e.to_string())?;
let token = WrappedJwt { jwt: token };
return Ok(token);
}


/// Invalidates the authentication for the current connection in an async manner.
///
///
/// # Arguments
/// * `connection` - The connection to be invalidated
///
///
/// # Returns
/// * `Ok(())` - The operation was successful
pub async fn invalidate(connection: WrappedConnection) -> Result<(), String> {
connection.connection.invalidate().await.map_err(|e| e.to_string())?;
return Ok(())
connection
.connection
.invalidate()
.await
.map_err(|e| e.to_string())?;
return Ok(());
}


/// Authenticates the current connection with a JWT token in an async manner.
///
///
/// # Arguments
/// * `connection` - The connection to be authenticated
/// * `jwt` - The JWT token to be used for authentication
///
///
/// # Returns
/// * `Ok(())` - The operation was successful
pub async fn authenticate(connection: WrappedConnection, jwt: WrappedJwt) -> Result<(), String> {
connection.connection.authenticate(jwt.jwt).await.map_err(|e| e.to_string())?;
return Ok(())
connection
.connection
.authenticate(jwt.jwt)
.await
.map_err(|e| e.to_string())?;
return Ok(());
}
Loading
Loading