-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup_page.js
84 lines (73 loc) · 2.62 KB
/
setup_page.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"use strict";
import * as Splunk from './splunk_helpers.js';
import * as Config from './setup_configuration.js';
import * as StoragePasswords from './storage_passwords.js';
const app_name = "bitwarden_event_logs_beta";
export async function getIndexes(splunk_js_sdk) {
// Create the Splunk JS SDK Service object
// Use a wildcard namespace to get all the indexes
const splunk_js_sdk_service = Config.create_splunk_js_sdk_service(
splunk_js_sdk,
{
owner: "-",
app: "-",
sharing: "app",
}
);
const indexes = await Config.get_indexes(splunk_js_sdk_service);
return indexes;
}
export async function perform(splunk_js_sdk, setup_options) {
var application_name_space = {
owner: "nobody",
app: app_name,
sharing: "app",
};
try {
// Setup
const service = Config.create_splunk_js_sdk_service(
splunk_js_sdk,
application_name_space,
);
let { clientId, clientSecret, index, serverUrl, startDate, ...properties } = setup_options;
// Store secrets
await StoragePasswords.write_secret(
service,
app_name + "_realm",
"api_key",
clientId + "_" + clientSecret
);
// Update inputs.conf
await Splunk.update_configuration_file(
service,
"inputs",
"script://$SPLUNK_HOME/etc/apps/" + app_name + "/bin/bitwarden_event_logs.py",
{ index: index },
);
if (serverUrl.startsWith("http://")) {
throw new URIError("URLs starting with 'http://' is considered insecure and not allowed in Splunk. " +
"Please use 'https://' instead.");
}
// Update script.conf
const isBitwardenCloud = serverUrl === "https://bitwarden.com" || serverUrl === "bitwarden.com";
const apiUrl = isBitwardenCloud ? "https://api.bitwarden.com" : serverUrl + "/api/";
const identityUrl = isBitwardenCloud ? "https://identity.bitwarden.com" : serverUrl + "/identity/";
await Splunk.update_configuration_file(
service,
"script",
"config",
{
apiUrl: apiUrl,
identityUrl: identityUrl,
startDate: startDate
},
);
// Complete setup
await Config.complete_setup(service);
await Config.reload_splunk_app(service, app_name);
Config.redirect_to_splunk_app_homepage(app_name);
} catch (error) {
console.log('Error: ', error);
alert('Error: ' + error);
}
}