Skip to content

Commit e9448e8

Browse files
authored
Remove unused imports. (awslabs#3)
Signed-off-by: David Calavera <[email protected]>
1 parent 2c0d41b commit e9448e8

File tree

8 files changed

+133
-170
lines changed

8 files changed

+133
-170
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,12 @@ jobs:
6363
- uses: actions/checkout@v1
6464
- uses: actions-rs/toolchain@v1
6565
with:
66-
toolchain: nightly
67-
components: rustfmt
66+
toolchain: stable
67+
components:
68+
- rustfmt
69+
- clippy
6870
override: true
6971
- name: Run fmt check
7072
run: cargo fmt --all -- --check
71-
72-
# publish rustdoc to a gh-pages branch on pushes to master
73-
# this can be helpful to those depending on the mainline branch
74-
publish-docs:
75-
if: github.ref == 'refs/heads/master'
76-
runs-on: ubuntu-latest
77-
needs: [build]
78-
steps:
79-
- name: Set up Rust
80-
uses: hecrj/setup-rust-action@v1
81-
- uses: actions/checkout@v2
82-
- name: Generate Docs
83-
run: |
84-
cargo doc --no-deps
85-
echo "<meta http-equiv=refresh content=0;url=lambda/index.html>" > target/doc/index.html
86-
- name: Publish
87-
uses: peaceiris/actions-gh-pages@v3
88-
with:
89-
github_token: ${{ secrets.GITHUB_TOKEN }}
90-
publish_dir: ./target/doc
73+
- name: Run clippy check
74+
run: cargo clippy --all-targets --all-features -- -D warnings

lambda-attributes/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(clippy::all)]
12
extern crate proc_macro;
23

34
use proc_macro::TokenStream;

lambda-http/examples/hello-http-without-macros.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
use netlify_lambda_http::{
2-
handler,
3-
lambda::{self, Context},
4-
IntoResponse, Request, RequestExt, Response,
5-
};
1+
use netlify_lambda_http::{handler, lambda::Context, IntoResponse, Request, RequestExt, Response};
62

73
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
84

lambda-http/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![warn(missing_docs)]
2-
//#![deny(warnings)]
1+
#![deny(clippy::all)]
32
//! Enriches the `lambda` crate with [`http`](https://github.com/hyperium/http)
43
//! types targeting AWS [ALB](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html), [API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html) REST and HTTP API lambda integrations.
54
//!

lambda/examples/basic.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use netlify_lambda::{handler_fn, Context};
55
use serde::{Deserialize, Serialize};
6-
use simple_logger;
76

87
/// A shorthand for `Box<dyn std::error::Error + Send + Sync + 'static>`
98
/// type required by aws-lambda-rust-runtime.
@@ -29,10 +28,6 @@ struct Response {
2928

3029
#[tokio::main]
3130
async fn main() -> Result<(), Error> {
32-
// required to enable CloudWatch error logging by the runtime
33-
// can be replaced with any other method of initializing `log`
34-
simple_logger::init_with_level(log::Level::Info)?;
35-
3631
let func = handler_fn(my_handler);
3732
netlify_lambda::run(func).await?;
3833
Ok(())

lambda/examples/error-handling.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ impl std::fmt::Display for CustomError {
5252

5353
#[tokio::main]
5454
async fn main() -> Result<(), Error> {
55-
// The runtime logging can be enabled here by initializing `log` with `simple_logger`
56-
// or another compatible crate. The runtime is using `tracing` internally.
57-
// You can comment out the `simple_logger` init line and uncomment the following block to
58-
// use `tracing` in the handler function.
59-
//
60-
simple_logger::init_with_level(log::Level::Info)?;
61-
/*
6255
tracing_subscriber::fmt()
6356
.with_max_level(tracing::Level::INFO)
6457
// this needs to be set to false, otherwise ANSI color codes will
@@ -67,7 +60,6 @@ async fn main() -> Result<(), Error> {
6760
// disabling time is handy because CloudWatch will add the ingestion time.
6861
.without_time()
6962
.init();
70-
*/
7163

7264
// call the actual handler of the request
7365
let func = handler_fn(func);

lambda/src/client.rs

Lines changed: 123 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,6 @@
1-
use crate::{
2-
requests::{IntoResponse, NextEventResponse},
3-
Error,
4-
};
5-
use http::{
6-
uri::{PathAndQuery, Scheme},
7-
HeaderValue, Method, Request, Response, StatusCode, Uri,
8-
};
9-
use hyper::{client::HttpConnector, server::conn::Http, service::service_fn, Body};
10-
use serde_json::json;
11-
use std::convert::TryFrom;
12-
use tokio::{
13-
io::{AsyncRead, AsyncWrite},
14-
select,
15-
sync::oneshot,
16-
};
17-
use tracing::{error, info, instrument};
18-
19-
#[instrument]
20-
async fn hello(req: Request<Body>) -> Result<Response<Body>, Error> {
21-
Ok(Response::new(Body::from("hello")))
22-
}
23-
24-
async fn handle_incoming(req: Request<Body>) -> Result<Response<Body>, Error> {
25-
let path: Vec<&str> = req
26-
.uri()
27-
.path_and_query()
28-
.unwrap()
29-
.as_str()
30-
.split("/")
31-
.collect::<Vec<&str>>();
32-
match &path[1..] {
33-
["2018-06-01", "runtime", "invocation", "next"] => next_event(&req).await,
34-
["2018-06-01", "runtime", "invocation", id, "response"] => complete_event(&req, id).await,
35-
["2018-06-01", "runtime", "invocation", id, "error"] => event_err(&req, id).await,
36-
["2018-06-01", "runtime", "init", "error"] => unimplemented!(),
37-
_ => unimplemented!(),
38-
}
39-
}
40-
41-
#[instrument(skip(io, rx))]
42-
async fn handle<I>(io: I, rx: oneshot::Receiver<()>) -> Result<(), hyper::error::Error>
43-
where
44-
I: AsyncRead + AsyncWrite + Unpin + 'static,
45-
{
46-
let conn = Http::new().serve_connection(io, service_fn(handle_incoming));
47-
select! {
48-
_ = rx => {
49-
info!("Received cancelation signal");
50-
return Ok(())
51-
}
52-
res = conn => {
53-
match res {
54-
Ok(()) => return Ok(()),
55-
Err(e) => {
56-
error!(message = "Got error serving connection", e = %e);
57-
return Err(e);
58-
}
59-
}
60-
}
61-
}
62-
}
1+
use crate::Error;
2+
use http::{uri::Scheme, Request, Response, Uri};
3+
use hyper::{client::HttpConnector, Body};
634

645
#[derive(Debug)]
656
pub(crate) struct Client<C = HttpConnector> {
@@ -105,83 +46,139 @@ where
10546
}
10647
}
10748

108-
async fn next_event(req: &Request<Body>) -> Result<Response<Body>, Error> {
109-
let path = "/2018-06-01/runtime/invocation/next";
110-
assert_eq!(req.method(), Method::GET);
111-
assert_eq!(req.uri().path_and_query().unwrap(), &PathAndQuery::from_static(path));
112-
let body = json!({"message": "hello"});
113-
114-
let rsp = NextEventResponse {
115-
request_id: "8476a536-e9f4-11e8-9739-2dfe598c3fcd",
116-
deadline: 1_542_409_706_888,
117-
arn: "arn:aws:lambda:us-east-2:123456789012:function:custom-runtime",
118-
trace_id: "Root=1-5bef4de7-ad49b0e87f6ef6c87fc2e700;Parent=9a9197af755a6419",
119-
body: serde_json::to_vec(&body)?,
49+
#[cfg(test)]
50+
mod endpoint_tests {
51+
use crate::{
52+
requests::{
53+
EventCompletionRequest, EventErrorRequest, IntoRequest, IntoResponse, NextEventRequest, NextEventResponse,
54+
},
55+
simulated::Connector,
56+
types::Diagnostic,
57+
Error,
12058
};
121-
rsp.into_rsp().map_err(|e| e.into())
122-
}
59+
use http::{
60+
uri::{PathAndQuery, Scheme},
61+
HeaderValue, Method, Request, Response, StatusCode, Uri,
62+
};
63+
use hyper::{server::conn::Http, service::service_fn, Body};
64+
use serde_json::json;
65+
use std::convert::TryFrom;
66+
use tokio::{
67+
io::{AsyncRead, AsyncWrite},
68+
select, sync,
69+
sync::oneshot,
70+
};
71+
use tracing::{error, info, instrument};
12372

124-
async fn complete_event(req: &Request<Body>, id: &str) -> Result<Response<Body>, Error> {
125-
assert_eq!(Method::POST, req.method());
126-
let rsp = Response::builder()
127-
.status(StatusCode::ACCEPTED)
128-
.body(Body::empty())
129-
.expect("Unable to construct response");
73+
#[instrument]
74+
async fn hello(req: Request<Body>) -> Result<Response<Body>, Error> {
75+
Ok(Response::new(Body::from("hello")))
76+
}
13077

131-
let expected = format!("/2018-06-01/runtime/invocation/{}/response", id);
132-
assert_eq!(expected, req.uri().path());
78+
async fn handle_incoming(req: Request<Body>) -> Result<Response<Body>, Error> {
79+
let path: Vec<&str> = req
80+
.uri()
81+
.path_and_query()
82+
.unwrap()
83+
.as_str()
84+
.split("/")
85+
.collect::<Vec<&str>>();
86+
match &path[1..] {
87+
["2018-06-01", "runtime", "invocation", "next"] => next_event(&req).await,
88+
["2018-06-01", "runtime", "invocation", id, "response"] => complete_event(&req, id).await,
89+
["2018-06-01", "runtime", "invocation", id, "error"] => event_err(&req, id).await,
90+
["2018-06-01", "runtime", "init", "error"] => unimplemented!(),
91+
_ => unimplemented!(),
92+
}
93+
}
13394

134-
Ok(rsp)
135-
}
95+
#[instrument(skip(io, rx))]
96+
async fn handle<I>(io: I, rx: oneshot::Receiver<()>) -> Result<(), hyper::error::Error>
97+
where
98+
I: AsyncRead + AsyncWrite + Unpin + 'static,
99+
{
100+
let conn = Http::new().serve_connection(io, service_fn(handle_incoming));
101+
select! {
102+
_ = rx => {
103+
info!("Received cancelation signal");
104+
return Ok(())
105+
}
106+
res = conn => {
107+
match res {
108+
Ok(()) => return Ok(()),
109+
Err(e) => {
110+
error!(message = "Got error serving connection", e = %e);
111+
return Err(e);
112+
}
113+
}
114+
}
115+
}
116+
}
136117

137-
async fn event_err(req: &Request<Body>, id: &str) -> Result<Response<Body>, Error> {
138-
let expected = format!("/2018-06-01/runtime/invocation/{}/error", id);
139-
assert_eq!(expected, req.uri().path());
118+
async fn next_event(req: &Request<Body>) -> Result<Response<Body>, Error> {
119+
let path = "/2018-06-01/runtime/invocation/next";
120+
assert_eq!(req.method(), Method::GET);
121+
assert_eq!(req.uri().path_and_query().unwrap(), &PathAndQuery::from_static(path));
122+
let body = json!({"message": "hello"});
123+
124+
let rsp = NextEventResponse {
125+
request_id: "8476a536-e9f4-11e8-9739-2dfe598c3fcd",
126+
deadline: 1_542_409_706_888,
127+
arn: "arn:aws:lambda:us-east-2:123456789012:function:custom-runtime",
128+
trace_id: "Root=1-5bef4de7-ad49b0e87f6ef6c87fc2e700;Parent=9a9197af755a6419",
129+
body: serde_json::to_vec(&body)?,
130+
};
131+
rsp.into_rsp().map_err(|e| e.into())
132+
}
140133

141-
assert_eq!(req.method(), Method::POST);
142-
let header = "lambda-runtime-function-error-type";
143-
let expected = "unhandled";
144-
assert_eq!(req.headers()[header], HeaderValue::try_from(expected)?);
134+
async fn complete_event(req: &Request<Body>, id: &str) -> Result<Response<Body>, Error> {
135+
assert_eq!(Method::POST, req.method());
136+
let rsp = Response::builder()
137+
.status(StatusCode::ACCEPTED)
138+
.body(Body::empty())
139+
.expect("Unable to construct response");
145140

146-
let rsp = Response::builder().status(StatusCode::ACCEPTED).body(Body::empty())?;
147-
Ok(rsp)
148-
}
141+
let expected = format!("/2018-06-01/runtime/invocation/{}/response", id);
142+
assert_eq!(expected, req.uri().path());
149143

150-
fn set_origin<B>(base: Uri, req: Request<B>) -> Result<Request<B>, Error> {
151-
let (mut parts, body) = req.into_parts();
152-
let (scheme, authority) = {
153-
let scheme = base.scheme().unwrap_or(&Scheme::HTTP);
154-
let authority = base.authority().expect("Authority not found");
155-
(scheme, authority)
156-
};
157-
let path = parts.uri.path_and_query().expect("PathAndQuery not found");
144+
Ok(rsp)
145+
}
158146

159-
let uri = Uri::builder()
160-
.scheme(scheme.clone())
161-
.authority(authority.clone())
162-
.path_and_query(path.clone())
163-
.build()
164-
.expect("Unable to build URI");
147+
async fn event_err(req: &Request<Body>, id: &str) -> Result<Response<Body>, Error> {
148+
let expected = format!("/2018-06-01/runtime/invocation/{}/error", id);
149+
assert_eq!(expected, req.uri().path());
165150

166-
parts.uri = uri;
167-
Ok(Request::from_parts(parts, body))
168-
}
151+
assert_eq!(req.method(), Method::POST);
152+
let header = "lambda-runtime-function-error-type";
153+
let expected = "unhandled";
154+
assert_eq!(req.headers()[header], HeaderValue::try_from(expected)?);
169155

170-
#[cfg(test)]
171-
mod endpoint_tests {
172-
use super::{handle, set_origin};
173-
use crate::{
174-
requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEventRequest},
175-
simulated::Connector,
176-
types::Diagnostic,
177-
Error,
178-
};
179-
use http::{HeaderValue, StatusCode, Uri};
180-
use std::convert::TryFrom;
181-
use tokio::sync;
156+
let rsp = Response::builder().status(StatusCode::ACCEPTED).body(Body::empty())?;
157+
Ok(rsp)
158+
}
159+
160+
fn set_origin<B>(base: Uri, req: Request<B>) -> Result<Request<B>, Error> {
161+
let (mut parts, body) = req.into_parts();
162+
let (scheme, authority) = {
163+
let scheme = base.scheme().unwrap_or(&Scheme::HTTP);
164+
let authority = base.authority().expect("Authority not found");
165+
(scheme, authority)
166+
};
167+
let path = parts.uri.path_and_query().expect("PathAndQuery not found");
168+
169+
let uri = Uri::builder()
170+
.scheme(scheme.clone())
171+
.authority(authority.clone())
172+
.path_and_query(path.clone())
173+
.build()
174+
.expect("Unable to build URI");
175+
176+
parts.uri = uri;
177+
Ok(Request::from_parts(parts, body))
178+
}
182179

183180
#[tokio::test]
184-
async fn next_event() -> Result<(), Error> {
181+
async fn test_next_event() -> Result<(), Error> {
185182
let (client, server) = crate::simulated::chan();
186183
let base = Uri::from_static("http://localhost:9001");
187184

lambda/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![deny(clippy::all, clippy::cargo)]
2-
#![warn(missing_docs, nonstandard_style, rust_2018_idioms)]
1+
#![deny(clippy::all)]
32

43
//! The official Rust runtime for AWS Lambda.
54
//!

0 commit comments

Comments
 (0)