summaryrefslogtreecommitdiff
path: root/src/authorization
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-10 13:43:20 -0600
committermo khan <mo@mokhan.ca>2025-07-10 13:43:20 -0600
commitafe29973c577b32de20d876d2dd30e3a6adcc1af (patch)
tree146417cef4c8232d8413732dc25bf37008c3aac0 /src/authorization
parent42c9d320e1976e2754cc33abcaba5994f3b07f92 (diff)
refactor: rename to fetch_hierarchy
Diffstat (limited to 'src/authorization')
-rw-r--r--src/authorization/entities.rs132
1 files changed, 59 insertions, 73 deletions
diff --git a/src/authorization/entities.rs b/src/authorization/entities.rs
index 8ff4e5bd..e47cf00f 100644
--- a/src/authorization/entities.rs
+++ b/src/authorization/entities.rs
@@ -146,83 +146,69 @@ impl EntitiesRepository {
}
if project.namespace.kind == "group" {
- fetch_group_hierarchy(
- &http,
- &self.host,
- &self.token,
- project.namespace.id,
- &mut entities,
- &mut groups,
- )
- .await?;
+ self.fetch_hierarchy(&http, project.namespace.id, &mut entities, &mut groups)
+ .await?;
}
Ok(entities)
}
-}
-
-pub fn fetch_group_hierarchy<'a>(
- client: &'a reqwest::Client,
- api_url: &'a str,
- token: &'a str,
- group_id: u64,
- entities: &'a mut Vec<CedarEntity>,
- processed_groups: &'a mut HashSet<u64>,
-) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<(), Box<dyn std::error::Error>>> + 'a>>
-{
- Box::pin(async move {
- if processed_groups.contains(&group_id) {
- return Ok(());
- }
-
- processed_groups.insert(group_id);
-
- let group_url = format!(
- "{}/api/v4/groups/{}",
- api_url.trim_end_matches('/'),
- group_id
- );
-
- let group: Group = client
- .get(&group_url)
- .header("PRIVATE-TOKEN", token)
- .send()
- .await?
- .error_for_status()?
- .json()
- .await?;
-
- let parents = if let Some(parent_id) = group.parent_id {
- fetch_group_hierarchy(
- client,
- api_url,
- token,
- parent_id,
- entities,
- processed_groups,
- )
- .await?;
- vec![CedarParent {
- parent_type: "Group".to_string(),
- id: parent_id.to_string(),
- }]
- } else {
- vec![]
- };
- entities.push(CedarEntity {
- uid: CedarUid {
- entity_type: "Group".to_string(),
- id: group.id.to_string(),
- },
- attrs: serde_json::json!({
- "name": group.name,
- "path": group.path,
- "full_path": group.full_path,
- }),
- parents,
- });
+ fn fetch_hierarchy<'a>(
+ &'a self,
+ client: &'a reqwest::Client,
+ group_id: u64,
+ entities: &'a mut Vec<CedarEntity>,
+ groups: &'a mut HashSet<u64>,
+ ) -> std::pin::Pin<
+ Box<dyn std::future::Future<Output = Result<(), Box<dyn std::error::Error>>> + 'a>,
+ > {
+ Box::pin(async move {
+ if groups.contains(&group_id) {
+ return Ok(());
+ }
- Ok(())
- })
+ groups.insert(group_id);
+
+ let group_url = format!(
+ "{}/api/v4/groups/{}",
+ self.host.trim_end_matches('/'),
+ group_id
+ );
+
+ let group: Group = client
+ .get(&group_url)
+ .header("PRIVATE-TOKEN", &self.token)
+ .send()
+ .await?
+ .error_for_status()?
+ .json()
+ .await?;
+
+ let parents = if let Some(parent_id) = group.parent_id {
+ self.fetch_hierarchy(client, parent_id, entities, groups)
+ .await?;
+ vec![CedarParent {
+ parent_type: "Group".to_string(),
+ id: parent_id.to_string(),
+ }]
+ } else {
+ vec![]
+ };
+
+ entities.push(CedarEntity {
+ uid: CedarUid {
+ entity_type: "Group".to_string(),
+ id: group.id.to_string(),
+ },
+ attrs: serde_json::json!({
+ "name": group.name,
+ "path": group.path,
+ "full_path": group.full_path,
+ }),
+ parents,
+ });
+
+ Ok(())
+ })
+ }
}