-
Notifications
You must be signed in to change notification settings - Fork 20
refactor: decouple auth_manager and pg_catalog #192
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
Merged
+164
−123
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
use std::fmt::Debug; | ||
|
||
use async_trait::async_trait; | ||
|
||
#[async_trait] | ||
pub trait PgCatalogContextProvider: Clone + Debug + Send + Sync + 'static { | ||
// retrieve all database role names | ||
async fn roles(&self) -> Vec<String> { | ||
vec![] | ||
} | ||
|
||
// retrieve database role information | ||
async fn role(&self, _name: &str) -> Option<Role> { | ||
None | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct EmptyContextProvider; | ||
|
||
impl PgCatalogContextProvider for EmptyContextProvider {} | ||
|
||
/// User information stored in the authentication system | ||
#[derive(Debug, Clone)] | ||
pub struct User { | ||
pub username: String, | ||
pub password_hash: String, | ||
pub roles: Vec<String>, | ||
pub is_superuser: bool, | ||
pub can_login: bool, | ||
pub connection_limit: Option<i32>, | ||
} | ||
|
||
/// Permission types for granular access control | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub enum Permission { | ||
Select, | ||
Insert, | ||
Update, | ||
Delete, | ||
Create, | ||
Drop, | ||
Alter, | ||
Index, | ||
References, | ||
Trigger, | ||
Execute, | ||
Usage, | ||
Connect, | ||
Temporary, | ||
All, | ||
} | ||
|
||
impl Permission { | ||
pub fn from_string(s: &str) -> Option<Permission> { | ||
match s.to_uppercase().as_str() { | ||
"SELECT" => Some(Permission::Select), | ||
"INSERT" => Some(Permission::Insert), | ||
"UPDATE" => Some(Permission::Update), | ||
"DELETE" => Some(Permission::Delete), | ||
"CREATE" => Some(Permission::Create), | ||
"DROP" => Some(Permission::Drop), | ||
"ALTER" => Some(Permission::Alter), | ||
"INDEX" => Some(Permission::Index), | ||
"REFERENCES" => Some(Permission::References), | ||
"TRIGGER" => Some(Permission::Trigger), | ||
"EXECUTE" => Some(Permission::Execute), | ||
"USAGE" => Some(Permission::Usage), | ||
"CONNECT" => Some(Permission::Connect), | ||
"TEMPORARY" => Some(Permission::Temporary), | ||
"ALL" => Some(Permission::All), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
/// Resource types for access control | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub enum ResourceType { | ||
Table(String), | ||
Schema(String), | ||
Database(String), | ||
Function(String), | ||
Sequence(String), | ||
All, | ||
} | ||
|
||
/// Grant entry for specific permissions on resources | ||
#[derive(Debug, Clone)] | ||
pub struct Grant { | ||
pub permission: Permission, | ||
pub resource: ResourceType, | ||
pub granted_by: String, | ||
pub with_grant_option: bool, | ||
} | ||
|
||
/// Role information for access control | ||
#[derive(Debug, Clone)] | ||
pub struct Role { | ||
pub name: String, | ||
pub is_superuser: bool, | ||
pub can_login: bool, | ||
pub can_create_db: bool, | ||
pub can_create_role: bool, | ||
pub can_create_user: bool, | ||
pub can_replication: bool, | ||
pub grants: Vec<Grant>, | ||
pub inherited_roles: Vec<String>, | ||
} | ||
|
||
/// Role configuration for creation | ||
#[derive(Debug, Clone)] | ||
pub struct RoleConfig { | ||
pub name: String, | ||
pub is_superuser: bool, | ||
pub can_login: bool, | ||
pub can_create_db: bool, | ||
pub can_create_role: bool, | ||
pub can_create_user: bool, | ||
pub can_replication: bool, | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.