summaryrefslogtreecommitdiff
path: root/src/authorization/entities.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/authorization/entities.rs')
-rw-r--r--src/authorization/entities.rs48
1 files changed, 15 insertions, 33 deletions
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<Vec<CedarEntity>, Box<dyn std::error::Error>> {
- 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?
@@ -97,17 +95,6 @@ impl EntitiesRepository {
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(),
id: project.id.to_string(),
},
@@ -132,7 +119,7 @@ impl EntitiesRepository {
project.id
);
- let members: Vec<Member> = client
+ let members: Vec<Member> = 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 {