mirror of
https://github.com/anthonyoteri/dredge.git
synced 2026-06-05 15:26:53 -04:00
Fix clippy security errors
This commit is contained in:
@@ -41,7 +41,6 @@ jobs:
|
|||||||
--all-features
|
--all-features
|
||||||
--tests
|
--tests
|
||||||
--message-format=json
|
--message-format=json
|
||||||
-- -D warnings
|
|
||||||
| clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
|
| clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
|
|||||||
+15
-15
@@ -24,7 +24,7 @@ use crate::error::ApiError;
|
|||||||
///
|
///
|
||||||
/// The Docker Registry API specifies that when making a GET request, the
|
/// The Docker Registry API specifies that when making a GET request, the
|
||||||
/// response will be paginated using a Link response header for the Next URI.
|
/// response will be paginated using a Link response header for the Next URI.
|
||||||
/// The URL will be encoded using RFC5988. [https://tools.ietf.org/html/rfc5988]
|
/// The URL will be encoded using [RFC5988](https://tools.ietf.org/html/rfc5988)
|
||||||
///
|
///
|
||||||
/// This function will continuously request the "Next" link as long as it is
|
/// This function will continuously request the "Next" link as long as it is
|
||||||
/// returned, collecting and returning the deserialized response bodies as a
|
/// returned, collecting and returning the deserialized response bodies as a
|
||||||
@@ -43,17 +43,17 @@ pub async fn fetch_all<T: for<'de> Deserialize<'de>>(
|
|||||||
log::trace!("fetch_all({path:?})");
|
log::trace!("fetch_all({path:?})");
|
||||||
|
|
||||||
let mut responses: Vec<T> = Vec::default();
|
let mut responses: Vec<T> = Vec::default();
|
||||||
let mut uri = String::from(path);
|
let mut path = String::from(path);
|
||||||
loop {
|
loop {
|
||||||
log::debug!("GET {uri:?}");
|
log::debug!("GET {path:?}");
|
||||||
let url = config.registry_url.join(&uri)?;
|
let url = config.registry_url.join(&path)?;
|
||||||
|
|
||||||
let resp = reqwest::get(url).await?;
|
let resp = reqwest::get(url).await?;
|
||||||
let headers = resp.headers().to_owned();
|
let headers = resp.headers().clone();
|
||||||
responses.push(resp.json().await?);
|
responses.push(resp.json().await?);
|
||||||
|
|
||||||
if let Some(path) = parse_rfc5988(headers.get(http::header::LINK))? {
|
if let Some(p) = parse_rfc5988(headers.get(http::header::LINK))? {
|
||||||
uri = path;
|
path = p;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -64,8 +64,8 @@ pub async fn fetch_all<T: for<'de> Deserialize<'de>>(
|
|||||||
/// Given an optional header value possibly containing an RFC5988 formatted
|
/// Given an optional header value possibly containing an RFC5988 formatted
|
||||||
/// URL, parse said URL into a `String`.
|
/// URL, parse said URL into a `String`.
|
||||||
///
|
///
|
||||||
/// If the header_value does not contain a correctly formatted RFC5988 URL,
|
/// If the `header_value` does not contain a correctly formatted RFC5988 URL,
|
||||||
/// or if the header_value is not properly formatted containing a URL
|
/// or if the `header_value` is not properly formatted containing a URL
|
||||||
/// surrounded by angle brackets, separated from the link relation by a ';'
|
/// surrounded by angle brackets, separated from the link relation by a ';'
|
||||||
/// character, the `None` variant will be returned.
|
/// character, the `None` variant will be returned.
|
||||||
///
|
///
|
||||||
@@ -128,10 +128,10 @@ pub fn parse_response_status(response: &reqwest::Response) -> Result<(), ApiErro
|
|||||||
http::StatusCode::OK => {
|
http::StatusCode::OK => {
|
||||||
let headers = response.headers();
|
let headers = response.headers();
|
||||||
if let Some(header_value) = headers.get("Docker-Distribution-API-Version") {
|
if let Some(header_value) = headers.get("Docker-Distribution-API-Version") {
|
||||||
if header_value.to_str()? != "registry/2.0" {
|
if header_value.to_str()? == "registry/2.0" {
|
||||||
Err(ApiError::UnsupportedVersion(header_value.to_str()?.into()))
|
|
||||||
} else {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(ApiError::UnsupportedVersion(header_value.to_str()?.into()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(ApiError::UnexpectedResponse(
|
Err(ApiError::UnexpectedResponse(
|
||||||
@@ -142,10 +142,10 @@ pub fn parse_response_status(response: &reqwest::Response) -> Result<(), ApiErro
|
|||||||
http::StatusCode::UNAUTHORIZED => {
|
http::StatusCode::UNAUTHORIZED => {
|
||||||
let headers = response.headers();
|
let headers = response.headers();
|
||||||
if let Some(header_value) = headers.get("Docker-Distribution-API-Version") {
|
if let Some(header_value) = headers.get("Docker-Distribution-API-Version") {
|
||||||
if header_value.to_str()? != "registry/2.0" {
|
if header_value.to_str()? == "registry/2.0" {
|
||||||
Err(ApiError::UnsupportedVersion(header_value.to_str()?.into()))
|
|
||||||
} else {
|
|
||||||
Err(ApiError::AuthorizationFailed)
|
Err(ApiError::AuthorizationFailed)
|
||||||
|
} else {
|
||||||
|
Err(ApiError::UnsupportedVersion(header_value.to_str()?.into()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(ApiError::UnexpectedResponse(
|
Err(ApiError::UnexpectedResponse(
|
||||||
|
|||||||
+4
-2
@@ -88,9 +88,10 @@ pub async fn tags_handler(config: &Config, name: &str) -> Result<(), ApiError> {
|
|||||||
///
|
///
|
||||||
/// Returns an `ApiError` if there is a problem fetching the manifest or if there
|
/// Returns an `ApiError` if there is a problem fetching the manifest or if there
|
||||||
/// is a problem parsing the response from the Docker Registry API.
|
/// is a problem parsing the response from the Docker Registry API.
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
pub async fn show_handler(config: &Config, image: &str, tag: &str) -> Result<(), ApiError> {
|
pub async fn show_handler(config: &Config, image: &str, tag: &str) -> Result<(), ApiError> {
|
||||||
log::trace!("show_handler(image: {image}, tag: {tag})");
|
log::trace!("show_handler(image: {image}, tag: {tag})");
|
||||||
let base = config.registry_url.to_owned();
|
let base = config.registry_url.clone();
|
||||||
let path = format!("/v2/{image}/manifests/{tag}");
|
let path = format!("/v2/{image}/manifests/{tag}");
|
||||||
let _url = base.join(&path)?;
|
let _url = base.join(&path)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -103,6 +104,7 @@ pub async fn show_handler(config: &Config, image: &str, tag: &str) -> Result<(),
|
|||||||
/// Returns and `ApiError` if there is a problem converting the given tag to a
|
/// Returns and `ApiError` if there is a problem converting the given tag to a
|
||||||
/// manifest digest, or if there is a problem deleting the manifest from the
|
/// manifest digest, or if there is a problem deleting the manifest from the
|
||||||
/// Docker Registry API.
|
/// Docker Registry API.
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
pub async fn delete_handler(_config: &Config, image: &str, tag: &str) -> Result<(), ApiError> {
|
pub async fn delete_handler(_config: &Config, image: &str, tag: &str) -> Result<(), ApiError> {
|
||||||
log::trace!("delete_handler(image: {image}, tag: {tag})");
|
log::trace!("delete_handler(image: {image}, tag: {tag})");
|
||||||
todo!()
|
todo!()
|
||||||
@@ -119,7 +121,7 @@ pub async fn delete_handler(_config: &Config, image: &str, tag: &str) -> Result<
|
|||||||
pub async fn check_handler(config: &Config) -> Result<(), ApiError> {
|
pub async fn check_handler(config: &Config) -> Result<(), ApiError> {
|
||||||
log::trace!("check_handler()");
|
log::trace!("check_handler()");
|
||||||
|
|
||||||
let base = config.registry_url.to_owned();
|
let base = config.registry_url.clone();
|
||||||
let path = "/v2";
|
let path = "/v2";
|
||||||
let url = base.join(path)?;
|
let url = base.join(path)?;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#![allow(clippy::enum_variant_names)]
|
#![allow(clippy::enum_variant_names)]
|
||||||
|
#![allow(clippy::module_name_repetitions)]
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
/// The common error type for this Application.
|
/// The common error type for this Application.
|
||||||
|
|||||||
+13
-19
@@ -50,24 +50,18 @@ const CONFIG_PREFIX: &str = "dredge";
|
|||||||
fn locate_config_file(path: Option<OsString>) -> Option<PathBuf> {
|
fn locate_config_file(path: Option<OsString>) -> Option<PathBuf> {
|
||||||
log::trace!("locate_config_file({path:?})");
|
log::trace!("locate_config_file({path:?})");
|
||||||
|
|
||||||
match path {
|
if let Some(path) = path {
|
||||||
Some(path) => {
|
let p = PathBuf::from(path);
|
||||||
let p = PathBuf::from(path);
|
log::debug!("Checking if path {p:?} exists");
|
||||||
log::debug!("Checking if path {p:?} exists");
|
p.try_exists().map(|_| Some(p)).unwrap_or(None)
|
||||||
p.try_exists().map(|_| Some(p)).unwrap_or(None)
|
} else {
|
||||||
}
|
let xdg_dirs = xdg::BaseDirectories::with_prefix(CONFIG_PREFIX).ok()?;
|
||||||
None => {
|
let search_paths: Vec<PathBuf> = vec![xdg_dirs.get_config_home()]
|
||||||
let xdg_dirs = xdg::BaseDirectories::with_prefix(CONFIG_PREFIX).ok()?;
|
.into_iter()
|
||||||
let search_paths: Vec<PathBuf> = vec![xdg_dirs.get_config_home()]
|
.chain(xdg_dirs.get_config_dirs())
|
||||||
.into_iter()
|
.collect();
|
||||||
.chain(xdg_dirs.get_config_dirs())
|
log::debug!("Searching configuration directories for {CONFIG_FILE_NAME} {search_paths:?}");
|
||||||
.collect();
|
xdg_dirs.find_config_file(CONFIG_FILE_NAME)
|
||||||
|
|
||||||
log::debug!(
|
|
||||||
"Searching configuration directories for {CONFIG_FILE_NAME} {search_paths:?}"
|
|
||||||
);
|
|
||||||
xdg_dirs.find_config_file(CONFIG_FILE_NAME)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +102,7 @@ async fn main() -> Result<(), DredgeError> {
|
|||||||
Commands::Catalog => commands::catalog_handler(&config).await?,
|
Commands::Catalog => commands::catalog_handler(&config).await?,
|
||||||
Commands::Tags { name } => commands::tags_handler(&config, &name).await?,
|
Commands::Tags { name } => commands::tags_handler(&config, &name).await?,
|
||||||
Commands::Show { image, tag } => {
|
Commands::Show { image, tag } => {
|
||||||
commands::show_handler(&config, &image, &tag.unwrap_or("latest".to_string())).await?
|
commands::show_handler(&config, &image, &tag.unwrap_or("latest".to_string())).await?;
|
||||||
}
|
}
|
||||||
Commands::Delete { image, tag } => commands::delete_handler(&config, &image, &tag).await?,
|
Commands::Delete { image, tag } => commands::delete_handler(&config, &image, &tag).await?,
|
||||||
Commands::Check => commands::check_handler(&config).await?,
|
Commands::Check => commands::check_handler(&config).await?,
|
||||||
|
|||||||
Reference in New Issue
Block a user