1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix type errors from new types

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-10-26 13:57:18 -04:00
parent 7a37e2a02b
commit 048bbe8a51
2 changed files with 35 additions and 13 deletions

View File

@ -5,6 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import execFileInjectable from "../fs/exec-file.injectable"; import execFileInjectable from "../fs/exec-file.injectable";
import loggerInjectable from "../logger.injectable"; import loggerInjectable from "../logger.injectable";
import type { AsyncResult } from "../utils/async-result";
import { requestSystemCAsInjectionToken } from "./request-system-cas-token"; import { requestSystemCAsInjectionToken } from "./request-system-cas-token";
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#other_assertions // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#other_assertions
@ -16,22 +17,34 @@ const requestSystemCAsInjectable = getInjectable({
const execFile = di.inject(execFileInjectable); const execFile = di.inject(execFileInjectable);
const logger = di.inject(loggerInjectable); const logger = di.inject(loggerInjectable);
const execSecurity = async (...args: string[]) => { const execSecurity = async (...args: string[]): Promise<AsyncResult<string[]>> => {
const output = await execFile("/usr/bin/security", args); const result = await execFile("/usr/bin/security", args);
return output.split(certSplitPattern); if (!result.callWasSuccessful) {
return {
callWasSuccessful: false,
error: result.error.stderr || result.error.error.message,
};
}
return {
callWasSuccessful: true,
response: result.response.split(certSplitPattern),
};
}; };
return async () => { return async () => {
try { const [trustedResult, rootCAResult] = await Promise.all([
const [trusted, rootCA] = await Promise.all([ execSecurity("find-certificate", "-a", "-p"),
execSecurity("find-certificate", "-a", "-p"), execSecurity("find-certificate", "-a", "-p", "/System/Library/Keychains/SystemRootCertificates.keychain"),
execSecurity("find-certificate", "-a", "-p", "/System/Library/Keychains/SystemRootCertificates.keychain"), ]);
]);
return [...new Set([...trusted, ...rootCA])]; if (!trustedResult.callWasSuccessful) {
} catch (error) { logger.warn(`[INJECT-CAS]: Error retreiving trusted CAs: ${trustedResult.error}`);
logger.warn(`[INJECT-CAS]: Error injecting root CAs from MacOSX: ${error}`); } else if (!rootCAResult.callWasSuccessful) {
logger.warn(`[INJECT-CAS]: Error retreiving root CAs: ${rootCAResult.error}`);
} else {
return [...new Set([...trustedResult.response, ...rootCAResult.response])];
} }
return []; return [];

View File

@ -4,6 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import execFileInjectable from "../fs/exec-file.injectable"; import execFileInjectable from "../fs/exec-file.injectable";
import loggerInjectable from "../logger.injectable";
import { requestSystemCAsInjectionToken } from "./request-system-cas-token"; import { requestSystemCAsInjectionToken } from "./request-system-cas-token";
const pemEncoding = (hexEncodedCert: String) => { const pemEncoding = (hexEncodedCert: String) => {
@ -24,15 +25,23 @@ const requestSystemCAsInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const wincaRootsExePath: string = __non_webpack_require__.resolve("win-ca/lib/roots.exe"); const wincaRootsExePath: string = __non_webpack_require__.resolve("win-ca/lib/roots.exe");
const execFile = di.inject(execFileInjectable); const execFile = di.inject(execFileInjectable);
const logger = di.inject(loggerInjectable);
return async () => { return async () => {
/** /**
* This needs to be done manually because for some reason calling the api from "win-ca" * This needs to be done manually because for some reason calling the api from "win-ca"
* directly fails to load "child_process" correctly on renderer * directly fails to load "child_process" correctly on renderer
*/ */
const output = await execFile(wincaRootsExePath); const result = await execFile(wincaRootsExePath);
return output if (!result.callWasSuccessful) {
logger.warn(`[INJECT-CAS]: Error retreiving CAs: ${result.error}`);
return [];
}
return result
.response
.split("\r\n") .split("\r\n")
.filter(Boolean) .filter(Boolean)
.map(pemEncoding); .map(pemEncoding);