From 0add7d417be1ca173cdbfc7736c0a658d76c4f60 Mon Sep 17 00:00:00 2001 From: Michael Nelson Date: Wed, 9 Aug 2023 06:33:00 +1000 Subject: [PATCH] Add descriptive comments about pagination loops Signed-off-by: Michael Nelson --- cmd/oci-catalog/src/providers/dockerhub.rs | 6 +++++- cmd/oci-catalog/src/providers/mod.rs | 13 +++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmd/oci-catalog/src/providers/dockerhub.rs b/cmd/oci-catalog/src/providers/dockerhub.rs index 74e7f8b2f63..80bfc082ec9 100644 --- a/cmd/oci-catalog/src/providers/dockerhub.rs +++ b/cmd/oci-catalog/src/providers/dockerhub.rs @@ -10,6 +10,7 @@ use tokio::sync::mpsc; use tonic::Status; /// The default page size with which requests are sent to docker hub. +/// We fetch all results in batches of this page size. const DEFAULT_PAGE_SIZE: u8 = 100; pub const PROVIDER_NAME: &str = "DockerHubAPI"; pub const DOCKERHUB_URI: &str = "https://hub.docker.com"; @@ -54,7 +55,6 @@ impl OCICatalogSender for DockerHubAPI { PROVIDER_NAME } - // Update to return a result so errors are handled properly. async fn send_repositories( &self, tx: mpsc::Sender>, @@ -64,6 +64,8 @@ impl OCICatalogSender for DockerHubAPI { let client = reqwest::Client::builder().build().unwrap(); + // We continue making the request until there is no `next` url + // in the result. loop { log::debug!("requesting: {}", url); let response = match client.get(url.clone()).send().await { @@ -132,6 +134,8 @@ impl OCICatalogSender for DockerHubAPI { let client = reqwest::Client::builder().build().unwrap(); + // We continue making the request until there is no `next` url + // in the result. loop { log::debug!("requesting: {}", url); let response = match client.get(url.clone()).send().await { diff --git a/cmd/oci-catalog/src/providers/mod.rs b/cmd/oci-catalog/src/providers/mod.rs index f59cb0f6975..4546379c4fa 100644 --- a/cmd/oci-catalog/src/providers/mod.rs +++ b/cmd/oci-catalog/src/providers/mod.rs @@ -9,17 +9,22 @@ use tonic::Status; pub mod dockerhub; -// OCICatalogSender is a trait that can be implemented by different providers. -// -// Initially we'll provide a DockerHub implementation followed by Harbor and -// others. +/// OCICatalogSender is a trait that can be implemented by different providers. +/// +/// Initially we'll provide a DockerHub implementation followed by Harbor and +/// others. #[tonic::async_trait] pub trait OCICatalogSender { + /// send_repositories requests repositories from the provider and sends + /// them down a channel for our API to return. async fn send_repositories( &self, tx: mpsc::Sender>, request: &ListRepositoriesRequest, ); + + /// send_tags requests tags for a repository of a provider and sends + /// them down a channel for our API to return. async fn send_tags(&self, tx: mpsc::Sender>, request: &ListTagsRequest); // The id simply gives a way in tests to determine which provider