#async-client #registry #docker #http-client #api-client #oci #blobs

bin+lib oci-registry-client

A async client for Docker Registry HTTP V2 protocol

5 releases

0.2.1 Jun 27, 2023
0.1.3 Apr 11, 2020
0.1.2 Apr 1, 2020
0.1.1 Apr 1, 2020
0.1.0 Mar 30, 2020

#1097 in Network programming

Download history 119/week @ 2023-12-11 99/week @ 2023-12-18 35/week @ 2023-12-25 51/week @ 2024-01-01 118/week @ 2024-01-08 69/week @ 2024-01-15 88/week @ 2024-01-22 197/week @ 2024-01-29 174/week @ 2024-02-05 59/week @ 2024-02-12 118/week @ 2024-02-19 67/week @ 2024-02-26 135/week @ 2024-03-04 62/week @ 2024-03-11 135/week @ 2024-03-18 17/week @ 2024-03-25

350 downloads per month

MIT license

25KB
488 lines

OCI Registry Client

crates.io Documentation MIT

A async client for OCI compliant image registries and Docker Registry HTTP V2 protocol.

Usage

The DockerRegistryClientV2 provides functions to query Registry API and download blobs.

use std::{path::Path, fs::File, io::Write};
use oci_registry_client::DockerRegistryClientV2;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = DockerRegistryClientV2::new(
        "registry.docker.io",
        "https://registry-1.docker.io",
        "https://auth.docker.io/token"
    );
    let token = client.auth("repository", "library/ubuntu", "latest").await?;
    client.set_auth_token(Some(token));

    let manifest = client.manifest("library/ubuntu", "latest").await?;
    println!("{:?}", manifest);

    for layer in &manifest.layers {
       let mut out_file = File::create(Path::new("/tmp/").join(&layer.digest))?;
       let mut blob = client.blob("library/ubuntu", &layer.digest).await?;

       while let Some(chunk) = blob.chunk().await? {
           out_file.write_all(&chunk)?;
       }
    }

    Ok(())
}

License

This project is licensed under the MIT License.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in oci-registry-client by you, shall be licensed as MIT, without any additional terms or conditions.

Dependencies

~6–20MB
~288K SLoC