-
Notifications
You must be signed in to change notification settings - Fork 215
/
authorization.js
57 lines (51 loc) · 2.06 KB
/
authorization.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
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
import * as API from '../api.js';
import * as Utils from '../utils.js';
/* eslint-disable prefer-const */
/* eslint-disable require-jsdoc */
import * as Environments from './environments.js';
let dom = {
bearer: null,
userName: null,
password: null,
devOpsUserName: null,
devOpsPassword: null,
collapseConnections: null,
};
export function ready() {
Utils.getAllElementsById(dom);
document.getElementById('authorizeBearer').onclick = () => {
Environments.current().useBasicAuth = false;
Environments.current().bearer = dom.bearer.value;
Environments.environmentsJsonChanged('authorization');
};
document.getElementById('authorizeBasic').onclick = () => {
Environments.current().useBasicAuth = true;
Environments.current().usernamePassword = dom.userName.value + ':' + dom.password.value;
Environments.current().usernamePasswordDevOps = dom.devOpsUserName.value + ':' + dom.devOpsPassword.value;
Environments.environmentsJsonChanged('authorization');
};
};
export function onEnvironmentChanged() {
let usernamePassword = Environments.current().usernamePassword ? Environments.current().usernamePassword : ':';
dom.userName.value = usernamePassword.split(':')[0];
dom.password.value = usernamePassword.split(':')[1];
usernamePassword = Environments.current().usernamePasswordDevOps ?
Environments.current().usernamePasswordDevOps :
':';
dom.devOpsUserName.value = usernamePassword.split(':')[0];
dom.devOpsPassword.value = usernamePassword.split(':')[1];
dom.bearer.value = Environments.current().bearer ? Environments.current().bearer : '';
API.setAuthHeader(dom.collapseConnections.classList.contains('show'));
};