Skip to content

Commit

Permalink
skip file paths that do not conform to expected path
Browse files Browse the repository at this point in the history
  • Loading branch information
afujiwara-roblox committed Oct 10, 2023
1 parent 9c45ba2 commit 2e0cc09
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/tool_provider/artifactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ impl ToolProviderImpl for ArtifactoryProvider {
let mut releases: Vec<ArtifactoryRelease> = Vec::new();
let mut release_map: HashMap<&str, Vec<ArtifactoryAsset>> = HashMap::new();
for file in &response.files {
let mut uri = file.uri.split("/");
// file.uri will look something like /<version>/<artifact-name>, so uri will be ["", <version>, <artifact-name]
uri.next();
let version = uri.next().unwrap();
let asset_name = uri.next().unwrap();
let uri = file.uri.split("/");
// file.uri should look something like /<version>/<artifact-name>, so uri will be ["", <version>, <artifact-name]
// we should skip files that do not follow the expected path
let Some((version, asset_name)) = get_version_and_asset_name(uri) else {
log::debug!(
"Skipping '{}', does not match expected file path <version>/<asset_name>",
file.uri
);
continue;
};

let asset_url = format!("{}artifactory/{}/{}/{}", host, repo, version, asset_name);

Expand Down Expand Up @@ -106,6 +111,33 @@ impl ToolProviderImpl for ArtifactoryProvider {
}
}

fn get_version_and_asset_name<'a, I>(mut uri: I) -> Option<(&'a str, &'a str)>
where
I: Iterator<Item = &'a str>,
{
let Some(empty_string) = uri.next() else {
return None;
};

if empty_string != "" {
return None;
}

let Some(version) = uri.next() else {
return None;
};

let Some(asset_name) = uri.next() else {
return None;
};

if uri.next().is_some() {
return None;
}

Some((version, asset_name))
}

#[derive(Debug, Serialize, Deserialize)]
struct ArtifactoryResponse {
files: Vec<ArtifactoryResponseFiles>,
Expand Down

0 comments on commit 2e0cc09

Please sign in to comment.