5 个版本
0.2.1 | 2023 年 6 月 27 日 |
---|---|
0.1.3 | 2020 年 4 月 11 日 |
0.1.2 | 2020 年 4 月 1 日 |
0.1.1 | 2020 年 4 月 1 日 |
0.1.0 | 2020 年 3 月 30 日 |
#1410 in 网络编程
25KB
488 行
OCI 注册表客户端
适用于符合 OCI 标准的镜像注册表 和 Docker 注册表 HTTP V2 协议 的异步客户端。
用法
DockerRegistryClientV2
提供了查询注册表 API 和下载 blob 的功能。
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(())
}
许可证
本项目采用 MIT 许可证。
贡献
除非您明确说明,否则您提交给 oci-registry-client 的任何贡献,都应按照 MIT 许可证授权,不附加任何额外条款或条件。
依赖项
~5–21MB
~277K SLoC