From 51dc342dead1408993c6a2d9d27471d5da7fd9d3 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 10 Jul 2025 13:23:38 -0600 Subject: refactor: remove hard-coded organization --- src/authorization/entities.rs | 48 ++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/authorization/entities.rs b/src/authorization/entities.rs index 4824fdd8..8ff4e5bd 100644 --- a/src/authorization/entities.rs +++ b/src/authorization/entities.rs @@ -63,31 +63,29 @@ pub struct Group { pub struct EntitiesRepository { pub token: String, pub host: String, - pub project: String, + pub project_url: String, } impl EntitiesRepository { pub fn new(token: String, host: String, project: String) -> EntitiesRepository { EntitiesRepository { token: token, - host: host, - project: project, + host: host.clone(), + project_url: format!( + "{}/api/v4/projects/{}", + host.trim_end_matches('/'), + urlencoding::encode(&project) + ), } } pub async fn all(&self) -> Result, Box> { - let client = reqwest::Client::new(); + let http = reqwest::Client::new(); let mut entities = Vec::new(); - let mut processed_groups = HashSet::new(); + let mut groups = HashSet::new(); - let project_url = format!( - "{}/api/v4/projects/{}", - self.host.trim_end_matches('/'), - urlencoding::encode(&self.project) - ); - - let project: Project = client - .get(&project_url) + let project: Project = http + .get(&self.project_url) .header("PRIVATE-TOKEN", &self.token) .send() .await? @@ -95,17 +93,6 @@ impl EntitiesRepository { .json() .await?; - entities.push(CedarEntity { - uid: CedarUid { - entity_type: "Organization".to_string(), - id: "1".to_string(), - }, - attrs: serde_json::json!({ - "name": "gitlab", - }), - parents: vec![], - }); - entities.push(CedarEntity { uid: CedarUid { entity_type: "Project".to_string(), @@ -132,7 +119,7 @@ impl EntitiesRepository { project.id ); - let members: Vec = client + let members: Vec = http .get(&members_url) .header("PRIVATE-TOKEN", &self.token) .send() @@ -160,12 +147,12 @@ impl EntitiesRepository { if project.namespace.kind == "group" { fetch_group_hierarchy( - &client, + &http, &self.host, &self.token, project.namespace.id, &mut entities, - &mut processed_groups, + &mut groups, ) .await?; } @@ -206,7 +193,6 @@ pub fn fetch_group_hierarchy<'a>( .await?; let parents = if let Some(parent_id) = group.parent_id { - // Recursively fetch parent group fetch_group_hierarchy( client, api_url, @@ -221,11 +207,7 @@ pub fn fetch_group_hierarchy<'a>( id: parent_id.to_string(), }] } else { - // Top-level group belongs to organization - vec![CedarParent { - parent_type: "Organization".to_string(), - id: "1".to_string(), - }] + vec![] }; entities.push(CedarEntity { -- cgit v1.2.3