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

Commit

Permalink
Change authz object for agent writer config (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
feymartynov committed May 20, 2021
1 parent b0fb07f commit f94be0c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 0 additions & 2 deletions docs/src/authz.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ object / action | create | read | update | list | subs
----------------------------------------- | ------ | ---- | ------ | ---- | ---------
["rooms"] | + | | | + |
["rooms", ROOM_ID] | | + | + | |
["rooms", ROOM_ID, "agents"] | | | + | + |
["rooms", ROOM_ID, "agents", AGENT_ID] | | + | | |
["rooms", ROOM_ID, "rtcs"] | + | | | + |
["rooms", ROOM_ID, "rtcs", RTC_ID] | | + | + | |
["rooms", ROOM_ID, "events"] | | | | | +
27 changes: 18 additions & 9 deletions src/app/endpoint/agent_writer_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,22 @@ impl RequestHandler for UpdateHandler {
};

// Authorize agent writer config updating on the tenant.
let room_id = room.id().to_string();
let object = vec!["rooms", &room_id, "agents"];
let is_only_owned_config =
payload.configs.len() == 1 && &payload.configs[0].agent_id == reqp.as_agent_id();

let authz_time = context
.authz()
.authorize(room.audience(), reqp, object, "update")
.await?;
let maybe_authz_time = if is_only_owned_config {
None
} else {
let room_id = room.id().to_string();
let object = vec!["rooms", &room_id];

let authz_time = context
.authz()
.authorize(room.audience(), reqp, object, "update")
.await?;

Some(authz_time)
};

let conn = context.get_conn()?;

Expand Down Expand Up @@ -195,7 +204,7 @@ impl RequestHandler for UpdateHandler {
state.clone(),
reqp,
context.start_timestamp(),
Some(authz_time),
maybe_authz_time,
);

let notification = helpers::build_notification(
Expand Down Expand Up @@ -224,7 +233,7 @@ impl RequestHandler for UpdateHandler {
&backend,
&rtc_writer_configs_with_rtcs,
context.start_timestamp(),
authz_time,
maybe_authz_time,
)
.or_else(|err| Err(err).error(AppErrorKind::MessageBuildingFailed))?;

Expand Down Expand Up @@ -352,7 +361,7 @@ mod tests {

// Allow agent to update agent_writer_config.
let room_id = room.id().to_string();
let object = vec!["rooms", &room_id, "agents"];
let object = vec!["rooms", &room_id];
authz.allow(agent1.account_id(), object, "update");

// Make agent_writer_config.update request.
Expand Down
7 changes: 5 additions & 2 deletions src/backend/janus/transactions/update_agent_writer_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ impl Client {
backend: &JanusBackend,
rtc_writer_configs_with_rtcs: &[(RtcWriterConfig, Rtc)],
start_timestamp: DateTime<Utc>,
authz_time: Duration,
maybe_authz_time: Option<Duration>,
) -> Result<OutgoingMessage<MessageRequest>> {
let to = backend.id();
let mut short_term_timing = ShortTermTimingProperties::until_now(start_timestamp);
short_term_timing.set_authorization_time(authz_time);

if let Some(authz_time) = maybe_authz_time {
short_term_timing.set_authorization_time(authz_time);
}

let props = reqp.to_request(
METHOD,
Expand Down

0 comments on commit f94be0c

Please sign in to comment.