Skip to content

Commit dea7817

Browse files
Merge pull request #1040 from LukasKalbertodt/config-file-query-param
Allow server settings path to be set via `settingsFile` query parameter
2 parents 8a37618 + 5cfddf9 commit dea7817

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

CONFIGURATION.md

+26-14
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@
33
Opencast Studio can be configured in three different ways:
44

55
- the user can manually configure certain things on the settings page,
6-
- the server can provide a `settings.toml` (only applicable if you deploy Studio yourself or as part of your Opencast), and
7-
- configuration values can be given via GET parameters in the URL.
6+
- the server can provide a configuration file (by default, Studio uses
7+
`settings.toml`, but this can be changed via the query parameter
8+
`settingsFile`), and
9+
- configuration values can be given via query parameters in the URL.
810

911
Settings configured by the user have the lowest priority and are overwritten by
10-
both, `settings.toml` and GET parameters. GET parameters also override settings
11-
given in `settings.toml`. Additionally, on the settings page, values that are
12-
already preconfigured via `settings.toml` or a GET parameter are hidden from the
13-
user.
12+
both, the server config (e.g. `settings.toml`) and query parameters. Query
13+
parameters also override settings given in the server config (e.g. `settings.toml`).
14+
Additionally, on the settings page, values that are already preconfigured via
15+
`settings.toml` or a query parameter are hidden from the user.
1416

1517

1618
## Possible configuration values
1719

1820
The following settings are currently understood and respected by Studio. This
19-
code block shows the TOML configuration, but all values can be specified as GET
20-
parameter as well. See further below for information on that.
21+
code block shows the TOML configuration, but all values, except
22+
`return.allowedDomains`, can be specified as query parameter as well. See
23+
further below for information on that.
2124

2225
```toml
2326
# Configuration for Opencast Studio.
@@ -62,7 +65,7 @@ parameter as well. See further below for information on that.
6265
[upload]
6366
# The ID of the series which the recording is a part of. When uploading the
6467
# recording, it is automatically associated with that series. This value is
65-
# mostly passed as GET parameter; specifying it in the configuration file only
68+
# mostly passed as query parameter; specifying it in the configuration file only
6669
# makes sense if you want all the Studio uploads (that don't specify a series
6770
# otherwise) to be associated with one series.
6871
#seriesId = "979e0a0b-db25-47cd-869a-10daa1b3eb7a"
@@ -145,11 +148,11 @@ parameter as well. See further below for information on that.
145148
[return]
146149
# If this key is set, a "exit and back" button is shown in the last dialog
147150
# right above the "start a new recording" button. This button links to the
148-
# value of this key. Setting this value is usually done via GET parameters, as
151+
# value of this key. Setting this value is usually done via query parameters, as
149152
# a global configuration often does not make sense. You also probably want to
150153
# set `return.label`. Also see `return.allowedDomains`.
151154
#
152-
# Remember to URL-encode the URL if you set it as GET parameter, e.g.
155+
# Remember to URL-encode the URL if you set it as query parameter, e.g.
153156
# `https://foo.org/?a=1&b=2` would be `https%3A%2F%2Ffoo.org%2F%3Fa%3D1%26b%3D2`.
154157
# To be precise, Studio uses `URLSearchParams` to retrieve the values of GET
155158
# parameters.
@@ -196,17 +199,17 @@ customCSS = """
196199
Please also note that all settings related to video capture or recording should be treated carefully. Setting any of those means that you know more than the user's browser, which is unlikely: the browser has exact information about screen resolution, connected cameras, CPU usage and the like. As such, before setting any of those values for all of your users, make sure to test everything first!
197200

198201

199-
## Specifying settings via GET Parameters
202+
## Specifying settings via query parameters
200203

201-
GET parameters can simply be attached to the studio URL. Values specified this way overwrite values set by the user or by `settings.toml`. Example URL:
204+
Query parameters can simply be attached to the Studio URL. Values specified this way overwrite values set by the user or by `settings.toml`. Example URL:
202205

203206
```
204207
https://studio.opencast.org/?opencast.serverUrl=https://develop.opencast.org&upload.workflowId=studio-upload&upload.seriesId=3fe9ea49-a671-4d1e-9669-0c96ff0f8f79
205208
```
206209

207210
Note that each key is a "path" like `opencast.serverUrl`. The first part of that path is the "section" in the TOML file shown above (e.g. `[opencast]`).
208211

209-
You can also put the settings in TOML file, then encode that as a hex string and pass it with the `config=` GET parameter. This might help to avoid problems if URLs (and thus the GET parameters) are processed (e.g. by an LMS) in a way that modifies special characters. For example:
212+
You can also put the settings in a TOML file, then encode that as a hex string and pass it with the `config=` query parameter. This might help to avoid problems if URLs (and thus the query parameters) are processed (e.g. by an LMS) in a way that modifies special characters. For example:
210213

211214
- TOML string:
212215
```
@@ -226,6 +229,15 @@ You can encode your TOML as hex string with [this tool](https://onlineutf8tools.
226229

227230
Note that if `config=` is specified, all other parameters are ignored!
228231

232+
Finally, you can change the filename from which the server configuration is loaded by using `settingsFile`, e.g.:
233+
234+
```
235+
https://your-opencast.com/studio?settingsFile=foo.toml
236+
```
237+
238+
This file needs to live in the same directory as the `settings.toml` that would
239+
have been loaded otherwise.
240+
229241

230242
## Debugging/Help
231243

src/settings.tsx

+22-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { unreachable } from './util/err';
1111

1212
const LOCAL_STORAGE_KEY = 'ocStudioSettings';
1313
const CONTEXT_SETTINGS_FILE = 'settings.toml';
14+
const QUERY_PARAM_SETTINGS_PATH = 'settingsFile';
1415

1516
export const FORM_FIELD_HIDDEN = 'hidden';
1617
export const FORM_FIELD_OPTIONAL = 'optional';
@@ -143,8 +144,11 @@ export class SettingsManager {
143144
'from server settings file',
144145
);
145146

146-
// Get settings from URL query.
147+
// Get settings from URL query. We remove the key `settingsFile` as that is
148+
// just used for loading the context settings.
147149
const urlParams = new URLSearchParams(window.location.search);
150+
urlParams.delete(QUERY_PARAM_SETTINGS_PATH);
151+
148152
const encodedConfig = urlParams.get('config');
149153
if (encodedConfig) {
150154
// In this case, the GET parameter `config` is specified. We now expect a
@@ -232,7 +236,23 @@ export class SettingsManager {
232236
// Construct path to settings file. If the `REACT_APP_SETTINGS_PATH` is
233237
// given and starts with '/', it is interpreted as absolute path from the
234238
// server root.
235-
const settingsPath = process.env.REACT_APP_SETTINGS_PATH || CONTEXT_SETTINGS_FILE;
239+
let settingsPath = process.env.REACT_APP_SETTINGS_PATH || CONTEXT_SETTINGS_FILE;
240+
241+
// If a custom file is given via query parameter, change the settings path
242+
// appropriately.
243+
const urlParams = new URLSearchParams(window.location.search);
244+
const customFile = urlParams.get(QUERY_PARAM_SETTINGS_PATH);
245+
if (customFile) {
246+
if (customFile.includes('/') || customFile.includes('\\')) {
247+
console.warn(`You can only specify a filename via '${QUERY_PARAM_SETTINGS_PATH}', `
248+
+ 'not a path');
249+
} else {
250+
const segments = settingsPath.split('/');
251+
segments[segments.length - 1] = customFile;
252+
settingsPath = segments.join('/');
253+
}
254+
}
255+
236256
const base = settingsPath.startsWith('/') ? '' : basepath;
237257
const url = `${window.location.origin}${base}${settingsPath}`;
238258
let response: Response;

0 commit comments

Comments
 (0)