Skip to content

Commit 13d9a37

Browse files
committed
chore: enforce rustfmt
1 parent fb96341 commit 13d9a37

14 files changed

Lines changed: 122 additions & 96 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ jobs:
2424
- name: Install Clippy and Rustfmt
2525
run: rustup component add clippy rustfmt
2626

27+
- name: Check code formatting
28+
run: |
29+
cargo fmt --check --manifest-path enclaver/Cargo.toml
30+
2731
- name: Check with default features
2832
run: |
2933
cargo clippy --quiet --no-deps --manifest-path enclaver/Cargo.toml

enclaver/src/api.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use anyhow::Result;
22
use async_trait::async_trait;
3-
use hyper::header::CONTENT_TYPE;
4-
use hyper::{Request, Response, StatusCode, Method};
3+
use http_body_util::{BodyExt, Full};
54
use hyper::body::Bytes;
6-
use http_body_util::{Full, BodyExt};
5+
use hyper::header::CONTENT_TYPE;
6+
use hyper::{Method, Request, Response, StatusCode};
77
use pkcs8::{DecodePublicKey, SubjectPublicKeyInfo};
88
use serde::Deserialize;
99

enclaver/src/bin/odyn/kms_proxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use enclaver::http_util::HttpServer;
99
use enclaver::keypair::KeyPair;
1010
use enclaver::nsm::{Nsm, NsmAttestationProvider};
1111
use enclaver::proxy::aws_util;
12-
use enclaver::proxy::kms::{KmsProxyConfig, KmsProxyHandler, CredentialsGetter};
12+
use enclaver::proxy::kms::{CredentialsGetter, KmsProxyConfig, KmsProxyHandler};
1313

1414
use crate::config::Configuration;
1515

enclaver/src/build.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::manifest::{load_manifest, Manifest};
66
use crate::nitro_cli::{EIFInfo, KnownIssue};
77
use anyhow::{anyhow, Result};
88
use bollard::container::{Config, LogOutput, LogsOptions, WaitContainerOptions};
9-
use bollard::models::{ImageConfig, HostConfig, Mount, MountTypeEnum};
9+
use bollard::models::{HostConfig, ImageConfig, Mount, MountTypeEnum};
1010
use bollard::Docker;
1111
use futures_util::stream::{StreamExt, TryStreamExt};
1212
use log::{debug, info, warn};
@@ -96,15 +96,22 @@ impl EnclaveArtifactBuilder {
9696

9797
if let Some(signature) = &manifest.signature {
9898
if let Some(parent_path) = PathBuf::from(manifest_path).parent() {
99-
certificate_path = Some(canonicalize(parent_path.join(&signature.certificate)).await?);
99+
certificate_path =
100+
Some(canonicalize(parent_path.join(&signature.certificate)).await?);
100101
key_path = Some(canonicalize(parent_path.join(&signature.key)).await?);
101102
} else {
102103
return Err(anyhow!("Failed to get parent path of manifest"));
103104
}
104105
}
105106

106107
let eif_info = self
107-
.image_to_eif(&amended_img, &build_dir, EIF_FILE_NAME, key_path, certificate_path)
108+
.image_to_eif(
109+
&amended_img,
110+
&build_dir,
111+
EIF_FILE_NAME,
112+
key_path,
113+
certificate_path,
114+
)
108115
.await?;
109116

110117
Ok(IntermediateBuildResult {
@@ -237,7 +244,7 @@ impl EnclaveArtifactBuilder {
237244
build_dir: &TempDir,
238245
eif_name: &str,
239246
key: Option<PathBuf>,
240-
certificate: Option<PathBuf>
247+
certificate: Option<PathBuf>,
241248
) -> Result<EIFInfo> {
242249
let build_dir_path = build_dir.path().to_str().unwrap();
243250

@@ -288,7 +295,6 @@ impl EnclaveArtifactBuilder {
288295
cmd.push("--private-key");
289296
cmd.push("/var/run/key");
290297

291-
292298
mounts.push(Mount {
293299
typ: Some(MountTypeEnum::BIND),
294300
source: Some(key_path.to_string_lossy().to_string()),

enclaver/src/http_client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use hyper::Uri;
21
use hyper::body::Body;
3-
use hyper_util::client::legacy::Client;
2+
use hyper::Uri;
3+
use hyper_proxy2::{Intercept, Proxy, ProxyConnector};
44
use hyper_util::client::legacy::connect::HttpConnector;
5+
use hyper_util::client::legacy::Client;
56
use hyper_util::rt::TokioExecutor;
6-
use hyper_proxy2::{Intercept, Proxy, ProxyConnector};
77

88
pub type HttpProxyClient<B> = Client<ProxyConnector<HttpConnector>, B>;
99

@@ -12,7 +12,7 @@ pub fn new_http_proxy_client<B>(proxy_uri: Uri) -> HttpProxyClient<B>
1212
where
1313
B: Body + Send + 'static,
1414
B::Data: Send,
15-
B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
15+
B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
1616
{
1717
let proxy = Proxy::new(Intercept::All, proxy_uri);
1818
let connector = HttpConnector::new();

enclaver/src/http_util.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use std::sync::Arc;
33

44
use anyhow::Result;
55
use async_trait::async_trait;
6-
use hyper::{Request, Response, StatusCode};
7-
use hyper::server::conn::http1;
6+
use http_body_util::{BodyExt, Full};
87
use hyper::body::{Bytes, Incoming};
8+
use hyper::server::conn::http1;
99
use hyper::service::service_fn;
10+
use hyper::{Request, Response, StatusCode};
1011
use hyper_util::rt::TokioIo;
11-
use http_body_util::{Full, BodyExt};
1212
use tokio::net::TcpListener;
1313

1414
#[async_trait]
@@ -45,16 +45,20 @@ impl HttpServer {
4545
// Finally, we bind the incoming connection to our `hello` service
4646
if let Err(err) = http1::Builder::new()
4747
// `service_fn` converts our function in a `Service`
48-
.serve_connection(io, service_fn(move |req: Request<Incoming>| {
49-
let handler = handler.clone(); // Clone before moving into async block
50-
async move {
51-
let (head, body) = req.into_parts();
52-
let body = body.collect().await?;
48+
.serve_connection(
49+
io,
50+
service_fn(move |req: Request<Incoming>| {
51+
let handler = handler.clone(); // Clone before moving into async block
52+
async move {
53+
let (head, body) = req.into_parts();
54+
let body = body.collect().await?;
5355

54-
let req_full = Request::from_parts(head, Full::new(body.to_bytes()));
55-
handler.handle(req_full).await
56-
}
57-
}))
56+
let req_full =
57+
Request::from_parts(head, Full::new(body.to_bytes()));
58+
handler.handle(req_full).await
59+
}
60+
}),
61+
)
5862
.await
5963
{
6064
eprintln!("Error serving connection: {:?}", err);

enclaver/src/images.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ impl ImageManager {
134134
// pair of streams, and lazily write the tarball to one of them while streaming
135135
// the other end of the pipe into the daemon request.
136136
let (tar_write, tar_read) = duplex(1024);
137-
let byte_stream = codec::FramedRead::new(tar_read, codec::BytesCodec::new()).map(|r| {
138-
r.unwrap().freeze()
139-
});
137+
let byte_stream =
138+
codec::FramedRead::new(tar_read, codec::BytesCodec::new()).map(|r| r.unwrap().freeze());
140139

141140
// Concurrently build the context tarball and perform the build request.
142141
let (realize_res, build_res) = tokio::join!(

enclaver/src/proxy/aws_util.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ use std::sync::Arc;
22

33
use anyhow::{anyhow, Result};
44
use http::Uri;
5-
use hyper::body::Bytes;
65
use http_body_util::BodyExt;
6+
use hyper::body::Bytes;
77

88
use aws_config::imds;
99
use aws_config::imds::credentials::ImdsCredentialsProvider;
1010
use aws_config::imds::region::ImdsRegionProvider;
1111
use aws_config::provider_config::ProviderConfig;
12-
use aws_types::sdk_config::{SdkConfig, SharedHttpClient, SharedCredentialsProvider};
12+
use aws_types::sdk_config::{SdkConfig, SharedCredentialsProvider, SharedHttpClient};
1313

14+
use aws_smithy_runtime_api::client::http::{
15+
HttpClient, HttpConnector, HttpConnectorFuture, HttpConnectorSettings, SharedHttpConnector,
16+
};
17+
use aws_smithy_runtime_api::client::result::ConnectorError;
1418
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
1519
use aws_smithy_runtime_api::http::Request;
16-
use aws_smithy_runtime_api::client::http::{HttpClient, HttpConnectorSettings, SharedHttpConnector, HttpConnector, HttpConnectorFuture};
17-
use aws_smithy_runtime_api::client::result::ConnectorError;
1820
use aws_smithy_types::body::SdkBody;
1921

2022
use crate::http_client::HttpProxyClient;
@@ -26,7 +28,9 @@ struct ProxiedHttpClient(Arc<HttpProxyClient<SdkBody>>);
2628

2729
impl ProxiedHttpClient {
2830
fn new(proxy_uri: Uri) -> Self {
29-
Self(Arc::new(crate::http_client::new_http_proxy_client(proxy_uri)))
31+
Self(Arc::new(crate::http_client::new_http_proxy_client(
32+
proxy_uri,
33+
)))
3034
}
3135
}
3236

@@ -47,7 +51,8 @@ impl HttpConnector for ProxiedHttpClient {
4751
let request = request.try_into_http1x().unwrap();
4852
let response = client.request(request).await.unwrap();
4953
let (head, body) = response.into_parts();
50-
body.collect().await
54+
body.collect()
55+
.await
5156
.map_err(|err| ConnectorError::user(err.into()))
5257
.and_then(|body| into_aws_response(head, body.to_bytes()))
5358
};
@@ -56,9 +61,10 @@ impl HttpConnector for ProxiedHttpClient {
5661
}
5762
}
5863

59-
fn into_aws_response(head: hyper::http::response::Parts, body: Bytes)
60-
-> Result<aws_smithy_runtime_api::client::orchestrator::HttpResponse, ConnectorError>
61-
{
64+
fn into_aws_response(
65+
head: hyper::http::response::Parts,
66+
body: Bytes,
67+
) -> Result<aws_smithy_runtime_api::client::orchestrator::HttpResponse, ConnectorError> {
6268
let resp = http::Response::from_parts(head, body.into());
6369
aws_smithy_runtime_api::client::orchestrator::HttpResponse::try_from(resp)
6470
.map_err(|err| ConnectorError::user(err.into()))
@@ -77,7 +83,7 @@ pub async fn imds_client_with_proxy(proxy_uri: Uri) -> Result<imds::Client> {
7783
let client = imds::Client::builder()
7884
.configure(&config)
7985
.endpoint(IMDS_URL)
80-
.map_err( anyhow::Error::from_boxed)?
86+
.map_err(anyhow::Error::from_boxed)?
8187
.build();
8288

8389
Ok(client)

enclaver/src/proxy/egress_http.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use anyhow::anyhow;
66
use async_trait::async_trait;
77
use futures::{Stream, StreamExt};
88
use http_body_util::combinators::BoxBody;
9-
use hyper::{Method, Request, Response, StatusCode};
9+
use http_body_util::Full;
1010
use hyper::body::{Body, Bytes, Incoming};
11-
use hyper::http::uri::PathAndQuery;
11+
use hyper::client::conn::http1 as http1_client;
1212
use hyper::header::HeaderValue;
13+
use hyper::http::uri::PathAndQuery;
1314
use hyper::server::conn::http1 as http1_server;
14-
use hyper::client::conn::http1 as http1_client;
1515
use hyper::service::service_fn;
16+
use hyper::{Method, Request, Response, StatusCode};
1617
use hyper_util::rt::TokioIo;
17-
use http_body_util::Full;
1818
use log::{debug, error};
1919
use serde::{de::DeserializeOwned, Deserialize, Serialize};
2020
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
@@ -211,7 +211,8 @@ async fn proxy(
211211

212212
fn with_boxed_body<B>(resp: Response<B>) -> Response<BoxBody<Bytes, anyhow::Error>>
213213
where
214-
B: Body<Data = Bytes> + Send + Sync + 'static, <B as hyper::body::Body>::Error: std::error::Error + Send + Sync
214+
B: Body<Data = Bytes> + Send + Sync + 'static,
215+
<B as hyper::body::Body>::Error: std::error::Error + Send + Sync,
215216
{
216217
use http_body_util::BodyExt;
217218

@@ -246,9 +247,7 @@ async fn handle_connect(
246247
// Connect to remote server before the upgrade so we can return an error if it fails
247248
let mut remote = match remote_connect(egress_port, authority.host(), port).await {
248249
Ok(remote) => remote,
249-
Err(err) => {
250-
return err_resp(StatusCode::SERVICE_UNAVAILABLE, err.to_string())
251-
}
250+
Err(err) => return err_resp(StatusCode::SERVICE_UNAVAILABLE, err.to_string()),
252251
};
253252

254253
tokio::task::spawn(async move {
@@ -280,7 +279,11 @@ async fn handle_request(
280279
) -> anyhow::Result<Response<BoxBody<Bytes, anyhow::Error>>> {
281280
let host = match req.uri().host() {
282281
Some(host) => host,
283-
None => return Ok(with_boxed_body(bad_request("URI is missing a host".to_string()))),
282+
None => {
283+
return Ok(with_boxed_body(bad_request(
284+
"URI is missing a host".to_string(),
285+
)))
286+
}
284287
};
285288
let port = req.uri().port_u16().unwrap_or(80);
286289

@@ -390,12 +393,12 @@ async fn remote_connect(egress_port: u32, host: &str, port: u16) -> anyhow::Resu
390393
mod tests {
391394
use assert2::assert;
392395
use http::{uri::PathAndQuery, Method, Version};
393-
use hyper::{Request, Response};
396+
use http_body_util::{BodyExt, Full};
394397
use hyper::body::{Bytes, Incoming};
395398
use hyper::server::conn::http1 as http1_server;
396399
use hyper::service::service_fn;
400+
use hyper::{Request, Response};
397401
use hyper_util::rt::TokioIo;
398-
use http_body_util::{Full, BodyExt};
399402
use rand::RngCore;
400403
use std::convert::Infallible;
401404
use std::net::{Ipv4Addr, SocketAddr};

enclaver/src/proxy/ingress.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ mod tests {
126126
use anyhow::Result;
127127
use assert2::assert;
128128
use rand::RngCore;
129-
use tokio_rustls::rustls::{ClientConfig, ServerConfig};
130-
use tokio_rustls::rustls::pki_types::ServerName;
131129
use std::collections::hash_map::DefaultHasher;
132130
use std::hash::Hasher;
133131
use std::net::{Ipv4Addr, SocketAddrV4};
@@ -136,6 +134,8 @@ mod tests {
136134
use tokio::net::{TcpListener, TcpStream};
137135
use tokio::sync::watch::Sender;
138136
use tokio::task::JoinHandle;
137+
use tokio_rustls::rustls::pki_types::ServerName;
138+
use tokio_rustls::rustls::{ClientConfig, ServerConfig};
139139
use tokio_rustls::TlsConnector;
140140

141141
use super::{EnclaveProxy, HostProxy};

0 commit comments

Comments
 (0)