Skip to content

Commit cb7994d

Browse files
committed
Lambda crate update + reformatting
1 parent dad66bb commit cb7994d

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

rustfmt.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
max_width = 120
2+
attr_fn_like_width = 90
3+
wrap_comments = false
4+
fn_call_width = 90

src/config.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ impl Config {
4141
.trim()
4242
.to_string();
4343

44-
let s3_region = Region::from_str(&s3_region)
45-
.expect("Invalid S3 Region value. Must look like `us-east-1`.");
44+
let s3_region = Region::from_str(&s3_region).expect("Invalid S3 Region value. Must look like `us-east-1`.");
4645

4746
Config {
4847
s3_bucket: std::env::var(S3_BUCKET_ENV)
@@ -70,8 +69,7 @@ impl Config {
7069
fn generate_s3_client(s3_region: Region) -> S3Client {
7170
let https_connector = HttpsConnector::with_native_roots();
7271

73-
let cred_prov =
74-
DefaultCredentialsProvider::new().expect("Cannot unwrap DefaultCredentialsProvider");
72+
let cred_prov = DefaultCredentialsProvider::new().expect("Cannot unwrap DefaultCredentialsProvider");
7573

7674
let mut builder = hyper::Client::builder();
7775
builder.pool_idle_timeout(Duration::from_secs(15));

src/handler.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use crate::config::Config;
12
use crate::s3;
2-
use crate::{config::Config, Error};
33
use base64::decode;
4-
use lambda_runtime::Context;
4+
use lambda_runtime::{Context, Error};
55
use ring::signature;
66
use serde::{Deserialize, Serialize};
77
use serde_json::Value;
@@ -51,10 +51,7 @@ pub(crate) async fn my_handler(event: Value, ctx: Context) -> Result<Value, Erro
5151
// parse the request
5252
let api_request = match serde_json::from_value::<ApiGatewayRequest>(event.clone()) {
5353
Err(e) => {
54-
error!(
55-
"Failed to deser APIGW request due to {}. Request: {}",
56-
e, event
57-
);
54+
error!("Failed to deser APIGW request due to {}. Request: {}", e, event);
5855
return gw_response(Some(ERROR_500_MSG.to_owned()), 500);
5956
}
6057
Ok(v) => v,
@@ -63,9 +60,7 @@ pub(crate) async fn my_handler(event: Value, ctx: Context) -> Result<Value, Erro
6360
info!("Report from IP: {:?}", api_request.headers.x_forwarded_for);
6461

6562
// these 2 headers are required no matter what
66-
if api_request.headers.stackmuncher_key.is_none()
67-
|| api_request.headers.stackmuncher_sig.is_none()
68-
{
63+
if api_request.headers.stackmuncher_key.is_none() || api_request.headers.stackmuncher_sig.is_none() {
6964
error!(
7065
"Missing a header. Key: {:?}, Sig: {:?}",
7166
api_request.headers.stackmuncher_key, api_request.headers.stackmuncher_sig
@@ -113,10 +108,7 @@ pub(crate) async fn my_handler(event: Value, ctx: Context) -> Result<Value, Erro
113108
let pub_key = match bs58::decode(pub_key_bs58.clone()).into_vec() {
114109
Ok(v) => v,
115110
Err(e) => {
116-
error!(
117-
"Failed to decode the stackmuncher_key from based58 due to: {}",
118-
e
119-
);
111+
error!("Failed to decode the stackmuncher_key from based58 due to: {}", e);
120112
return gw_response(Some(ERROR_500_MSG.to_owned()), 500);
121113
}
122114
};
@@ -132,10 +124,7 @@ pub(crate) async fn my_handler(event: Value, ctx: Context) -> Result<Value, Erro
132124
{
133125
Ok(v) => v,
134126
Err(e) => {
135-
error!(
136-
"Failed to decode the stackmuncher_key from based58 due to: {}",
137-
e
138-
);
127+
error!("Failed to decode the stackmuncher_key from based58 due to: {}", e);
139128
return gw_response(Some(ERROR_500_MSG.to_owned()), 500);
140129
}
141130
};

src/main.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#[cfg(not(debug_assertions))]
22
use lambda_runtime::handler_fn;
3+
use lambda_runtime::Error;
34

45
mod config;
56
mod handler;
67
mod s3;
78

8-
pub(crate) type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
9-
109
/// Boilerplate Lambda runtime code with conditional debug proxy
1110
#[tokio::main]
1211
async fn main() -> Result<(), Error> {
@@ -44,10 +43,12 @@ mod proxy {
4443
pub(crate) type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
4544

4645
// these are specific to a particular account - modify as needed for development
47-
// they should probably be taken out into a separate file
48-
const AWS_REGION: Region = Region::UsEast1;
49-
const REQUEST_QUEUE_URL: &str = "https://sqs.us-east-1.amazonaws.com/028534811986/STM_INBOX_LAMBDA_PROXY_REQ";
50-
const RESPONSE_QUEUE_URL: &str = " https://sqs.us-east-1.amazonaws.com/028534811986/STM_INBOX_LAMBDA_PROXY_RESP";
46+
// they should probably be taken out into a separate file
47+
const AWS_REGION: Region = Region::UsEast1;
48+
const REQUEST_QUEUE_URL: &str =
49+
"https://sqs.us-east-1.amazonaws.com/028534811986/STM_INBOX_LAMBDA_PROXY_REQ";
50+
const RESPONSE_QUEUE_URL: &str =
51+
"https://sqs.us-east-1.amazonaws.com/028534811986/STM_INBOX_LAMBDA_PROXY_RESP";
5152

5253
#[derive(Deserialize, Debug)]
5354
struct RequestPayload {

0 commit comments

Comments
 (0)