diff --git a/src/features/certificate-authorities/common/channel.ts b/src/features/certificate-authorities/common/channel.ts new file mode 100644 index 0000000000..5fb58ee1ca --- /dev/null +++ b/src/features/certificate-authorities/common/channel.ts @@ -0,0 +1,8 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import { getRequestChannel } from "../../../common/utils/channel/get-request-channel"; + +export const casChannel = getRequestChannel("certificate-authorities"); diff --git a/src/features/certificate-authorities/main/channel-handler.global-override-for-injectable.ts b/src/features/certificate-authorities/main/channel-handler.global-override-for-injectable.ts new file mode 100644 index 0000000000..32c5c2aead --- /dev/null +++ b/src/features/certificate-authorities/main/channel-handler.global-override-for-injectable.ts @@ -0,0 +1,13 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import { getGlobalOverride } from "../../../common/test-utils/get-global-override"; +import { casChannel } from "../common/channel"; +import certificateAuthoritiesChannelListenerInjectable from "./channel-handler.injectable"; + +export default getGlobalOverride(certificateAuthoritiesChannelListenerInjectable, () => ({ + channel: casChannel, + handler: () => () => [], +})); diff --git a/src/features/certificate-authorities/main/channel-handler.injectable.ts b/src/features/certificate-authorities/main/channel-handler.injectable.ts new file mode 100644 index 0000000000..300b69c383 --- /dev/null +++ b/src/features/certificate-authorities/main/channel-handler.injectable.ts @@ -0,0 +1,25 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getRequestChannelListenerInjectable } from "../../../main/utils/channel/channel-listeners/listener-tokens"; +import { casChannel } from "../common/channel"; +import { globalAgent } from "https"; +import { isString } from "../../../common/utils"; + +const certificateAuthoritiesChannelListenerInjectable = getRequestChannelListenerInjectable({ + channel: casChannel, + handler: () => () => { + if (Array.isArray(globalAgent.options.ca)) { + return globalAgent.options.ca.filter(isString); + } + + if (typeof globalAgent.options.ca === "string") { + return [globalAgent.options.ca]; + } + + return []; + }, +}); + +export default certificateAuthoritiesChannelListenerInjectable; diff --git a/src/features/certificate-authorities/renderer/request-system-cas.injectable.ts b/src/features/certificate-authorities/renderer/request-system-cas.injectable.ts new file mode 100644 index 0000000000..e3c840a95a --- /dev/null +++ b/src/features/certificate-authorities/renderer/request-system-cas.injectable.ts @@ -0,0 +1,20 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getInjectable } from "@ogre-tools/injectable"; +import { requestFromChannelInjectionToken } from "../../../common/utils/channel/request-from-channel-injection-token"; +import { casChannel } from "../common/channel"; +import { requestSystemCAsInjectionToken } from "../common/request-system-cas-token"; + +const requestSystemCAsInjectable = getInjectable({ + id: "request-system-cas", + instantiate: (di) => { + const requestFromChannel = di.inject(requestFromChannelInjectionToken); + + return () => requestFromChannel(casChannel); + }, + injectionToken: requestSystemCAsInjectionToken, +}); + +export default requestSystemCAsInjectable;