Skip to content

Commit 814367a

Browse files
committed
SBOM Browser: Pagination / Regex fix
1 parent 0c42c64 commit 814367a

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

tools/harbor_sbom_browser/src/handlers/artifact_tree.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl IntoResponse for ArtifactTreeError {
4343

4444
lazy_static! {
4545
static ref RELEASE_TAG_REGEX: Regex =
46-
Regex::new(r"^(?P<prefix>.+\-stackable)?(?P<release>\d+\.\d+\.\d+(\-dev?))$").unwrap();
46+
Regex::new(r"^(?P<prefix>.+\-stackable)?(?P<release>\d+\.\d+\.\d+(\-dev)?)$").unwrap();
4747
}
4848

4949
pub async fn render_as_html(
@@ -189,17 +189,31 @@ pub async fn process_artifacts(
189189
repository_name: &str,
190190
artifact_tree: Arc<Mutex<ArtifactTree>>,
191191
) -> Result<(), ArtifactTreeError> {
192-
let artifacts: Vec<Artifact> = reqwest::get(format!(
193-
"{}/projects/{}/repositories/{}/artifacts",
194-
base_url,
195-
encode(project_name),
196-
encode(repository_name)
197-
))
198-
.await
199-
.context(GetArtifactsSnafu)?
200-
.json()
201-
.await
202-
.context(ParseArtifactsSnafu)?;
192+
let mut artifacts: Vec<Artifact> = Vec::with_capacity(64);
193+
let mut page = 1;
194+
let page_size = 20;
195+
loop {
196+
let artifacts_page: Vec<Artifact> = reqwest::get(format!(
197+
"{}/projects/{}/repositories/{}/artifacts?page_size={}&page={}",
198+
base_url,
199+
encode(project_name),
200+
encode(repository_name),
201+
page_size,
202+
page
203+
))
204+
.await
205+
.context(GetArtifactsSnafu)?
206+
.json()
207+
.await
208+
.context(ParseArtifactsSnafu)?;
209+
210+
let number_of_returned_artifacts = artifacts_page.len();
211+
artifacts.extend(artifacts_page);
212+
if number_of_returned_artifacts < page_size {
213+
break;
214+
}
215+
page += 1;
216+
}
203217

204218
for artifact in &artifacts {
205219
let has_release_tag = artifact.tags.as_ref().and_then(|tags| {
@@ -229,4 +243,4 @@ pub async fn process_artifacts(
229243
}
230244

231245
Ok(())
232-
}
246+
}

0 commit comments

Comments
 (0)