Skip to content

Commit

Permalink
Merge pull request #22 from unsplash/maintenance-feb24
Browse files Browse the repository at this point in the history
Maintenance
  • Loading branch information
samhh authored Feb 16, 2024
2 parents 8a6aabb + 2ce1022 commit 498224d
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 130 deletions.
415 changes: 311 additions & 104 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ edition = "2021"

[dependencies]
# Data
regex = "1.8"
regex = "1.10"
serde = { version = "1.0", features = ["derive"] }
serde_with = "3.0"
serde_with = "3.6"
serde_json = "1.0"
serde_urlencoded = "0.7"
url = { version = "2.3", features = ["serde"] }
url = { version = "2.5", features = ["serde"] }

# Crypto
base64 = "0.21"
sha2 = "0.10"
hmac = "0.12"

# Async
tokio = { version = "1.28", features = ["macros", "rt-multi-thread"] }
tokio = { version = "1.36", features = ["macros", "rt-multi-thread"] }

# Environment
dotenvy = "0.15"
Expand All @@ -28,16 +28,17 @@ tracing = "0.1"
tracing-subscriber = "0.3"

# Server
hyper = "0.14"
hyper = "1.1"
tower = "0.4"
tower-http = { version = "0.4", features = ["trace", "validate-request", "auth"] }
axum = { version = "0.6", features = ["headers", "macros"] }
tower-http = { version = "0.5", features = ["trace", "validate-request", "auth"] }
axum = { version = "0.7", features = ["macros"] }
axum-extra = { version = "0.9", features = ["typed-header"] }

# Client
reqwest = { version = "0.11", features = ["json"] }

[dev-dependencies]
# Testing
quickcheck = "1.0"
mockito = "1.0"
mockito = "1.2"
mock_instant = "0.3"
12 changes: 6 additions & 6 deletions flake.lock

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

4 changes: 2 additions & 2 deletions src/heroku/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use super::{auth::*, webhook::*, Platform};
use crate::{router::Deps, slack::router::handle_slack_err};
use axum::{
extract::{self, State},
headers,
http::{header::HeaderMap, StatusCode},
response::IntoResponse,
routing::post,
Router, TypedHeader,
Router,
};
use axum_extra::{headers, TypedHeader};
use hyper::body::Bytes;
use tracing::{info, warn};

Expand Down
16 changes: 11 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use heroku::HerokuSecret;
use router::Deps;
use slack::{api::API_BASE, SlackAccessToken, SlackClient};
use std::{env, net::SocketAddr, sync::Arc};
use tokio::sync::{oneshot, Mutex};
use tokio::{
net::TcpListener,
sync::{oneshot, Mutex},
};
use tracing::{info, warn};

mod de;
Expand Down Expand Up @@ -42,7 +45,7 @@ async fn main() {

let slack_token = env::var("SLACK_TOKEN")
.map(SlackAccessToken)
.expect("No $HEROKU_SECRET environment variable found");
.expect("No $SLACK_TOKEN environment variable found");

let addr = SocketAddr::from(([0, 0, 0, 0], port));

Expand Down Expand Up @@ -70,10 +73,12 @@ async fn server(addr: SocketAddr, slack_token: SlackAccessToken, rx: oneshot::Re
heroku_secret,
};

let listener = TcpListener::bind(&addr)
.await
.unwrap_or_else(|_| panic!("Failed to bind to {}", addr));
info!("Listening on {}", addr.to_string());

axum::Server::bind(&addr)
.serve(router::new(deps).into_make_service())
axum::serve(listener, router::new(deps).into_make_service())
.with_graceful_shutdown(async {
rx.await.ok();
})
Expand Down Expand Up @@ -112,8 +117,9 @@ fn print_in_color() -> bool {

#[cfg(test)]
mod tests {
use reqwest::StatusCode;

use super::*;
use axum::http::StatusCode;

#[tokio::test]
async fn test_real_health_api() {
Expand Down
4 changes: 2 additions & 2 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ mod tests {
mockito::Server::new_async().await
}

async fn plaintext_body(body: axum::body::BoxBody) -> String {
let bytes = hyper::body::to_bytes(body).await.unwrap();
async fn plaintext_body(body: axum::body::Body) -> String {
let bytes = axum::body::to_bytes(body, usize::MAX).await.unwrap();
String::from_utf8(bytes.to_vec()).unwrap()
}

Expand Down
1 change: 0 additions & 1 deletion src/slack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ pub mod router;

pub use api::SlackClient;
pub use auth::SlackAccessToken;
pub use channel::ChannelName;
pub use error::SlackError;
pub use message::Message;
4 changes: 2 additions & 2 deletions src/slack/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use crate::{
};
use axum::{
extract::{self, State},
headers,
http::StatusCode,
response::IntoResponse,
routing::post,
Router, TypedHeader,
Router,
};
use axum_extra::{headers, TypedHeader};
use tower_http::validate_request::ValidateRequestHeaderLayer;
use tracing::error;

Expand Down

0 comments on commit 498224d

Please sign in to comment.