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

Move config sync.{user,password} to opencast.* #1296

Merged
Merged
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
4 changes: 2 additions & 2 deletions .deployment/templates/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ file = "/var/log/tobira/{{ id }}-${cmd}.log"

[opencast]
host = "https://tobira-test-oc.ethz.ch"

[sync]
user = "admin"
password = "{{ opencast_admin_password }}"

[sync]
poll_period = "1min"
interpret_eth_passwords = true

Expand Down
18 changes: 18 additions & 0 deletions backend/src/config/opencast.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{str::FromStr, fmt};

use hyper::Uri;
use base64::Engine as _;
use secrecy::{ExposeSecret as _, Secret};
use serde::Deserialize;

use crate::{
Expand Down Expand Up @@ -49,6 +51,15 @@ pub(crate) struct OpencastConfig {
/// be trusted.
#[config(default = [])]
pub(crate) other_hosts: Vec<HttpHost>,

/// Username of the user used to communicate with Opencast for data syncing
/// and external API authentication.
/// This user has to have access to all events and series. Currently, that
/// user has to be admin.
pub user: String,

/// Password of the user used to communicate with Opencast.
password: Secret<String>,
}

impl OpencastConfig {
Expand Down Expand Up @@ -111,6 +122,13 @@ impl OpencastConfig {
})
}

pub(crate) fn basic_auth_header(&self) -> Secret<String> {
let credentials = format!("{}:{}", self.user, self.password.expose_secret());
let encoded_credentials = base64::engine::general_purpose::STANDARD.encode(credentials);
let auth_header = format!("Basic {}", encoded_credentials);
Secret::new(auth_header)
}

fn unwrap_host(&self) -> &HttpHost {
self.host.as_ref().expect("Neither 'opencast.host' nor override host set!")
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/sync/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl OcClient {
http_client: crate::util::http_client()?,
sync_node: config.opencast.sync_node().clone(),
external_api_node: config.opencast.external_api_node().clone(),
auth_header: config.sync.basic_auth_header(),
username: config.sync.user.clone(),
auth_header: config.opencast.basic_auth_header(),
username: config.opencast.user.clone(),
})
}

Expand Down
19 changes: 0 additions & 19 deletions backend/src/sync/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use base64::Engine as _;
use secrecy::{ExposeSecret as _, Secret};
use core::fmt;
use std::time::Duration;

Expand Down Expand Up @@ -41,14 +39,6 @@ pub(crate) async fn check_compatibility(client: &OcClient) -> Result<()> {

#[derive(Debug, confique::Config)]
pub(crate) struct SyncConfig {
/// Username of the user used to communicate with Opencast for data syncing.
/// This user has to have access to all events and series. Currently, that
/// user has to be admin.
user: String,

/// Password of the user used to communicate with Opencast.
password: Secret<String>,

/// A rough estimate of how many items (events & series) are transferred in
/// each HTTP request while harvesting (syncing) with the Opencast
/// instance.
Expand Down Expand Up @@ -84,15 +74,6 @@ pub(crate) struct SyncConfig {
concurrent_download_tasks: u8,
}

impl SyncConfig {
pub(crate) fn basic_auth_header(&self) -> Secret<String> {
let credentials = format!("{}:{}", self.user, self.password.expose_secret());
let encoded_credentials = base64::engine::general_purpose::STANDARD.encode(credentials);
let auth_header = format!("Basic {}", encoded_credentials);
Secret::new(auth_header)
}
}

/// Version of the Tobira-module API in Opencast.
struct ApiVersion {
major: u32,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/sync/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl Context {

let mut headers = header::HeaderMap::new();
let mut header_value = header::HeaderValue::try_from(
config.sync.basic_auth_header().expose_secret()
config.opencast.basic_auth_header().expose_secret()
).unwrap();
header_value.set_sensitive(true);
headers.insert(header::AUTHORIZATION, header_value);
Expand Down
7 changes: 4 additions & 3 deletions docs/docs/setup/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,8 @@
# Default value: []
#other_hosts = []


[sync]
# Username of the user used to communicate with Opencast for data syncing.
# Username of the user used to communicate with Opencast for data syncing
# and external API authentication.
# This user has to have access to all events and series. Currently, that
# user has to be admin.
#
Expand All @@ -454,6 +453,8 @@
# Required! This value must be specified.
#password =


[sync]
# A rough estimate of how many items (events & series) are transferred in
# each HTTP request while harvesting (syncing) with the Opencast
# instance.
Expand Down
2 changes: 0 additions & 2 deletions frontend/tests/util/isolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ const tobiraConfig = ({ index, port, dbName, rootPath }: {

[opencast]
host = "https://dummy.invalid" # Not used in UI tests

[sync]
user = "admin"
password = "opencast"

Expand Down
4 changes: 2 additions & 2 deletions util/dev-config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ secret_key = "jwt-key.pem"

[opencast]
host = "http://localhost:8081"

[sync]
user = "admin"
password = "opencast"

[sync]
preferred_harvest_size = 3
interpret_eth_passwords = true

Expand Down
Loading