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

Commit

Permalink
Separate upload configs for sharing policies
Browse files Browse the repository at this point in the history
  • Loading branch information
feymartynov committed Apr 16, 2021
1 parent b61d33c commit 611c384
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
10 changes: 7 additions & 3 deletions App.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ default_timeout = 5
stream_upload_timeout = 600
transaction_watchdog_check_period = 1

[upload."example.net"]
backend = "EXAMPLE"
bucket = "origin.webinars.example.net"
[upload.shared."example.net"]
backend = "yandex"
bucket = "origin.webinar.example.net"

[upload.owned."example.net"]
backend = "yandex"
bucket = "origin.minigroup.example.net"

[metrics.http]
bind_address = "0.0.0.0:8087"
16 changes: 13 additions & 3 deletions src/app/endpoint/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::config::UploadConfig;
use crate::db;
use crate::db::recording::{Object as Recording, Status as RecordingStatus};
use crate::db::room::Object as Room;
use crate::db::rtc::SharingPolicy;

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -191,9 +192,18 @@ fn upload_config<'a, C: Context>(
context: &'a C,
room: &Room,
) -> StdResult<&'a UploadConfig, AppError> {
context
.config()
.upload
let configs = &context.config().upload;

let config = match room.rtc_sharing_policy() {
SharingPolicy::Shared => &configs.shared,
SharingPolicy::Owned => &configs.owned,
SharingPolicy::None => {
let err = anyhow!("Uploading not available for rooms with 'none' RTC sharing policy");
return Err(err).error(AppErrorKind::NotImplemented);
}
};

config
.get(room.audience())
.ok_or_else(|| anyhow!("Missing upload configuration for the room's audience"))
.error(AppErrorKind::ConfigKeyMissing)
Expand Down
8 changes: 7 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) struct Config {
pub(crate) mqtt: AgentConfig,
pub(crate) sentry: Option<SentryConfig>,
pub(crate) backend: BackendConfig,
pub(crate) upload: UploadConfigMap,
pub(crate) upload: UploadConfigs,
#[serde(default)]
pub(crate) telemetry: TelemetryConfig,
#[serde(default)]
Expand Down Expand Up @@ -47,6 +47,12 @@ pub(crate) struct BackendConfig {
pub(crate) transaction_watchdog_check_period: u64,
}

#[derive(Clone, Debug, Deserialize)]
pub(crate) struct UploadConfigs {
pub(crate) shared: UploadConfigMap,
pub(crate) owned: UploadConfigMap,
}

pub(crate) type UploadConfigMap = HashMap<String, UploadConfig>;

#[derive(Clone, Debug, Deserialize)]
Expand Down
14 changes: 11 additions & 3 deletions src/test_helpers/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@ fn build_config() -> Config {
"transaction_watchdog_check_period": 1,
},
"upload": {
USR_AUDIENCE: {
"backend": "EXAMPLE",
"bucket": format!("origin.webinar.{}", USR_AUDIENCE),
"shared": {
USR_AUDIENCE: {
"backend": "EXAMPLE",
"bucket": format!("origin.webinar.{}", USR_AUDIENCE),
}
},
"owned": {
USR_AUDIENCE: {
"backend": "EXAMPLE",
"bucket": format!("origin.minigroup.{}", USR_AUDIENCE),
}
}
}
});
Expand Down

0 comments on commit 611c384

Please sign in to comment.