Skip to content

Commit

Permalink
feat: replace filters with filtered_query_params (dragonflyoss#233)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <gaius.qi@gmail.com>
  • Loading branch information
gaius-qi authored Jan 24, 2024
1 parent d8c8a0b commit 0e336b3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ local-ip-address = "0.5.3"
rocksdb = "0.21.0"
num_cpus = "1.0"
chrono = { version = "0.4.26", features = ["serde"] }
dragonfly-api = "2.0.84"
dragonfly-api = "2.0.85"
sysinfo = "0.29.6"
sha2 = "0.10"
hex = "0.4"
Expand Down
8 changes: 4 additions & 4 deletions src/bin/dfget/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ struct Args {
header: Option<Vec<String>>,

#[arg(
long = "filter",
long = "filtered-query-param",
required = false,
help = "Filter the query parameters of the downloaded URL. If the download URL is the same, it will be scheduled as the same task, e.g. --filter='signature' --filter='timeout'"
help = "Filter the query parameters of the downloaded URL. If the download URL is the same, it will be scheduled as the same task, e.g. --filtered-query-param='signature' --filtered-query-param='timeout'"
)]
filters: Option<Vec<String>>,
filtered_query_params: Option<Vec<String>>,

#[arg(
long = "disable-back-to-source",
Expand Down Expand Up @@ -242,7 +242,7 @@ async fn main() -> Result<(), anyhow::Error> {
tag: Some(args.tag),
application: Some(args.application),
priority: args.priority,
filters: args.filters.unwrap_or_default(),
filtered_query_params: args.filtered_query_params.unwrap_or_default(),
request_header: header_vec_to_hashmap(args.header.unwrap_or_default())?,
piece_length: args.piece_length,
output_path: Some(args.output.into_os_string().into_string().unwrap()),
Expand Down
2 changes: 1 addition & 1 deletion src/grpc/dfdaemon_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl DfdaemonDownload for DfdaemonDownloadServerHandler {
download.tag.as_deref(),
download.application.as_deref(),
download.piece_length,
download.filters.clone(),
download.filtered_query_params.clone(),
)
.map_err(|e| {
error!("generate task id: {}", e);
Expand Down
5 changes: 4 additions & 1 deletion src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ fn make_download_task_request(
tag: header::get_tag(&header),
application: header::get_application(&header),
priority: header::get_priority(&header),
filters: header::get_filtered_query_params(&header, rule.filtered_query_params),
filtered_query_params: header::get_filtered_query_params(
&header,
rule.filtered_query_params,
),
request_header: headermap_to_hashmap(&header),
piece_length: header::get_piece_length(&header),
output_path: None,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/id_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ impl IDGenerator {
tag: Option<&str>,
application: Option<&str>,
piece_length: u64,
filters: Vec<String>,
filtered_query_params: Vec<String>,
) -> Result<String> {
// Filter the query parameters.
let url = Url::parse(url)?;
let query = url
.query_pairs()
.filter(|(k, _)| filters.contains(&k.to_string()));
.filter(|(k, _)| filtered_query_params.contains(&k.to_string()));
let mut artifact_url = url.clone();
artifact_url.query_pairs_mut().clear().extend_pairs(query);

Expand Down

0 comments on commit 0e336b3

Please sign in to comment.