Skip to content

Commit

Permalink
Introduce basic label generation, qr generation, and engine logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Jul 22, 2024
1 parent 0925a15 commit 6401550
Show file tree
Hide file tree
Showing 16 changed files with 1,279 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"vsicons.associations.folders": [
{ "icon": "engine", "extensions": ["engine"], "format": "svg" }
],
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions service/src/main.rs → engine/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use tracing::info;

mod router;
mod state;
mod permissions;

#[tokio::main]
async fn main() {
Expand Down
51 changes: 51 additions & 0 deletions engine/src/permissions/default_rules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use crate::permissions::rule::{PermissionedEntity, Rule, RuleOutput};

/**
*
* Examples rules for permissions (impl Rule):
* - byOrg(ruleOutput, org)
* - byUser(ruleOutput, user)
* - byGroup(ruleOutput, group)
*
*/

#[derive(Debug, Clone)]
pub struct ByOrgRule {
pub rule_output: RuleOutput,
pub org: String,
}

impl Rule for ByOrgRule {
fn check(&self, entity: PermissionedEntity) -> RuleOutput {
match entity {
PermissionedEntity::Organization(org) => {
if org == self.org {
self.rule_output
}
else {
RuleOutput::PASSTHROUGH
}
},
_ => RuleOutput::PASSTHROUGH,
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_by_org_rule() {
let rule = ByOrgRule {
rule_output: RuleOutput::READ,
org: "test".to_string(),
};

let entity = PermissionedEntity::Organization("test".to_string());
assert_eq!(rule.check(entity), RuleOutput::READ);

let entity = PermissionedEntity::Organization("other".to_string());
assert_eq!(rule.check(entity), RuleOutput::NONE);
}
}
2 changes: 2 additions & 0 deletions engine/src/permissions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod rule;
mod default_rules;
18 changes: 18 additions & 0 deletions engine/src/permissions/rule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum RuleOutput {
DISSALOW,
READ,
WRITE,
PASSTHROUGH,
}

#[derive(Debug, Clone)]
pub enum PermissionedEntity {
Organization(String),
User(String),
Group(String),
}

pub trait Rule {
fn check(&self, entity: PermissionedEntity) -> RuleOutput;
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6401550

Please sign in to comment.