Skip to content

Commit

Permalink
Add guest account permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikWin committed Jan 16, 2025
1 parent 33c8119 commit 3f2887e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vidformer-igni/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ enum UserCmd {
enum UserPermissionLevel {
Regular,
Test,
Guest,
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -570,6 +571,7 @@ async fn cmd_user_add(
let permissions = match add_user.permissions {
UserPermissionLevel::Regular => server::UserPermissions::default_regular(),
UserPermissionLevel::Test => server::UserPermissions::default_test(),
UserPermissionLevel::Guest => server::UserPermissions::default_guest(),
};
let user_id = ops::add_user(&pool, &name, &api_key, &permissions).await?;
println!("{}", user_id);
Expand Down
50 changes: 50 additions & 0 deletions vidformer-igni/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,56 @@ impl UserPermissions {
}
}

pub fn default_guest() -> UserPermissions {
let limits_int = [
("spec:max_width", 1280), // DCI 4K
("spec:max_height", 720), // DCI 4K
]
.iter()
.map(|(key, value)| (key.to_string(), *value))
.collect();

let limits_frac = [
("spec:max_vod_segment_length", (3, 1)),
("spec:min_vod_segment_legth", (1, 1)),
("spec:max_frame_rate", (30, 1)),
("spec:min_frame_rate", (1, 1)),
]
.iter()
.map(|(key, value)| (key.to_string(), Rational64::new(value.0, value.1)))
.collect();

let valsets = [("spec:pix_fmt", vec!["yuv420p"])]
.iter()
.map(|(key, values)| {
let values = values.iter().map(|v| v.to_string()).collect();
(key.to_string(), values)
})
.collect();

let flags = vec![
// Source permissions
"source:get",
"source:list",
"source:search",
// Spec permissions
"spec:create",
"spec:get",
"spec:push_part",
"spec:delete",
]
.into_iter()
.map(String::from)
.collect();

UserPermissions {
flags,
valsets,
limits_int,
limits_frac,
}
}

pub fn default_test() -> UserPermissions {
let mut out = UserPermissions::default_regular();
out.valsets
Expand Down

0 comments on commit 3f2887e

Please sign in to comment.