Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dino-park-fence to Actix 4, Tokio 1 #79

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,943 changes: 1,301 additions & 642 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ default = []
localuserscope = ["dino_park_gate/localuserscope"]

[dependencies]
cis_client = { git = "https://github.com/mozilla-iam/cis_client-rust", branch = "0.8", version = "0.8", features = ["sync"]}
cis_profile = { git = "https://github.com/mozilla-iam/cis_profile-rust", branch = "0.5", version = "0.5", features = ["aws", "vendored", "graphql"] }
dino_park_gate = { git = "https://github.com/mozilla-iam/dino-park-gate", tag = "0.8.3", version = "0.8.3" }
dino_park_guard = { git = "https://github.com/mozilla-iam/dino-park-guard", tag = "0.3.1", version = "0.3.1" }
dino_park_trust = { git = "https://github.com/mozilla-iam/dino-park-trust", tag = "0.0.7", version = "0.0.7" }
actix-web = "3"
actix-rt = "1"
actix-http= "2"
cis_client = { git = "https://github.com/mozilla-iam/cis_client-rust", branch = "0.9", version = "0.9", features = ["sync"]}
cis_profile = { git = "https://github.com/mozilla-iam/cis_profile-rust", branch = "0.6", version = "0.6", features = ["aws", "vendored", "graphql"] }
dino_park_gate = { git = "https://github.com/mozilla-iam/dino-park-gate", tag = "0.9.4", version = "0.9.4" }
dino_park_guard = { git = "https://github.com/mozilla-iam/dino-park-guard", tag = "0.4.4", version = "0.4.4" }
dino_park_trust = { git = "https://github.com/mozilla-iam/dino-park-trust", tag = "0.1.0", version = "0.1.0" }
actix-web = "4"
actix-rt = "^2"
awc = "2.0.3"
cookie = "0.16"
juniper = "0.15"
juniper_actix = "0.2"
juniper_actix = "0.4"
futures = "0.3"
log = "0.4"
env_logger = "0.8"
Expand All @@ -34,8 +35,7 @@ failure = "0.1"
url = "2.1"
prometheus = { version = "0.11", default-features = false }
time = "0.2"
# juniper_codegen breaks with syn 1.0.60 :/
syn = "= 1.0.59"
syn = "= 1.0.98"

[dev-dependencies]
tokio = { version = "0.3", features = ["full"] }
tokio = { version = "1", features = ["full"] }
4 changes: 2 additions & 2 deletions src/graphql_api/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ pub fn graphql_app<T: AsyncCisClientTrait + Clone + Send + Sync + 'static>(
);

web::scope("/graphql")
.data(GraphQlState {
.app_data(GraphQlState {
schema: Arc::new(schema),
})
.data(web::JsonConfig::default().limit(1_048_576))
.app_data(web::JsonConfig::default().limit(1_048_576))
.service(web::resource("").route(web::post().to(graphql::<T>)))
.service(web::resource("/graphiql").route(web::get().to(graphiql)))
}
21 changes: 12 additions & 9 deletions src/graphql_api/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ use crate::graphql_api::error::field_error;
use crate::graphql_api::input::InputProfile;
use crate::metrics::Metrics;
use crate::settings::DinoParkServices;
use cis_client::error::ProfileError;
use cis_client::error::{CisClientError, ProfileError};
use cis_client::getby::GetBy;
use cis_client::AsyncCisClientTrait;
use cis_profile::schema::Display;
use cis_profile::schema::Profile;
use dino_park_gate::scope::ScopeAndUser;
use dino_park_trust::Trust;
use failure::Error;
use juniper::FieldError;
use juniper::FieldResult;
use juniper::RootNode;
Expand All @@ -33,7 +32,7 @@ async fn get_profile(
cis_client: &impl AsyncCisClientTrait,
by: &GetBy,
filter: &str,
) -> Result<Profile, Error> {
) -> Result<Profile, CisClientError> {
cis_client.get_user_by(&id, by, Some(filter)).await
}

Expand Down Expand Up @@ -147,12 +146,16 @@ impl<T: AsyncCisClientTrait + Send + Sync> Query<T> {
.await
{
Ok(p) => Ok(p),
Err(e) if self_query => match e.downcast::<ProfileError>() {
Ok(ProfileError::ProfileDoesNotExist) => Err(FieldError::new(
"wait_for_profile",
graphql_value!({"warning": "profile does not exist yet"}),
)),
Err(e) => Err(e.into()),
// if there was an error and self_query is none
// enter nested match on enum error type CisClientError
Err(e) if self_query => match e {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

downcast no longer existed on e and we are returning a CisClientError instead of a ProfileError. ProfileError is a variant of the CisClientError enum and ProfileDoesNotExist is a variant of the ProfileError enum. This seems to be functionally equivalent of what was here before.

CisClientError::ProfileError(ProfileError::ProfileDoesNotExist) => {
Err(FieldError::new(
"wait_for_profile",
graphql_value!({"warning": "profile does not exist yet"}),
))
}
e => Err(e.into()),
},
Err(e) => Err(e.into()),
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::search::app::search_app;
use crate::session::app::session_app;

use actix_web::middleware::Logger;
use actix_web::web;
use actix_web::web::{self, Data};
use actix_web::App;
use actix_web::HttpServer;
use cis_client::CisClient;
Expand Down Expand Up @@ -53,7 +53,7 @@ async fn main() -> std::io::Result<()> {
let scope_middleware = ScopeAndUserAuth::new(provider.clone()).public();
App::new()
.wrap(Logger::default().exclude("/healthz"))
.data(m.clone())
.app_data(Data::new(m.clone()))
.service(
web::scope("/api/v4/")
.wrap(scope_middleware)
Expand Down
6 changes: 3 additions & 3 deletions src/orgchart/app.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::error::ApiError;
use crate::proxy::proxy;
use crate::settings::Orgchart;
use actix_web::client::Client;
use actix_web::dev::HttpServiceFactory;
use actix_web::web;
use actix_web::web::Data;
use actix_web::web::Path;
use actix_web::HttpResponse;
use awc::Client;
use dino_park_guard::guard;
use percent_encoding::utf8_percent_encode;
use percent_encoding::AsciiSet;
Expand Down Expand Up @@ -72,8 +72,8 @@ async fn handle_related(
pub fn orgchart_app(settings: &Orgchart) -> impl HttpServiceFactory {
let client = Client::default();
web::scope("/orgchart")
.data(settings.clone())
.data(client)
.app_data(settings.clone())
.app_data(client)
.service(web::resource("").route(web::get().to(handle_full)))
.service(web::resource("/related/{username}").route(web::get().to(handle_related)))
.service(web::resource("/trace/{username}").route(web::get().to(handle_trace)))
Expand Down
2 changes: 1 addition & 1 deletion src/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::ApiError;
use actix_web::client::Client;
use actix_web::HttpResponse;
use awc::Client;
use log::error;
use log::info;
use serde_json::Value;
Expand Down
6 changes: 3 additions & 3 deletions src/search/app.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::error::ApiError;
use crate::proxy::proxy;
use crate::settings::Search;
use actix_web::client::Client;
use actix_web::dev::HttpServiceFactory;
use actix_web::web;
use actix_web::web::Data;
use actix_web::web::Query;
use actix_web::HttpResponse;
use awc::Client;
use dino_park_gate::scope::ScopeAndUser;
use dino_park_guard::guard;
use url::Url;
Expand Down Expand Up @@ -43,7 +43,7 @@ async fn handle_simple(
pub fn search_app(settings: &Search) -> impl HttpServiceFactory {
let client = Client::default();
web::scope("/search")
.data(client)
.data(settings.clone())
.app_data(client)
.app_data(settings.clone())
.service(web::resource("/simple/").route(web::get().to(handle_simple)))
}
10 changes: 5 additions & 5 deletions src/session/app.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use actix_http::cookie::SameSite;
use actix_web::dev::HttpServiceFactory;
use actix_web::http;
use actix_web::http::Cookie;
use actix_web::web;
use actix_web::HttpResponse;
use actix_web::Responder;
use time::Duration;
use cookie::Cookie;
use cookie::SameSite;

const KEEP_LOGGED_IN_COOKIE_NAME: &str = "pmo-kli";
const LOGIN_PATH: &str = "/";
const LOGOUT_PATH: &str = "/oauth/logout?redirect=/";

const FIVE_YEARS_IN_SECS: Duration = Duration::new(5 * 365 * 24 * 60 * 60, 0);
const FIVE_YEARS_IN_SECS: cookie::time::Duration =
cookie::time::Duration::new(5 * 365 * 24 * 60 * 60, 0);

enum KeepLoggedIn {
No,
Expand Down Expand Up @@ -42,7 +42,7 @@ fn set_cookie_and_redirect(
.max_age(FIVE_YEARS_IN_SECS)
.finish(),
)
.header(http::header::LOCATION, location)
.append_header((http::header::LOCATION, location.to_string()))
.finish()
}

Expand Down