Skip to content

Commit

Permalink
Parse sessionspace gid as u32
Browse files Browse the repository at this point in the history
  • Loading branch information
garryod committed Aug 20, 2024
1 parent 1ed9b86 commit 89c3e9d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
7 changes: 7 additions & 0 deletions sessionspaces/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sessionspaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ clap = { version = "4.5.16", features = ["derive", "env"] }
derive_more = { version = "1.0.0", features = ["deref", "deref_mut"] }
dotenvy = { version = "0.15.7" }
humantime = { version = "2.1.0" }
if_chain = "1.0.2"
itertools = { version = "0.13.0" }
k8s-openapi = { version = "0.22.0", features = ["latest"] }
kube = { version = "0.93.1" }
Expand Down
2 changes: 1 addition & 1 deletion sessionspaces/src/permissionables/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct Session {
/// A set of session members
pub members: BTreeSet<String>,
/// The posix GID of the session group
pub gid: Option<String>,
pub gid: Option<u32>,
/// The session start date and time
pub start_date: PrimitiveDateTime,
/// The session end date and time
Expand Down
22 changes: 11 additions & 11 deletions sessionspaces/src/permissionables/posix_attributes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use derive_more::{Deref, DerefMut};
use if_chain::if_chain;
use ldap3::{Ldap, LdapError, Scope, SearchEntry};
use std::collections::BTreeMap;

Expand All @@ -10,7 +11,7 @@ pub struct SessionPosixAttributes(BTreeMap<String, PosixAttributes>);
#[derive(Debug)]
pub struct PosixAttributes {
/// The posix Group ID of the session group
pub gid: String,
pub gid: u32,
}

impl SessionPosixAttributes {
Expand All @@ -29,16 +30,15 @@ impl SessionPosixAttributes {
let mut posix_attributes = Self::default();
for result_entry in rs {
let mut search_entry = SearchEntry::construct(result_entry);
if let Some(Ok([gid])) = search_entry
.attrs
.remove("gidNumber")
.map(<[_; 1]>::try_from)
{
if let Some(Ok([session_name])) =
search_entry.attrs.remove("cn").map(<[_; 1]>::try_from)
{
posix_attributes
.insert(session_name.replace('_', "-"), PosixAttributes { gid });
if_chain! {
if let Some(gids) = search_entry.attrs.remove("gidNumber");
if let Ok([gid]) = <[_;1]>::try_from(gids);
if let Ok(gid) = gid.parse();
then {
if let Some(Ok([session_name])) = search_entry.attrs.remove("cn").map(<[_;1]>::try_from) {
posix_attributes
.insert(session_name.replace('_', "-"), PosixAttributes { gid });
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sessionspaces/src/resources/config_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub async fn create_configmap(
("end_date".to_string(), session.end_date.to_string()),
]);
if let Some(gid) = session.gid {
configmap_data.insert("gid".to_string(), gid);
configmap_data.insert("gid".to_string(), gid.to_string());
}
if let Some(mount_path) = mount_path {
configmap_data.insert(
Expand Down

0 comments on commit 89c3e9d

Please sign in to comment.