Skip to content

Commit

Permalink
Merge pull request #1600 from radu-matei/fix/pub-oci-client
Browse files Browse the repository at this point in the history
(fix/oci-client): allow adding a token for OCI client
  • Loading branch information
vdice authored Sep 11, 2023
2 parents 2e3b39e + 93df4ef commit f554a45
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions crates/oci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dkregistry = { git = "https://github.com/camallo/dkregistry-rs", rev = "37acecb4
docker_credential = "1.0"
dirs = "4.0"
futures-util = "0.3"
oci-distribution = { git = "https://github.com/krustlet/oci-distribution", rev = "64986855ef0d692df3b270d23c4bee8c41d97c27" }
oci-distribution = { git = "https://github.com/fermyon/oci-distribution", rev = "05022618d78feef9b99f20b5da8fd6def6bb80d2" }
reqwest = "0.11"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -22,4 +22,5 @@ spin-trigger = { path = "../trigger" }
tempfile = "3.3"
tokio = { version = "1", features = ["fs"] }
tracing = { workspace = true }
walkdir = "2.3"
walkdir = "2.3"

13 changes: 13 additions & 0 deletions crates/oci/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use anyhow::{bail, Context, Result};
use docker_credential::DockerCredential;
use futures_util::future;
use futures_util::stream::{self, StreamExt, TryStreamExt};
use oci_distribution::token_cache::RegistryTokenType;
use oci_distribution::RegistryOperation;
use oci_distribution::{
client::{Config, ImageLayer},
manifest::OciImageManifest,
Expand Down Expand Up @@ -37,6 +39,7 @@ const CONTENT_REF_INLINE_MAX_SIZE: usize = 128;
pub struct Client {
/// Global cache for the metadata, Wasm modules, and static assets pulled from OCI registries.
pub cache: Cache,
/// Underlying OCI client.
oci: oci_distribution::Client,
}

Expand Down Expand Up @@ -326,6 +329,16 @@ impl Client {
auth.save_default().await
}

/// Insert a token in the OCI client token cache.
pub fn insert_token(
&mut self,
reference: &Reference,
op: RegistryOperation,
token: RegistryTokenType,
) {
self.oci.tokens.insert(reference, op, token);
}

/// Validate the credentials by attempting to send an authenticated request to the registry.
async fn validate_credentials(
server: impl AsRef<str>,
Expand Down

0 comments on commit f554a45

Please sign in to comment.