Skip to content

Commit

Permalink
chore: Change name used on QuayIO environment variable and for `clien…
Browse files Browse the repository at this point in the history
…t` in test and examples (#2)
  • Loading branch information
bryantbiggs authored Aug 23, 2024
1 parent e8bbff9 commit 08693eb
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 167 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ jobs:
# - name: Run cargo test (test-net-private)
# run: cargo test --features test-net,test-net-private
# env:
# DKREG_QUAY_USER: ${{ secrets.DKREG_QUAY_USER }}
# DKREG_QUAY_PASSWD: ${{ secrets.DKREG_QUAY_PASSWD }}
# DOCKER_REGISTRY_QUAY_USER: ${{ secrets.DOCKER_REGISTRY_QUAY_USER }}
# DOCKER_REGISTRY_QUAY_PASSWD: ${{ secrets.DOCKER_REGISTRY_QUAY_PASSWD }}

lints:
name: Lints
Expand All @@ -93,6 +93,8 @@ jobs:

- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy

- name: Run cargo fmt
run: cargo fmt --all -- --check
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ url = "2.5"

[dev-dependencies]
dirs = "5.0"
env_logger = "0.11"
hyper = "1.4"
mockito = "1.5"
native-tls = "0.2"
test-case = "3.3"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
tracing = "0.1"
tracing-subscriber = "0.3"

[features]
default = ["reqwest-default-tls"]
Expand Down
9 changes: 7 additions & 2 deletions examples/checkregistry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ use tracing::{error, info};

#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.pretty()
.with_max_level(tracing::Level::INFO)
.init();

let registry = match std::env::args().nth(1) {
Some(x) => x,
None => "registry-1.docker.io".into(),
Expand All @@ -18,12 +23,12 @@ async fn main() {
}

async fn run(host: &str) -> Result<bool, boxed::Box<dyn error::Error>> {
let dclient = docker_registry::v2::Client::configure()
let client = docker_registry::v2::Client::configure()
.registry(host)
.insecure_registry(false)
.build()?;

let supported = dclient.is_v2_supported().await?;
let supported = client.is_v2_supported().await?;
if supported {
info!("{host} supports v2");
} else {
Expand Down
17 changes: 11 additions & 6 deletions examples/image-labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use tracing::{error, info, warn};

#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.pretty()
.with_max_level(tracing::Level::INFO)
.init();

let dkr_ref = match std::env::args().nth(1) {
Some(ref x) => reference::Reference::from_str(x),
None => reference::Reference::from_str("quay.io/steveej/cincinnati-test-labels:0.0.0"),
Expand All @@ -27,13 +32,13 @@ async fn main() {
warn!("[{registry}] no credentials found in config.json");
}
} else {
user = env::var("DKREG_USER").ok();
user = env::var("DOCKER_REGISTRY_USER").ok();
if user.is_none() {
warn!("[{registry}] no $DKREG_USER for login user");
warn!("[{registry}] no $DOCKER_REGISTRY_USER for login user");
}
password = env::var("DKREG_PASSWD").ok();
password = env::var("DOCKER_REGISTRY_PASSWD").ok();
if password.is_none() {
warn!("[{registry}] no $DKREG_PASSWD for login password");
warn!("[{registry}] no $DOCKER_REGISTRY_PASSWD for login password");
}
};

Expand Down Expand Up @@ -61,8 +66,8 @@ async fn run(
let login_scope = format!("repository:{image}:pull");
let version = dkr_ref.version();

let dclient = client.authenticate(&[&login_scope]).await?;
let manifest = dclient.get_manifest(&image, &version).await?;
let client = client.authenticate(&[&login_scope]).await?;
let manifest = client.get_manifest(&image, &version).await?;

if let Manifest::S1Signed(s1s) = manifest {
let labels = s1s.get_labels(0);
Expand Down
22 changes: 11 additions & 11 deletions examples/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ async fn main() -> Result<(), boxed::Box<dyn error::Error>> {
warn!("[{registry}] no credentials found in config.json");
}
} else {
user = env::var("DKREG_USER").ok();
user = env::var("DOCKER_REGISTRY_USER").ok();
if user.is_none() {
warn!("[{registry}] no $DKREG_USER for login user");
warn!("[{registry}] no $DOCKER_REGISTRY_USER for login user");
}
password = env::var("DKREG_PASSWD").ok();
password = env::var("DOCKER_REGISTRY_PASSWD").ok();
if password.is_none() {
warn!("[{registry}] no $DKREG_PASSWD for login password");
warn!("[{registry}] no $DOCKER_REGISTRY_PASSWD for login password");
}
};

Expand All @@ -77,10 +77,10 @@ async fn run(
passwd: Option<String>,
path: &Path,
) -> Result<(), boxed::Box<dyn error::Error>> {
env_logger::Builder::new()
.filter(Some("docker_registry"), log::LevelFilter::Trace)
.filter(Some("trace"), log::LevelFilter::Trace)
.try_init()?;
tracing_subscriber::fmt()
.pretty()
.with_max_level(tracing::Level::INFO)
.init();

let client = docker_registry::v2::Client::configure()
.registry(registry)
Expand All @@ -91,15 +91,15 @@ async fn run(

let login_scope = format!("repository:{image}:pull");

let dclient = client.authenticate(&[&login_scope]).await?;
let manifest = dclient.get_manifest(image, version).await?;
let client = client.authenticate(&[&login_scope]).await?;
let manifest = client.get_manifest(image, version).await?;
let layers_digests = manifest.layers_digests(None)?;

info!("{} -> got {} layer(s)", &image, layers_digests.len(),);

let blob_futures = layers_digests
.iter()
.map(|layer_digest| dclient.get_blob(image, layer_digest))
.map(|layer_digest| client.get_blob(image, layer_digest))
.collect::<Vec<_>>();

let blobs = try_join_all(blob_futures).await?;
Expand Down
22 changes: 11 additions & 11 deletions examples/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ use tracing::{error, warn};

#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.pretty()
.with_max_level(tracing::Level::INFO)
.init();

let registry = match std::env::args().nth(1) {
Some(x) => x,
None => "registry-1.docker.io".into(),
Expand All @@ -14,13 +19,13 @@ async fn main() {
None => "".into(),
};

let user = std::env::var("DKREG_USER").ok();
let user = std::env::var("DOCKER_REGISTRY_USER").ok();
if user.is_none() {
warn!("[{registry}] no $DKREG_USER for login user");
warn!("[{registry}] no $DOCKER_REGISTRY_USER for login user");
}
let password = std::env::var("DKREG_PASSWD").ok();
let password = std::env::var("DOCKER_REGISTRY_PASSWD").ok();
if password.is_none() {
warn!("[{registry}] no $DKREG_PASSWD for login password");
warn!("[{registry}] no $DOCKER_REGISTRY_PASSWD for login password");
}

let res = run(&registry, user, password, login_scope).await;
Expand All @@ -37,19 +42,14 @@ async fn run(
passwd: Option<String>,
login_scope: String,
) -> Result<(), boxed::Box<dyn error::Error>> {
env_logger::Builder::new()
.filter(Some("docker_registry"), log::LevelFilter::Trace)
.filter(Some("trace"), log::LevelFilter::Trace)
.try_init()?;

let client = docker_registry::v2::Client::configure()
.registry(host)
.insecure_registry(false)
.username(user)
.password(passwd)
.build()?;

let dclient = client.authenticate(&[&login_scope]).await?;
dclient.is_auth().await?;
let client = client.authenticate(&[&login_scope]).await?;
client.is_auth().await?;
Ok(())
}
22 changes: 11 additions & 11 deletions examples/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use tracing::{error, info, warn};

#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.pretty()
.with_max_level(tracing::Level::INFO)
.init();

let registry = match std::env::args().nth(1) {
Some(x) => x,
None => "registry-1.docker.io".into(),
Expand All @@ -16,13 +21,13 @@ async fn main() {
};
info!("[{registry}] requesting tags for image {image}");

let user = std::env::var("DKREG_USER").ok();
let user = std::env::var("DOCKER_REGISTRY_USER").ok();
if user.is_none() {
warn!("[{registry}] no $DKREG_USER for login user");
warn!("[{registry}] no $DOCKER_REGISTRY_USER for login user");
}
let password = std::env::var("DKREG_PASSWD").ok();
let password = std::env::var("DOCKER_REGISTRY_PASSWD").ok();
if password.is_none() {
warn!("[{registry}] no $DKREG_PASSWD for login password");
warn!("[{registry}] no $DOCKER_REGISTRY_PASSWD for login password");
}

let res = run(&registry, user, password, &image).await;
Expand All @@ -39,11 +44,6 @@ async fn run(
passwd: Option<String>,
image: &str,
) -> Result<(), boxed::Box<dyn error::Error>> {
env_logger::Builder::new()
.filter(Some("docker_registry"), log::LevelFilter::Trace)
.filter(Some("trace"), log::LevelFilter::Trace)
.try_init()?;

let client = docker_registry::v2::Client::configure()
.registry(host)
.insecure_registry(false)
Expand All @@ -53,9 +53,9 @@ async fn run(

let login_scope = format!("repository:{image}:pull");

let dclient = client.authenticate(&[&login_scope]).await?;
let client = client.authenticate(&[&login_scope]).await?;

dclient
client
.get_tags(image, Some(7))
.collect::<Vec<_>>()
.await
Expand Down
24 changes: 12 additions & 12 deletions examples/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use tracing::{error, info, warn};

#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.pretty()
.with_max_level(tracing::Level::INFO)
.init();

let dkr_ref = match std::env::args().nth(1) {
Some(ref x) => reference::Reference::from_str(x),
None => reference::Reference::from_str("quay.io/coreos/etcd"),
Expand All @@ -27,13 +32,13 @@ async fn main() {
warn!("[{registry}] no credentials found in config.json");
}
} else {
user = env::var("DKREG_USER").ok();
user = env::var("DOCKER_REGISTRY_USER").ok();
if user.is_none() {
warn!("[{registry}] no $DKREG_USER for login user");
warn!("[{registry}] no $DOCKER_REGISTRY_USER for login user");
}
password = env::var("DKREG_PASSWD").ok();
password = env::var("DOCKER_REGISTRY_PASSWD").ok();
if password.is_none() {
warn!("[{registry}] no $DKREG_PASSWD for login password");
warn!("[{registry}] no $DOCKER_REGISTRY_PASSWD for login password");
}
};

Expand All @@ -50,11 +55,6 @@ async fn run(
user: Option<String>,
passwd: Option<String>,
) -> Result<(), boxed::Box<dyn error::Error>> {
env_logger::Builder::new()
.filter(Some("docker_registry"), log::LevelFilter::Trace)
.filter(Some("trace"), log::LevelFilter::Trace)
.try_init()?;

let image = dkr_ref.repository();
let version = dkr_ref.version();

Expand All @@ -67,14 +67,14 @@ async fn run(

let login_scope = "";

let dclient = client.authenticate(&[login_scope]).await?;
let manifest = dclient.get_manifest(&image, &version).await?;
let client = client.authenticate(&[login_scope]).await?;
let manifest = client.get_manifest(&image, &version).await?;

let layers_digests = manifest.layers_digests(None)?;
info!("{} -> got {} layer(s)", &image, layers_digests.len(),);

for layer_digest in &layers_digests {
let blob = dclient.get_blob(&image, layer_digest).await?;
let blob = client.get_blob(&image, layer_digest).await?;
info!("Layer {layer_digest}, got {} bytes.", blob.len());
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
//!
//! // Check whether a registry supports API v2.
//! let host = "quay.io";
//! let dclient = Client::configure()
//! let client = Client::configure()
//! .insecure_registry(false)
//! .registry(host)
//! .build()?;
//! match dclient.is_v2_supported().await? {
//! match client.is_v2_supported().await? {
//! false => println!("{} does NOT support v2", host),
//! true => println!("{} supports v2", host),
//! };
Expand Down
4 changes: 2 additions & 2 deletions src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
//! use docker_registry::v2::Client;
//!
//! // Retrieve an image manifest.
//! let dclient = Client::configure().registry("quay.io").build()?;
//! let manifest = dclient.get_manifest("coreos/etcd", "v3.1.0").await?;
//! let client = Client::configure().registry("quay.io").build()?;
//! let manifest = client.get_manifest("coreos/etcd", "v3.1.0").await?;
//! #
//! # Ok(())
//! # };
Expand Down
Loading

0 comments on commit 08693eb

Please sign in to comment.