UNPKG

@openshift-assisted/ui-lib

Version:

React component library for the Assisted Installer UI

39 lines 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const react_1 = tslib_1.__importDefault(require("react")); const file_saver_1 = require("file-saver"); const KubeconfigDownload_1 = tslib_1.__importDefault(require("../../../common/components/clusterDetail/KubeconfigDownload")); const status_1 = require("../helpers/status"); const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper"); const ClusterDeploymentKubeconfigDownload = ({ clusterDeployment, agentClusterInstall, fetchSecret, }) => { var _a; const [clusterStatus] = (0, status_1.getClusterStatus)(agentClusterInstall); const { t } = (0, use_translation_wrapper_1.useTranslation)(); const handleKubeconfigDownload = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { var _b, _c, _d, _e, _f, _g, _h, _j; const kubeconfigSecretName = ((_d = (_c = (_b = agentClusterInstall.spec) === null || _b === void 0 ? void 0 : _b.clusterMetadata) === null || _c === void 0 ? void 0 : _c.adminKubeconfigSecretRef) === null || _d === void 0 ? void 0 : _d.name) || ((_g = (_f = (_e = clusterDeployment.spec) === null || _e === void 0 ? void 0 : _e.clusterMetadata) === null || _f === void 0 ? void 0 : _f.adminKubeconfigSecretRef) === null || _g === void 0 ? void 0 : _g.name); const kubeconfigSecretNamespace = (_h = clusterDeployment.metadata) === null || _h === void 0 ? void 0 : _h.namespace; if (kubeconfigSecretName && kubeconfigSecretNamespace) { try { const kubeconfigSecret = yield fetchSecret(kubeconfigSecretName, kubeconfigSecretNamespace); const kubeconfig = (_j = kubeconfigSecret.data) === null || _j === void 0 ? void 0 : _j.kubeconfig; if (!kubeconfig) throw new Error(t('ai:Kubeconfig is empty.')); const blob = new Blob([atob(kubeconfig)], { type: 'text/plain;charset=utf-8' }); (0, file_saver_1.saveAs)(blob, 'kubeconfig.yaml'); } catch (e) { // console.error('Failed to fetch kubeconfig secret.', e); } } }); return (react_1.default.createElement(KubeconfigDownload_1.default // eslint-disable-next-line @typescript-eslint/no-misused-promises , { // eslint-disable-next-line @typescript-eslint/no-misused-promises handleDownload: handleKubeconfigDownload, clusterId: ((_a = clusterDeployment.metadata) === null || _a === void 0 ? void 0 : _a.uid) || '', status: clusterStatus })); }; exports.default = ClusterDeploymentKubeconfigDownload; //# sourceMappingURL=ClusterDeploymentKubeconfigDownload.js.map