Skip to content

Commit

Permalink
Add descriptive comments about pagination loops
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Nelson <minelson@vmware.com>
  • Loading branch information
absoludity committed Aug 8, 2023
1 parent d3e097b commit 0add7d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion cmd/oci-catalog/src/providers/dockerhub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<Result<Repository, Status>>,
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 9 additions & 4 deletions cmd/oci-catalog/src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result<Repository, Status>>,
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<Result<Tag, Status>>, request: &ListTagsRequest);

// The id simply gives a way in tests to determine which provider
Expand Down

0 comments on commit 0add7d4

Please sign in to comment.