Skip to content

Commit dce1320

Browse files
committed
introduce constant and doc comments
1 parent 39ca7ca commit dce1320

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

rust/stackable-cockpit/src/constants.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ pub const PRODUCT_NAMES: &[&str] = &[
4141
"trino",
4242
"zookeeper",
4343
];
44+
45+
pub const OCI_INDEX_PAGE_SIZE: usize = 20;

rust/stackable-cockpit/src/oci.rs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use tracing::debug;
66
use urlencoding::encode;
77

88
use crate::{
9-
constants::{HELM_OCI_BASE, HELM_REPO_NAME_DEV, HELM_REPO_NAME_STABLE, HELM_REPO_NAME_TEST},
9+
constants::{
10+
HELM_OCI_BASE, HELM_REPO_NAME_DEV, HELM_REPO_NAME_STABLE, HELM_REPO_NAME_TEST,
11+
OCI_INDEX_PAGE_SIZE,
12+
},
1013
utils::chartsource::{ChartSourceEntry, ChartSourceMetadata},
1114
};
1215

@@ -28,16 +31,39 @@ pub enum Error {
2831
UnexpectedOciRepositoryName,
2932
}
3033

34+
/// Identifies an operator-specific root folder in the repository e.g.
35+
/// ```
36+
/// {
37+
/// name: "sdp-charts/airflow-operator"
38+
/// }
39+
/// ```
3140
#[derive(Deserialize, Debug)]
32-
pub struct OciRepository {
41+
struct OciRepository {
3342
pub name: String,
3443
}
3544

45+
/// Identifies an image tag e.g.
46+
/// ```
47+
/// {
48+
/// name: "24.11.1-rc1"
49+
/// }
50+
/// ```
3651
#[derive(Deserialize, Debug)]
3752
pub struct Tag {
3853
pub name: String,
3954
}
4055

56+
/// Identifies an image artifact with its digest and tags e.g.
57+
/// ```
58+
/// {
59+
/// digest: "sha256:e80a4b1e004f90dee0321f817871c4a225369b89efdc17c319595263139364b5",
60+
/// tags: [
61+
/// {
62+
/// name: "0.0.0-pr569"
63+
/// }
64+
/// ])
65+
/// }
66+
/// ```
4167
#[derive(Deserialize, Debug)]
4268
pub struct Artifact {
4369
pub digest: String,
@@ -93,30 +119,29 @@ pub async fn get_oci_index<'a>() -> Result<HashMap<&'a str, ChartSourceMetadata>
93119

94120
let mut artifacts = Vec::new();
95121
let mut page = 1;
96-
let page_size = 20;
97122

98123
loop {
99124
let url = format!(
100125
"{}/projects/{}/repositories/{}/artifacts?page_size={}&page={}",
101126
base_url,
102127
encode(project_name),
103128
encode(repository_name),
104-
page_size,
129+
OCI_INDEX_PAGE_SIZE,
105130
page
106131
);
107132

108-
let artifact_page = client
133+
let artifacts_page = client
109134
.get(url)
110135
.send()
111136
.await
112137
.context(GetArtifactsSnafu)?
113138
.json::<Vec<Artifact>>()
114139
.await
115140
.context(ParseArtifactsSnafu)?;
116-
141+
117142
let count = artifacts_page.len();
118143
artifacts.extend(artifacts_page);
119-
if count < page_size {
144+
if count < OCI_INDEX_PAGE_SIZE {
120145
break;
121146
}
122147
page += 1;
@@ -138,6 +163,11 @@ pub async fn get_oci_index<'a>() -> Result<HashMap<&'a str, ChartSourceMetadata>
138163
release_artifact.name.to_string()
139164
);
140165

166+
debug!(
167+
"Repo/Artifact/Tag: {:?} / {:?} / {:?}",
168+
repository, artifact, release_artifact
169+
);
170+
141171
let entry = ChartSourceEntry {
142172
name: repository_name.to_string(),
143173
version: release_version.to_string(),

0 commit comments

Comments
 (0)