diff --git a/.github/workflows/rust-clippy.yml b/.github/workflows/rust-clippy.yml index f299c9f..b302a2b 100644 --- a/.github/workflows/rust-clippy.yml +++ b/.github/workflows/rust-clippy.yml @@ -41,7 +41,6 @@ jobs: --all-features --tests --message-format=json - -- -D warnings | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt continue-on-error: true diff --git a/src/api.rs b/src/api.rs index 7c79611..3c8ba5c 100644 --- a/src/api.rs +++ b/src/api.rs @@ -24,7 +24,7 @@ use crate::error::ApiError; /// /// 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. -/// 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 /// returned, collecting and returning the deserialized response bodies as a @@ -43,17 +43,17 @@ pub async fn fetch_all Deserialize<'de>>( log::trace!("fetch_all({path:?})"); let mut responses: Vec = Vec::default(); - let mut uri = String::from(path); + let mut path = String::from(path); loop { - log::debug!("GET {uri:?}"); - let url = config.registry_url.join(&uri)?; + log::debug!("GET {path:?}"); + let url = config.registry_url.join(&path)?; let resp = reqwest::get(url).await?; - let headers = resp.headers().to_owned(); + let headers = resp.headers().clone(); responses.push(resp.json().await?); - if let Some(path) = parse_rfc5988(headers.get(http::header::LINK))? { - uri = path; + if let Some(p) = parse_rfc5988(headers.get(http::header::LINK))? { + path = p; } else { break; } @@ -64,8 +64,8 @@ pub async fn fetch_all Deserialize<'de>>( /// Given an optional header value possibly containing an RFC5988 formatted /// URL, parse said URL into a `String`. /// -/// If the header_value does not contain a correctly formatted RFC5988 URL, -/// or if the header_value is not properly formatted containing a 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 /// surrounded by angle brackets, separated from the link relation by a ';' /// character, the `None` variant will be returned. /// @@ -128,10 +128,10 @@ pub fn parse_response_status(response: &reqwest::Response) -> Result<(), ApiErro http::StatusCode::OK => { let headers = response.headers(); if let Some(header_value) = headers.get("Docker-Distribution-API-Version") { - if header_value.to_str()? != "registry/2.0" { - Err(ApiError::UnsupportedVersion(header_value.to_str()?.into())) - } else { + if header_value.to_str()? == "registry/2.0" { Ok(()) + } else { + Err(ApiError::UnsupportedVersion(header_value.to_str()?.into())) } } else { Err(ApiError::UnexpectedResponse( @@ -142,10 +142,10 @@ pub fn parse_response_status(response: &reqwest::Response) -> Result<(), ApiErro http::StatusCode::UNAUTHORIZED => { let headers = response.headers(); if let Some(header_value) = headers.get("Docker-Distribution-API-Version") { - if header_value.to_str()? != "registry/2.0" { - Err(ApiError::UnsupportedVersion(header_value.to_str()?.into())) - } else { + if header_value.to_str()? == "registry/2.0" { Err(ApiError::AuthorizationFailed) + } else { + Err(ApiError::UnsupportedVersion(header_value.to_str()?.into())) } } else { Err(ApiError::UnexpectedResponse( diff --git a/src/commands.rs b/src/commands.rs index 58f9356..df69589 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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 /// 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> { 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 _url = base.join(&path)?; 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 /// manifest digest, or if there is a problem deleting the manifest from the /// Docker Registry API. +#[allow(clippy::unused_async)] pub async fn delete_handler(_config: &Config, image: &str, tag: &str) -> Result<(), ApiError> { log::trace!("delete_handler(image: {image}, tag: {tag})"); 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> { log::trace!("check_handler()"); - let base = config.registry_url.to_owned(); + let base = config.registry_url.clone(); let path = "/v2"; let url = base.join(path)?; diff --git a/src/error.rs b/src/error.rs index 58638aa..897873a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -15,7 +15,7 @@ */ #![allow(clippy::enum_variant_names)] - +#![allow(clippy::module_name_repetitions)] use thiserror::Error; /// The common error type for this Application. diff --git a/src/main.rs b/src/main.rs index 8be0c86..e28234e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,24 +50,18 @@ const CONFIG_PREFIX: &str = "dredge"; fn locate_config_file(path: Option) -> Option { log::trace!("locate_config_file({path:?})"); - match path { - Some(path) => { - let p = PathBuf::from(path); - log::debug!("Checking if path {p:?} exists"); - p.try_exists().map(|_| Some(p)).unwrap_or(None) - } - None => { - let xdg_dirs = xdg::BaseDirectories::with_prefix(CONFIG_PREFIX).ok()?; - let search_paths: Vec = vec![xdg_dirs.get_config_home()] - .into_iter() - .chain(xdg_dirs.get_config_dirs()) - .collect(); - - log::debug!( - "Searching configuration directories for {CONFIG_FILE_NAME} {search_paths:?}" - ); - xdg_dirs.find_config_file(CONFIG_FILE_NAME) - } + if let Some(path) = path { + let p = PathBuf::from(path); + log::debug!("Checking if path {p:?} exists"); + p.try_exists().map(|_| Some(p)).unwrap_or(None) + } else { + let xdg_dirs = xdg::BaseDirectories::with_prefix(CONFIG_PREFIX).ok()?; + let search_paths: Vec = vec![xdg_dirs.get_config_home()] + .into_iter() + .chain(xdg_dirs.get_config_dirs()) + .collect(); + 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::Tags { name } => commands::tags_handler(&config, &name).await?, 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::Check => commands::check_handler(&config).await?,