Outlook_Addin_LLM/node_modules/office-addin-dev-certs/lib/commands.js

100 lines
4.2 KiB
JavaScript
Raw Permalink Normal View History

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
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 = 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(command) {
return __awaiter(this, void 0, void 0, function* () {
try {
const days = parseDays(command.days);
const domains = parseDomains(command.domains);
yield (0, install_1.ensureCertificatesAreInstalled)(days, domains, command.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 (err) {
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(command) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield (0, uninstall_1.uninstallCaCertificate)(command.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(command /* 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