mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Use electron.clipboard for all clipboard uses (#4535) Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * Fix ERR_UNSAFE_PORT from LensProxy (#4558) * Fix ERR_UNSAFE_PORT from LensProxy - Use the current list of ports from chromium as it is much easier to just reject using one of those instead of trying to handle the ERR_UNSAFE_PORT laod error from a BrowserWindow.on("did-fail-load") Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move all port handling into LensProxy Signed-off-by: Sebastian Malton <sebastian@malton.name> * don't use so many exceptions Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * Fix not being able to clear set cluster icon (#4555) Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * Fix extension engine range not working for some ^ ranges (#4554) Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * Fix crash on NetworkPolicy when matchLabels is missing (#4500) Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * Replace all uses of promiseExec with promiseExecFile (#4514) Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * Less noisy metrics-not-available error logging (#4602) Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * Fix close button overflow in Preferences (#4611) * Adding basic colors to tailwind theme Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Using tailwind inline to style close button Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Make Select look similar to inputs Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Moving styles into separate module Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Convert tailwind commands to css Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * Fix prometheus operator metrics work out of the box (#4617) Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * Fix CRD.getPreferedVersion() to work based on apiVersion (#4553) * Fix CRD.getPreferedVersion() to work based on apiVersion Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add tests Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * Fix crash for KubeObjectStore.loadAll() (#4675) Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * Convert CloseButton styles out from css modules (#4723) * Convert CloseButton styles out from css modules Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fix close button styling Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * release v5.3.4 Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> Co-authored-by: Sebastian Malton <sebastian@malton.name> Co-authored-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Co-authored-by: Alex Andreev <alex.andreev.email@gmail.com> Co-authored-by: Lauri Nevala <lauri.nevala@gmail.com>
149 lines
4.3 KiB
TypeScript
149 lines
4.3 KiB
TypeScript
/**
|
|
* Copyright (c) 2021 OpenLens Authors
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
* the Software without restriction, including without limitation the rights to
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
* subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
import styles from "./kubeconfig-dialog.module.css";
|
|
import React from "react";
|
|
import { makeObservable, observable } from "mobx";
|
|
import { observer } from "mobx-react";
|
|
import yaml from "js-yaml";
|
|
import type { ServiceAccount } from "../../../common/k8s-api/endpoints";
|
|
import { saveFileDialog } from "../../utils";
|
|
import { Button } from "../button";
|
|
import { Dialog, DialogProps } from "../dialog";
|
|
import { Icon } from "../icon";
|
|
import { Notifications } from "../notifications";
|
|
import { Wizard, WizardStep } from "../wizard";
|
|
import { apiBase } from "../../api";
|
|
import { MonacoEditor } from "../monaco-editor";
|
|
import { clipboard } from "electron";
|
|
|
|
interface IKubeconfigDialogData {
|
|
title?: React.ReactNode;
|
|
loader?: () => Promise<any>;
|
|
}
|
|
|
|
interface Props extends Partial<DialogProps> {
|
|
}
|
|
|
|
const dialogState = observable.object({
|
|
isOpen: false,
|
|
data: null as IKubeconfigDialogData,
|
|
});
|
|
|
|
@observer
|
|
export class KubeConfigDialog extends React.Component<Props> {
|
|
@observable config = ""; // parsed kubeconfig in yaml format
|
|
|
|
constructor(props: Props) {
|
|
super(props);
|
|
makeObservable(this);
|
|
}
|
|
|
|
static open(data: IKubeconfigDialogData) {
|
|
dialogState.isOpen = true;
|
|
dialogState.data = data;
|
|
}
|
|
|
|
static close() {
|
|
dialogState.isOpen = false;
|
|
dialogState.data = null;
|
|
}
|
|
|
|
get data(): IKubeconfigDialogData {
|
|
return dialogState.data;
|
|
}
|
|
|
|
close = () => {
|
|
KubeConfigDialog.close();
|
|
};
|
|
|
|
onOpen = () => {
|
|
this.loadConfig();
|
|
};
|
|
|
|
async loadConfig() {
|
|
const config = await this.data.loader().catch(err => {
|
|
Notifications.error(err);
|
|
this.close();
|
|
});
|
|
|
|
this.config = config ? yaml.dump(config) : "";
|
|
}
|
|
|
|
copyToClipboard = () => {
|
|
clipboard.writeText(this.config);
|
|
Notifications.ok("Config copied to clipboard");
|
|
};
|
|
|
|
download = () => {
|
|
saveFileDialog("config", this.config, "text/yaml");
|
|
};
|
|
|
|
render() {
|
|
const { ...dialogProps } = this.props;
|
|
const yamlConfig = this.config;
|
|
const header = <h5>{this.data?.title || "Kubeconfig File"}</h5>;
|
|
const buttons = (
|
|
<div className="actions flex gaps">
|
|
<Button plain onClick={this.copyToClipboard}>
|
|
<Icon material="assignment"/> Copy to clipboard
|
|
</Button>
|
|
<Button plain onClick={this.download}>
|
|
<Icon material="cloud_download"/> Download file
|
|
</Button>
|
|
<Button plain className="box right" onClick={this.close}>
|
|
Close
|
|
</Button>
|
|
</div>
|
|
);
|
|
|
|
return (
|
|
<Dialog
|
|
{...dialogProps}
|
|
className={styles.KubeConfigDialog}
|
|
isOpen={dialogState.isOpen}
|
|
onOpen={this.onOpen}
|
|
close={this.close}
|
|
>
|
|
<Wizard header={header}>
|
|
<WizardStep customButtons={buttons} prev={this.close}>
|
|
<MonacoEditor
|
|
readOnly
|
|
className={styles.editor}
|
|
value={yamlConfig}
|
|
/>
|
|
</WizardStep>
|
|
</Wizard>
|
|
</Dialog>
|
|
);
|
|
}
|
|
}
|
|
|
|
export function openServiceAccountKubeConfig(account: ServiceAccount) {
|
|
const accountName = account.getName();
|
|
const namespace = account.getNs();
|
|
|
|
KubeConfigDialog.open({
|
|
title: `${accountName} kubeconfig`,
|
|
loader: () => apiBase.get(`/kubeconfig/service-account/${namespace}/${accountName}`),
|
|
});
|
|
}
|