From 72f4df12adc5745e5d5a528c5c075be71532f22a Mon Sep 17 00:00:00 2001 From: subcrip Date: Tue, 9 Apr 2024 00:10:13 +0800 Subject: [PATCH] feat(db): resource db access --- src/db.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/db.rs b/src/db.rs index 38178e5..9a558c9 100644 --- a/src/db.rs +++ b/src/db.rs @@ -84,7 +84,7 @@ impl OAuthDatabase { /// Applicant: client pub async fn trusted_register_access(&mut self, app: &crate::oauth_types::oauth_application::OAuthHashedApplication, scope: &crate::oauth_types::oauth_scope::OAuthScope) -> Result<(), tokio_postgres::Error> { let access = crate::oauth_types::oauth_access::OAuthApplicationAccess::create(app, scope); - self.psql_execute("insert into ApplicationAccess(access_id, client_id, scope_id) values($1, $2, $3)", &[&access.access_id, &access.client_id, &access.scope_id]).await?; + self.psql_execute("insert into ApplicationAccess(access_id, client_id, scope_id) values ($1, $2, $3)", &[&access.access_id, &access.client_id, &access.scope_id]).await?; Ok(()) } @@ -98,15 +98,22 @@ impl OAuthDatabase { /// Issue a master token. /// Applicant: master - pub async fn trusted_issue_master_token(&mut self, description: &String) -> Result { + pub async fn trusted_issue_master_db_token(&mut self, description: &String) -> Result { // TEST: functionality let access = crate::oauth_types::oauth_access::OAuthMasterDBAccess::create(description); let hashed = crate::oauth_types::oauth_access::OAuthHashedMasterDBAccess::from(&access); - self.psql_execute("insert into MasterDBAccess(master_db_id, master_db_token, master_db_desc) values($1, $2, $3)", &[&hashed.master_db_id, &hashed.master_db_token, &hashed.master_db_desc]).await?; + self.psql_execute("insert into MasterDBAccess(master_db_id, master_db_token, master_db_desc) values ($1, $2, $3)", &[&hashed.master_db_id, &hashed.master_db_token, &hashed.master_db_desc]).await?; Ok(access) } // TODO: other type of db tokens + pub async fn trusted_issue_resource_db_token(&mut self, resource_id: &Uuid, description: &String) -> Result { + // TEST: functionality + let access = crate::oauth_types::oauth_access::OAuthResourceDBAccess::create(resource_id, description); + let hashed = crate::oauth_types::oauth_access::OAuthHashedResourceDBAccess::from(&access); + self.psql_execute("insert into ResourceDBAccess(resource_db_id, resource_id, resource_db_token, resource_db_desc) values ($1, $2, $3, $4)", &[&hashed.resource_db_id, &hashed.resource_id, &hashed.resource_db_token, &hashed.resource_db_desc]).await?; + Ok(access) + } } #[cfg(test)]