124 lines
5.2 KiB
JavaScript
124 lines
5.2 KiB
JavaScript
"use strict";
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT license.
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.verify = exports.uninstall = exports.install = void 0;
|
|
const office_addin_cli_1 = require("office-addin-cli");
|
|
const office_addin_usage_data_1 = require("office-addin-usage-data");
|
|
const defaults = __importStar(require("./defaults"));
|
|
const install_1 = require("./install");
|
|
const uninstall_1 = require("./uninstall");
|
|
const verify_1 = require("./verify");
|
|
const defaults_1 = require("./defaults");
|
|
const office_addin_usage_data_2 = require("office-addin-usage-data");
|
|
/* global console */
|
|
function install(options) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
try {
|
|
const days = parseDays(options.days);
|
|
const domains = parseDomains(options.domains);
|
|
yield (0, install_1.ensureCertificatesAreInstalled)(days, domains, options.machine);
|
|
defaults_1.usageDataObject.reportSuccess("install");
|
|
}
|
|
catch (err) {
|
|
defaults_1.usageDataObject.reportException("install", err);
|
|
(0, office_addin_usage_data_1.logErrorMessage)(err);
|
|
}
|
|
});
|
|
}
|
|
exports.install = install;
|
|
function parseDays(optionValue) {
|
|
const days = (0, office_addin_cli_1.parseNumber)(optionValue, "--days should specify a number.");
|
|
if (days !== undefined) {
|
|
if (!Number.isInteger(days)) {
|
|
throw new office_addin_usage_data_2.ExpectedError("--days should be integer.");
|
|
}
|
|
if (days <= 0) {
|
|
throw new office_addin_usage_data_2.ExpectedError("--days should be greater than zero.");
|
|
}
|
|
}
|
|
return days;
|
|
}
|
|
function parseDomains(optionValue) {
|
|
switch (typeof optionValue) {
|
|
case "string": {
|
|
try {
|
|
return optionValue.split(",");
|
|
}
|
|
catch (_a) {
|
|
throw new Error("string value not in the correct format");
|
|
}
|
|
}
|
|
case "undefined": {
|
|
return undefined;
|
|
}
|
|
default: {
|
|
throw new Error("--domains value should be a string.");
|
|
}
|
|
}
|
|
}
|
|
function uninstall(options) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
try {
|
|
yield (0, uninstall_1.uninstallCaCertificate)(options.machine);
|
|
(0, uninstall_1.deleteCertificateFiles)(defaults.certificateDirectory);
|
|
defaults_1.usageDataObject.reportSuccess("uninstall");
|
|
}
|
|
catch (err) {
|
|
defaults_1.usageDataObject.reportException("uninstall", err);
|
|
(0, office_addin_usage_data_1.logErrorMessage)(err);
|
|
}
|
|
});
|
|
}
|
|
exports.uninstall = uninstall;
|
|
function verify(options /* eslint-disable-line @typescript-eslint/no-unused-vars */) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
try {
|
|
if (yield (0, verify_1.verifyCertificates)()) {
|
|
console.log(`You have trusted access to https://localhost.\nCertificate: ${defaults.localhostCertificatePath}\nKey: ${defaults.localhostKeyPath}`);
|
|
}
|
|
else {
|
|
console.log(`You need to install certificates for trusted access to https://localhost.`);
|
|
}
|
|
defaults_1.usageDataObject.reportSuccess("verify");
|
|
}
|
|
catch (err) {
|
|
defaults_1.usageDataObject.reportException("verify", err);
|
|
(0, office_addin_usage_data_1.logErrorMessage)(err);
|
|
}
|
|
});
|
|
}
|
|
exports.verify = verify;
|
|
//# sourceMappingURL=commands.js.map
|