Skip to content

Commit

Permalink
Merge pull request #93 from rbbl-dev/feature/pushable_manifests
Browse files Browse the repository at this point in the history
Improved Push Logic
  • Loading branch information
flavio authored Sep 26, 2023
2 parents 50f3a81 + 814a9e7 commit fd7922e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
12 changes: 3 additions & 9 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ impl Client {
/// Pushes the manifest for a specified image
///
/// Returns pullable manifest URL
async fn push_manifest(&self, image: &Reference, manifest: &OciManifest) -> Result<String> {
pub async fn push_manifest(&self, image: &Reference, manifest: &OciManifest) -> Result<String> {
let url = self.to_v2_manifest_url(image);

let mut headers = HeaderMap::new();
Expand Down Expand Up @@ -1412,22 +1412,17 @@ pub fn current_platform_resolver(manifests: &[ImageIndexEntry]) -> Option<String
}

/// The protocol that the client should use to connect
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum ClientProtocol {
#[allow(missing_docs)]
Http,
#[allow(missing_docs)]
#[default]
Https,
#[allow(missing_docs)]
HttpsExcept(Vec<String>),
}

impl Default for ClientProtocol {
fn default() -> Self {
ClientProtocol::Https
}
}

impl ClientProtocol {
fn scheme_for(&self, registry: &str) -> &str {
match self {
Expand Down Expand Up @@ -1468,7 +1463,6 @@ impl TryFrom<&HeaderValue> for BearerChallenge {
None
}
})
.into_iter()
.next()
.ok_or_else(|| "Cannot find Bearer challenge".to_string())
}
Expand Down
3 changes: 1 addition & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ struct Empty {}
/// Helper to deserialize a `map[string]struct{}` of golang
fn hashset_from_str<'de, D: Deserializer<'de>>(d: D) -> Result<HashSet<String>, D::Error> {
let res = <HashMap<String, Empty>>::deserialize(d)?
.into_iter()
.map(|(k, _)| k)
.into_keys()
.collect();
Ok(res)
}
Expand Down
10 changes: 8 additions & 2 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ impl OciManifest {
/// Returns the appropriate content-type for each variant.
pub fn content_type(&self) -> &str {
match self {
OciManifest::Image(_) => OCI_IMAGE_MEDIA_TYPE,
OciManifest::ImageIndex(_) => IMAGE_MANIFEST_LIST_MEDIA_TYPE,
OciManifest::Image(image) => {
image.media_type.as_deref().unwrap_or(OCI_IMAGE_MEDIA_TYPE)
}
OciManifest::ImageIndex(image) => image
.media_type
.as_deref()
.unwrap_or(IMAGE_MANIFEST_LIST_MEDIA_TYPE),
}
}
}
Expand Down Expand Up @@ -452,6 +457,7 @@ impl std::fmt::Display for Platform {
#[cfg(test)]
mod test {
use super::*;

const TEST_MANIFEST: &str = r#"{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
Expand Down

0 comments on commit fd7922e

Please sign in to comment.