1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 |
|
7 | require("dotenv").config();
|
8 | const debug_1 = __importDefault(require("debug"));
|
9 | const error_1 = __importDefault(require("./error"));
|
10 | const server_1 = __importDefault(require("./server"));
|
11 | exports.Server = server_1.default;
|
12 | const debug = debug_1.default("NCEnvironmentVcapServices");
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | class EnvironmentVcapServices {
|
19 | constructor(instanceName) {
|
20 | if (!process.env.VCAP_SERVICES) {
|
21 | throw new error_1.default("NCEnvironmentVcapServices: environment VCAP_SERVICES not found", "ERR_VCAP_SERVICES_NOT_FOUND");
|
22 | }
|
23 | const vcapServices = require("vcap_services");
|
24 | const cred = vcapServices.getCredentials("user-provided", undefined, instanceName);
|
25 | if (!cred || cred === undefined || (!cred.url && !cred.username && !cred.password)) {
|
26 | debug("NCEnvironmentVcapServices: error credentials not found or not fully specified %O", cred);
|
27 | throw new error_1.default(`NCEnvironmentVcapServices: nextcloud credentials not found in environment VCAP_SERVICES. Service section: "user-provided", service instance name: "${instanceName}" `, "ERR_VCAP_SERVICES_NOT_FOUND");
|
28 | }
|
29 | if (!cred.url) {
|
30 | throw new error_1.default("NCEnvironmentVcapServices: VCAP_SERVICES url not defined in user provided services for nextcloud", "ERR_VCAP_SERVICES_URL_NOT_DEFINED", { credentials: cred });
|
31 | }
|
32 | if (!cred.password) {
|
33 | throw new error_1.default("NCEnvironmentVcapServices: VCAP_SERVICES password not defined in user provided services for nextcloud", "ERR_VCAP_SERVICES_PASSWORD_NOT_DEFINED", { credentials: cred });
|
34 | }
|
35 | if (!cred.username) {
|
36 | throw new error_1.default("NCEnvironmentVcapServices: VCAP_SERVICES username not defined in user provided services for nextcloud", "ERR_VCAP_SERVICES_USERNAME_NOT_DEFINED", { credentials: cred });
|
37 | }
|
38 | this.url = cred.url;
|
39 | this.userName = cred.username;
|
40 | this.password = cred.password;
|
41 | }
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | getServer() {
|
49 | return new server_1.default({
|
50 | basicAuth: {
|
51 | password: this.password,
|
52 | username: this.userName,
|
53 | },
|
54 | url: this.url,
|
55 | });
|
56 | }
|
57 | }
|
58 | exports.default = EnvironmentVcapServices;
|