Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Make authz asynchronous (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
feymartynov committed Nov 12, 2019
1 parent f9fbaa0 commit 5bd5baa
Show file tree
Hide file tree
Showing 11 changed files with 710 additions and 194 deletions.
858 changes: 684 additions & 174 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 3 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,12 @@ chrono = { version = "0.4", features = ["serde"] }
openssl = "*"
diesel = { version = "1.4", features = ["postgres", "uuid", "chrono", "serde_json", "r2d2"] }
diesel-derive-enum = { version = "0.4", features = ["postgres"] }
futures = { version = "0.3", features = ["thread-pool"] }
futures-channel = "0.3"
svc-agent = { version = "0.9", features = ["diesel"] }
svc-authz = "0.5"
svc-authz = "0.9"
svc-authn = { version = "0.5", features = ["jose", "diesel"] }
svc-error = { version = "0.1", features = ["diesel", "r2d2", "svc-agent", "svc-authn", "svc-authz", "sentry-extension"] }

[dev-dependencies]
rand = "0.7"

[dependencies.futures]
version = "=0.3.0-alpha.18"
package = "futures-preview"
features = ["compat"]

[dependencies.futures-channel]
version = "=0.3.0-alpha.18"
package = "futures-channel-preview"

[patch.crates-io]
# Use a branch with synchronous authz until 1.39 becomes stable (07.11.2019)
svc-authz = { git = "https://github.com/netology-group/svc-authz-rs", branch = "sync" }
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## -----------------------------------------------------------------------------
## Build
## -----------------------------------------------------------------------------
FROM clux/muslrust:nightly-2019-09-05 as build-stage
FROM clux/muslrust:nightly-2019-11-05 as build-stage

WORKDIR "/build"
COPY . .
Expand Down
1 change: 1 addition & 0 deletions src/app/endpoint/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl State {
vec!["rooms", &room_id, "agents"],
"list",
)
.await
.map_err(|err| SvcError::from(err))?
};

Expand Down
11 changes: 10 additions & 1 deletion src/app/endpoint/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl State {
vec!["rooms"],
"create",
)
.await
.map_err(|err| SvcError::from(err))?;

// Creating a Room
Expand Down Expand Up @@ -153,6 +154,7 @@ impl State {
vec!["rooms", &room_id],
"read",
)
.await
.map_err(|err| SvcError::from(err))?;

shared::respond(&inreq, object, None, start_timestamp, authz_time)
Expand Down Expand Up @@ -188,6 +190,7 @@ impl State {
vec!["rooms", &room_id],
"update",
)
.await
.map_err(|err| SvcError::from(err))?;

let object = {
Expand Down Expand Up @@ -234,6 +237,7 @@ impl State {
vec!["rooms", &room_id],
"delete",
)
.await
.map_err(|err| SvcError::from(err))?;

{
Expand Down Expand Up @@ -278,6 +282,7 @@ impl State {
vec!["rooms", &room_id, "events"],
"subscribe",
)
.await
.map_err(|err| SvcError::from(err))?;

agent::InsertQuery::new(inreq.properties().as_agent_id(), object.id()).execute(&conn)?;
Expand Down Expand Up @@ -978,7 +983,11 @@ mod test {
let payload = json!({"id": room.id()});
let state = State::new(authz.into(), db.connection_pool().clone());
let request: EnterRequest = agent.build_request("room.enter", &payload).unwrap();
state.enter(request, Utc::now()).await.into_result().unwrap();
state
.enter(request, Utc::now())
.await
.into_result()
.unwrap();

// Assert agent is in `in_progress` state in the DB.
let conn = db.connection_pool().get().unwrap();
Expand Down
4 changes: 4 additions & 0 deletions src/app/endpoint/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl State {
vec!["rooms", &room_id, "rtcs"],
"create",
)
.await
.map_err(|err| SvcError::from(err))?
};

Expand Down Expand Up @@ -163,6 +164,7 @@ impl State {
vec!["rooms", &room_id, "rtcs", &rtc_id],
"read",
)
.await
.map_err(|err| SvcError::from(err))?
};

Expand Down Expand Up @@ -229,6 +231,7 @@ impl State {
vec!["rooms", &room_id, "rtcs", &rtc_id],
"read",
)
.await
.map_err(|err| SvcError::from(err))?
};

Expand Down Expand Up @@ -281,6 +284,7 @@ impl State {
vec!["rooms", &room_id, "rtcs"],
"list",
)
.await
.map_err(|err| SvcError::from(err))?
};

Expand Down
1 change: 1 addition & 0 deletions src/app/endpoint/rtc_signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl State {
vec!["rooms", &room_id, "rtcs", &rtc_id],
action,
)
.await
.map_err(|err| SvcError::from(err))
}
}
Expand Down
1 change: 1 addition & 0 deletions src/app/endpoint/rtc_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl State {
vec!["rooms", &room_id, "rtcs"],
"list",
)
.await
.map_err(|err| SvcError::from(err))?
};

Expand Down
1 change: 1 addition & 0 deletions src/app/endpoint/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl State {
vec!["system"],
"update",
)
.await
.map_err(|err| SvcError::from(err))?;

// TODO: Update 'finished_without_recordings' in order to return (backend,room,rtc)
Expand Down
4 changes: 2 additions & 2 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub(crate) async fn run(db: &ConnectionPool) -> Result<(), Error> {
});

// Authz
let authz = svc_authz::ClientMap::new(&config.id, config.authz)
let authz = svc_authz::ClientMap::new(&config.id, None, config.authz)
.expect("Error converting authz config to clients");

// Sentry
Expand Down Expand Up @@ -127,7 +127,7 @@ pub(crate) async fn run(db: &ConnectionPool) -> Result<(), Error> {
.expect("Error subscribing to everyone's output messages");

// Thread Pool
let mut threadpool = ThreadPoolBuilder::new().create()?;
let threadpool = ThreadPoolBuilder::new().create()?;

while let Some(message) = mq_rx.next().await {
let start_timestamp = Utc::now();
Expand Down
4 changes: 2 additions & 2 deletions src/test_helpers/authz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Into<ClientMap> for TestAuthz {
config_map.insert(self.audience.to_owned(), Config::LocalWhitelist(config));

let account_id = AccountId::new("conference", &self.audience);
ClientMap::new(&account_id, config_map).expect("Failed to build authz")
ClientMap::new(&account_id, None, config_map).expect("Failed to build authz")
}
}

Expand All @@ -44,5 +44,5 @@ pub(crate) fn no_authz(audience: &str) -> ClientMap {
authz_config_map.insert(audience.to_owned(), authz_none_config);

let account_id = AccountId::new("conference", audience);
svc_authz::ClientMap::new(&account_id, authz_config_map).expect("Failed to build authz")
svc_authz::ClientMap::new(&account_id, None, authz_config_map).expect("Failed to build authz")
}

0 comments on commit 5bd5baa

Please sign in to comment.