mirror of
https://github.com/anthonyoteri/dredge.git
synced 2026-06-05 15:26:53 -04:00
Merge pull request #25 from anthonyoteri/fix-clippy-errors
Fix clippy security errors
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
+15
-15
@@ -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<T: for<'de> Deserialize<'de>>(
|
||||
log::trace!("fetch_all({path:?})");
|
||||
|
||||
let mut responses: Vec<T> = 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<T: for<'de> 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(
|
||||
|
||||
+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
|
||||
/// 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)?;
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
#![allow(clippy::enum_variant_names)]
|
||||
|
||||
#![allow(clippy::module_name_repetitions)]
|
||||
use thiserror::Error;
|
||||
|
||||
/// The common error type for this Application.
|
||||
|
||||
+4
-10
@@ -50,25 +50,19 @@ const CONFIG_PREFIX: &str = "dredge";
|
||||
fn locate_config_file(path: Option<OsString>) -> Option<PathBuf> {
|
||||
log::trace!("locate_config_file({path:?})");
|
||||
|
||||
match path {
|
||||
Some(path) => {
|
||||
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)
|
||||
}
|
||||
None => {
|
||||
} else {
|
||||
let xdg_dirs = xdg::BaseDirectories::with_prefix(CONFIG_PREFIX).ok()?;
|
||||
let search_paths: Vec<PathBuf> = 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:?}"
|
||||
);
|
||||
log::debug!("Searching configuration directories for {CONFIG_FILE_NAME} {search_paths:?}");
|
||||
xdg_dirs.find_config_file(CONFIG_FILE_NAME)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempt to create a default configuration file in the XDG configuration
|
||||
@@ -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?,
|
||||
|
||||
Reference in New Issue
Block a user