52 lines
1.1 KiB
Rust
52 lines
1.1 KiB
Rust
use reqwest;
|
|
use serde::Deserialize;
|
|
use url::Url;
|
|
|
|
pub struct Registry<'a> {
|
|
pub url: &'a str,
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct RepositoryList {
|
|
pub repositories: Vec<String>,
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct RepositoryTags {
|
|
name: String,
|
|
tags: Option<Vec<String>>,
|
|
}
|
|
|
|
impl<'a> Registry<'a> {
|
|
pub async fn get_repositories(&self) -> Result<RepositoryList, Box<dyn std::error::Error>> {
|
|
let registry_url = Url::parse(self.url).unwrap();
|
|
let api_url = registry_url.join("/v2/_catalog").unwrap();
|
|
|
|
let resp = reqwest::get(api_url)
|
|
.await?
|
|
.json::<RepositoryList>()
|
|
.await?;
|
|
|
|
Ok(resp)
|
|
}
|
|
|
|
pub async fn get_repository_tags(
|
|
&self,
|
|
repo: &str,
|
|
) -> Result<RepositoryTags, Box<dyn std::error::Error>> {
|
|
let registry_url = Url::parse(self.url).unwrap();
|
|
let api_url = registry_url
|
|
.join(format!("/v2/{}/tags/list", repo).as_str())
|
|
.unwrap();
|
|
|
|
let resp = reqwest::get(api_url).await?;
|
|
|
|
println!("{:?}", resp.headers());
|
|
|
|
let data = resp.json::<RepositoryTags>().await?;
|
|
Ok(data)
|
|
}
|
|
}
|