UNPKG

2.17 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const debug_1 = __importDefault(require("debug"));
7const error_1 = __importDefault(require("./error"));
8const server_1 = __importDefault(require("./server"));
9const debug = debug_1.default("NCEnvironment");
10class Environment {
11 constructor() {
12 this.url = process.env.NEXTCLOUD_URL;
13 this.userName = process.env.NEXTCLOUD_USERNAME;
14 this.password = process.env.NEXTCLOUD_PASSWORD;
15 if ((process.env.TEST_RECORDING_ACTIVE &&
16 (process.env.TEST_RECORDING_ACTIVE === "0" || process.env.TEST_RECORDING_ACTIVE === "false" || process.env.TEST_RECORDING_ACTIVE === "inactive")) ||
17 !process.env.TEST_RECORDING_ACTIVE) {
18 this.recordingActive = false;
19 }
20 else {
21 this.recordingActive = true;
22 }
23 }
24 /**
25 * returns the nextcloud credentials that is defined in the
26 * "user-provided" service section of the VCAP_SERVICES environment
27 * @param instanceName the name of the nextcloud user provided service instance
28 * @returns credentials from the VCAP_SERVICES environment (user provided service)
29 */
30 getServer() {
31 if (!this.url) {
32 throw new error_1.default("NCEnvironment: NEXTCLOUD_URL not defined in environment", "ERR_NEXTCLOUD_URL_NOT_DEFINED");
33 }
34 if (!this.userName) {
35 throw new error_1.default("NCEnvironment: NEXTCLOUD_USERNAME not defined in environment", "ERR_NEXTCLOUD_USERNAME_NOT_DEFINED");
36 }
37 if (!this.password) {
38 throw new error_1.default("NCEnvironment: NEXTCLOUD_PASSWORD not defined in environment", "ERR_NEXTCLOUD_PASSWORD_NOT_DEFINED");
39 }
40 return new server_1.default({
41 basicAuth: {
42 password: this.password,
43 username: this.userName,
44 },
45 logRequestResponse: this.recordingActive,
46 url: this.url,
47 });
48 }
49}
50exports.default = Environment;