mirror of
https://github.com/getnora-io/nora.git
synced 2026-04-12 12:40:31 +00:00
v0.2.29: upstream auth, remove dead code, version bump
- Remove unused DockerAuth::fetch_with_auth() method - Fix basic_auth_header docstring - Bump to v0.2.29
This commit is contained in:
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -1247,7 +1247,7 @@ checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nora-cli"
|
name = "nora-cli"
|
||||||
version = "0.2.28"
|
version = "0.2.29"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"flate2",
|
"flate2",
|
||||||
@@ -1261,7 +1261,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nora-registry"
|
name = "nora-registry"
|
||||||
version = "0.2.28"
|
version = "0.2.29"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"axum",
|
"axum",
|
||||||
@@ -1299,7 +1299,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nora-storage"
|
name = "nora-storage"
|
||||||
version = "0.2.28"
|
version = "0.2.29"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"base64",
|
"base64",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.2.28"
|
version = "0.2.29"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["DevITWay <devitway@gmail.com>"]
|
authors = ["DevITWay <devitway@gmail.com>"]
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use std::fs;
|
|||||||
pub use crate::secrets::SecretsConfig;
|
pub use crate::secrets::SecretsConfig;
|
||||||
|
|
||||||
/// Encode "user:pass" into a Basic Auth header value, e.g. "Basic dXNlcjpwYXNz".
|
/// Encode "user:pass" into a Basic Auth header value, e.g. "Basic dXNlcjpwYXNz".
|
||||||
/// Returns None if input is None.
|
|
||||||
pub fn basic_auth_header(credentials: &str) -> String {
|
pub fn basic_auth_header(credentials: &str) -> String {
|
||||||
format!("Basic {}", STANDARD.encode(credentials))
|
format!("Basic {}", STANDARD.encode(credentials))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,49 +110,6 @@ impl DockerAuth {
|
|||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make an authenticated request to an upstream registry
|
|
||||||
pub async fn fetch_with_auth(
|
|
||||||
&self,
|
|
||||||
url: &str,
|
|
||||||
registry_url: &str,
|
|
||||||
name: &str,
|
|
||||||
basic_auth: Option<&str>,
|
|
||||||
) -> Result<reqwest::Response, ()> {
|
|
||||||
// First try — with basic auth if configured, otherwise anonymous
|
|
||||||
let mut request = self.client.get(url);
|
|
||||||
if let Some(credentials) = basic_auth {
|
|
||||||
request = request.header("Authorization", basic_auth_header(credentials));
|
|
||||||
}
|
|
||||||
let response = request.send().await.map_err(|_| ())?;
|
|
||||||
|
|
||||||
if response.status() == reqwest::StatusCode::UNAUTHORIZED {
|
|
||||||
// Extract Www-Authenticate header
|
|
||||||
let www_auth = response
|
|
||||||
.headers()
|
|
||||||
.get("www-authenticate")
|
|
||||||
.and_then(|v| v.to_str().ok())
|
|
||||||
.map(String::from);
|
|
||||||
|
|
||||||
// Get token and retry
|
|
||||||
if let Some(token) = self
|
|
||||||
.get_token(registry_url, name, www_auth.as_deref(), basic_auth)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
return self
|
|
||||||
.client
|
|
||||||
.get(url)
|
|
||||||
.header("Authorization", format!("Bearer {}", token))
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.map_err(|_| ());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(response)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DockerAuth {
|
impl Default for DockerAuth {
|
||||||
|
|||||||
Reference in New Issue
Block a user