Skip to content

Commit dd8b136

Browse files
authored
fix: reqwest https (#79)
1 parent d75ae07 commit dd8b136

File tree

11 files changed

+401
-95
lines changed

11 files changed

+401
-95
lines changed

Cargo.lock

Lines changed: 308 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
authors = ["Alex Chi <iskyzh@gmail.com>"]
3-
edition = "2018"
3+
edition = "2024"
44
name = "mirror-intel"
55
license = "Apache-2.0"
66
version = "0.1.0"
@@ -20,9 +20,9 @@ lazy_static = "1.4"
2020
percent-encoding = "2.1"
2121
prometheus = "0.14"
2222
regex = "1"
23-
reqwest = { version = "0.13", default-features = false, features = ["stream"] }
23+
reqwest = { version = "0.13", default-features = false, features = ["stream", "rustls"] }
2424
rstest = "0.26"
25-
serde = "1.0"
25+
serde = { version = "1.0", features = ["derive"] }
2626
thiserror = "2.0"
2727
tokio = { version = "1", features = ["full"] }
2828
tracing = "0.1"

src/artifacts.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
use std::borrow::Cow;
44
use std::collections::HashSet;
55
use std::path::{Path, PathBuf};
6-
use std::sync::atomic::{AtomicUsize, Ordering};
76
use std::sync::Arc;
7+
use std::sync::atomic::{AtomicUsize, Ordering};
88

99
use bytes::Bytes;
1010
use futures_util::StreamExt;
1111
use reqwest::{Client, Response};
1212
use tokio::fs::{self, OpenOptions};
1313
use tokio::io::{AsyncWriteExt, BufWriter};
14-
use tokio::sync::mpsc::{unbounded_channel, Receiver, UnboundedSender};
14+
use tokio::sync::mpsc::{Receiver, UnboundedSender, unbounded_channel};
1515
use tokio::sync::{Mutex, OwnedSemaphorePermit, Semaphore};
1616
use tracing::{info, instrument, warn};
1717
use url::Url;
@@ -56,10 +56,10 @@ fn next_buffer_path(config: &Config) -> PathBuf {
5656

5757
/// Remove a temporary file, ignoring not-found errors.
5858
async fn remove_buffer_file(path: &Path) {
59-
if let Err(err) = fs::remove_file(path).await {
60-
if err.kind() != std::io::ErrorKind::NotFound {
61-
warn!(error=?err, path=%path.display(), "failed to remove cache file");
62-
}
59+
if let Err(err) = fs::remove_file(path).await
60+
&& err.kind() != std::io::ErrorKind::NotFound
61+
{
62+
warn!(error=?err, path=%path.display(), "failed to remove cache file");
6363
}
6464
}
6565

src/browse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::borrow::Cow;
44
use std::time::Duration;
55

66
use actix_web::http::header::ContentType;
7-
use actix_web::{web, HttpResponse};
7+
use actix_web::{HttpResponse, web};
88

99
use crate::common::{Config, IntelMission, IntelResponse, Redirect};
1010
use crate::intel_path::IntelPath;

src/common.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Common types.
22
33
use actix_web::body::EitherBody;
4-
use actix_web::http::{header, StatusCode};
4+
use actix_web::http::{StatusCode, header};
55
use actix_web::{HttpRequest, HttpResponse, Responder};
66
use aws_sdk_s3::Client as S3Client;
7-
use figment::providers::{Format, Serialized, Toml};
87
use figment::Figment;
8+
use figment::providers::{Format, Serialized, Toml};
99
use percent_encoding::percent_decode;
10-
use prometheus::{proto, IntCounter as Counter, IntGauge as Gauge, Opts, Registry};
10+
use prometheus::{IntCounter as Counter, IntGauge as Gauge, Opts, Registry, proto};
1111
use reqwest::Client;
1212
use serde::Deserialize;
1313
use std::path::PathBuf;
@@ -373,10 +373,10 @@ mod tests {
373373
use figment::Jail;
374374
use serial_test::serial;
375375

376+
use crate::Config;
376377
use crate::common::{
377-
collect_config, EndpointOverride, Endpoints, GithubReleaseConfig, S3Config,
378+
EndpointOverride, Endpoints, GithubReleaseConfig, S3Config, collect_config,
378379
};
379-
use crate::Config;
380380

381381
#[allow(clippy::result_large_err)]
382382
#[test]

src/intel_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ops::Deref;
33

44
use actix_http::{Payload, StatusCode};
55
use actix_web::{FromRequest, HttpRequest, ResponseError};
6-
use futures_util::future::{ready, Ready};
6+
use futures_util::future::{Ready, ready};
77
use thiserror::Error;
88

99
/// `IntelPath` represents a URL-encoded path which is safe to use both

src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use std::sync::Arc;
1212

13-
use actix_web::{guard, web, App, HttpServer};
13+
use actix_web::{App, HttpServer, guard, web};
1414
use prometheus::{Encoder, TextEncoder};
1515
use reqwest::{Client, ClientBuilder};
1616
use tokio::sync::mpsc::channel;
@@ -19,7 +19,7 @@ use tracing_actix_web::TracingLogger;
1919
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
2020
use tracing_log::LogTracer;
2121
use tracing_subscriber::layer::SubscriberExt;
22-
use tracing_subscriber::{fmt, EnvFilter, Registry};
22+
use tracing_subscriber::{EnvFilter, Registry, fmt};
2323

2424
use artifacts::download_artifacts;
2525
use browse::list;
@@ -104,14 +104,14 @@ async fn main() {
104104

105105
info!("checking if bucket is available...");
106106
// check if credentials are set and we have permissions
107-
if !config.read_only {
108-
if let Err(error) = check_s3(&config.s3).await {
109-
warn!(
110-
?error,
111-
"s3 storage backend not available, but not running in read-only mode"
112-
);
113-
// config.read_only = true;
114-
}
107+
if !config.read_only
108+
&& let Err(error) = check_s3(&config.s3).await
109+
{
110+
warn!(
111+
?error,
112+
"s3 storage backend not available, but not running in read-only mode"
113+
);
114+
// config.read_only = true;
115115
}
116116

117117
info!(?config, "config loaded");

src/queue.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
use std::future::Future;
2-
3-
use actix_web::body::BoxBody;
1+
use actix_web::body::MessageBody;
42
use actix_web::dev::{Service, ServiceRequest, ServiceResponse};
5-
use actix_web::http::header::HeaderName;
63
use actix_web::http::Method;
4+
use actix_web::http::header::HeaderName;
75
use actix_web::web;
6+
use futures_util::future::LocalBoxFuture;
87

98
use crate::IntelMission;
109

11-
pub fn queue_length<S>(
10+
pub fn queue_length<S, B>(
1211
req: ServiceRequest,
1312
srv: &S,
14-
) -> impl Future<Output = Result<ServiceResponse, actix_web::Error>>
13+
) -> LocalBoxFuture<'static, Result<ServiceResponse<B>, actix_web::Error>>
1514
where
16-
S: Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = actix_web::Error>,
15+
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = actix_web::Error>,
16+
S::Future: 'static,
17+
B: MessageBody + 'static,
1718
{
1819
let length = (req.method() == Method::GET).then(|| {
1920
let mission = req
@@ -23,19 +24,18 @@ where
2324
mission.metrics.task_in_queue.get()
2425
});
2526
let fut = srv.call(req);
26-
async move {
27-
let mut resp: ServiceResponse<_> = fut.await?;
27+
28+
Box::pin(async move {
29+
let mut resp = fut.await?;
2830
if let Some(length) = length {
2931
// Rewrite the response to return the current counts.
3032
resp.headers_mut().append(
3133
HeaderName::from_static("x-intel-queue-length"),
3234
length.into(),
3335
);
34-
return Ok(resp);
3536
}
36-
3737
Ok(resp)
38-
}
38+
})
3939
}
4040

4141
#[cfg(test)]
@@ -44,13 +44,13 @@ mod tests {
4444

4545
use actix_http::Request;
4646
use actix_web::dev::{Service, ServiceResponse};
47-
use actix_web::test::{call_service, init_service, TestRequest};
48-
use actix_web::{web, App};
47+
use actix_web::test::{TestRequest, call_service, init_service};
48+
use actix_web::{App, web};
4949
use reqwest::Client;
5050

5151
use crate::common::S3Config;
5252
use crate::storage::get_anonymous_s3_client;
53-
use crate::{queue_length, IntelMission, Metrics};
53+
use crate::{IntelMission, Metrics, queue_length};
5454

5555
async fn make_service(
5656
metrics: Arc<Metrics>,

src/repos.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use actix_web::http::{Method, Uri};
2-
use actix_web::{guard, web, HttpResponse, Route};
2+
use actix_web::{HttpResponse, Route, guard, web};
33
use lazy_static::lazy_static;
44
use regex::Regex;
55

66
use crate::error::Result;
77
use crate::intel_path::IntelPath;
88
use crate::{
9+
Error,
910
common::{Config, Endpoints, IntelMission, IntelResponse, Redirect, Task},
10-
utils, Error,
11+
utils,
1112
};
1213

1314
pub fn simple_intel(
@@ -444,19 +445,19 @@ pub async fn index(path: IntelPath, config: web::Data<Config>) -> IntelResponse
444445
mod tests {
445446
use std::sync::Arc;
446447

447-
use actix_http::{body, Request};
448+
use actix_http::{Request, body};
449+
use actix_web::App;
448450
use actix_web::dev::{Service, ServiceResponse};
449451
use actix_web::http::StatusCode;
450-
use actix_web::test::{call_service, init_service, TestRequest};
451-
use actix_web::App;
452+
use actix_web::test::{TestRequest, call_service, init_service};
453+
use figment::Figment;
452454
use figment::providers::{Format, Toml};
453455
use figment::util::map;
454-
use figment::Figment;
455456
use httpmock::MockServer;
456457
use reqwest::ClientBuilder;
457458
use rstest::rstest;
458459
use serial_test::serial;
459-
use tokio::sync::mpsc::{channel, Receiver};
460+
use tokio::sync::mpsc::{Receiver, channel};
460461
use url::Url;
461462

462463
use crate::common::EndpointOverride;

src/storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! S3 storage backend.
22
use std::time::Duration;
33

4-
use aws_sdk_s3::config::{BehaviorVersion, Region};
54
use aws_sdk_s3::Client as S3Client;
5+
use aws_sdk_s3::config::Region;
66
use tokio::time::timeout;
77

88
use crate::common::S3Config;

0 commit comments

Comments
 (0)