Skip to content

Commit

Permalink
zenohd does not override configured adminspace permissions when --adm…
Browse files Browse the repository at this point in the history
…inspace-permissions argument is not present (eclipse-zenoh#624)
  • Loading branch information
OlivierHecart authored Dec 14, 2023
1 parent 677b2b4 commit 7340153
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions zenohd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ struct Args {
#[arg(long)]
cfg: Vec<String>,
/// Configure the read and/or write permissions on the admin space. Default is read only.
#[arg(long, default_value = "r", value_name = "[r|w|rw|none]")]
adminspace_permissions: String,
#[arg(long, value_name = "[r|w|rw|none]")]
adminspace_permissions: Option<String>,
}

fn main() {
Expand Down Expand Up @@ -271,40 +271,42 @@ fn config_from_args(args: &Args) -> Config {
}
(false, false) => {}
};
match args.adminspace_permissions.as_str() {
"r" => config
.adminspace
.set_permissions(PermissionsConf {
read: true,
write: false,
})
.unwrap(),
"w" => config
.adminspace
.set_permissions(PermissionsConf {
read: false,
write: true,
})
.unwrap(),
"rw" => config
.adminspace
.set_permissions(PermissionsConf {
read: true,
write: true,
})
.unwrap(),
"none" => config
.adminspace
.set_permissions(PermissionsConf {
read: false,
write: false,
})
.unwrap(),
s => panic!(
r#"Invalid option: --adminspace-permissions={} - Accepted values: "r", "w", "rw" or "none""#,
s
),
};
if let Some(adminspace_permissions) = &args.adminspace_permissions {
match adminspace_permissions.as_str() {
"r" => config
.adminspace
.set_permissions(PermissionsConf {
read: true,
write: false,
})
.unwrap(),
"w" => config
.adminspace
.set_permissions(PermissionsConf {
read: false,
write: true,
})
.unwrap(),
"rw" => config
.adminspace
.set_permissions(PermissionsConf {
read: true,
write: true,
})
.unwrap(),
"none" => config
.adminspace
.set_permissions(PermissionsConf {
read: false,
write: false,
})
.unwrap(),
s => panic!(
r#"Invalid option: --adminspace-permissions={} - Accepted values: "r", "w", "rw" or "none""#,
s
),
};
}
for json in &args.cfg {
if let Some((key, value)) = json.split_once(':') {
match json5::Deserializer::from_str(value) {
Expand Down

0 comments on commit 7340153

Please sign in to comment.