mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Split UserManagement into seperate Cluster and Namespace Roles and RoleBindings (#2755)
This commit is contained in:
1 parent
1ed7892b26
commit
a1a1c240e9
69 files changed
+2896
-901
No files matched your search
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.CreateServiceAccountDialog {
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* 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 "./create-dialog.scss";
|
||||
|
||||
import React from "react";
|
||||
import { makeObservable, observable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
|
||||
import { NamespaceSelect } from "../../+namespaces/namespace-select";
|
||||
import { Dialog, DialogProps } from "../../dialog";
|
||||
import { Input } from "../../input";
|
||||
import { systemName } from "../../input/input_validators";
|
||||
import { showDetails } from "../../kube-object";
|
||||
import { SubTitle } from "../../layout/sub-title";
|
||||
import { Notifications } from "../../notifications";
|
||||
import { Wizard, WizardStep } from "../../wizard";
|
||||
import { serviceAccountsStore } from "./store";
|
||||
|
||||
interface Props extends Partial<DialogProps> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class CreateServiceAccountDialog extends React.Component<Props> {
|
||||
static isOpen = observable.box(false);
|
||||
|
||||
@observable name = "";
|
||||
@observable namespace = "default";
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
static open() {
|
||||
CreateServiceAccountDialog.isOpen.set(true);
|
||||
}
|
||||
|
||||
static close() {
|
||||
CreateServiceAccountDialog.isOpen.set(false);
|
||||
}
|
||||
|
||||
createAccount = async () => {
|
||||
const { name, namespace } = this;
|
||||
|
||||
try {
|
||||
const serviceAccount = await serviceAccountsStore.create({ namespace, name });
|
||||
|
||||
this.name = "";
|
||||
showDetails(serviceAccount.selfLink);
|
||||
CreateServiceAccountDialog.close();
|
||||
} catch (err) {
|
||||
Notifications.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const { ...dialogProps } = this.props;
|
||||
const { name, namespace } = this;
|
||||
const header = <h5>Create Service Account</h5>;
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
{...dialogProps}
|
||||
className="CreateServiceAccountDialog"
|
||||
isOpen={CreateServiceAccountDialog.isOpen.get()}
|
||||
close={CreateServiceAccountDialog.close}
|
||||
>
|
||||
<Wizard header={header} done={CreateServiceAccountDialog.close}>
|
||||
<WizardStep nextLabel="Create" next={this.createAccount}>
|
||||
<SubTitle title="Account Name" />
|
||||
<Input
|
||||
autoFocus required
|
||||
placeholder="Enter a name"
|
||||
validators={systemName}
|
||||
value={name} onChange={v => this.name = v.toLowerCase()}
|
||||
/>
|
||||
<SubTitle title="Namespace" />
|
||||
<NamespaceSelect
|
||||
themeName="light"
|
||||
value={namespace}
|
||||
onChange={({ value }) => this.namespace = value}
|
||||
/>
|
||||
</WizardStep>
|
||||
</Wizard>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.ServiceAccountsDetails {
|
||||
.links {
|
||||
a {
|
||||
margin-right: $margin;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/**
|
||||
* 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 "./details.scss";
|
||||
|
||||
import { autorun, observable, makeObservable } from "mobx";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
import { secretsStore } from "../../+config-secrets/secrets.store";
|
||||
import { KubeEventDetails } from "../../+events/kube-event-details";
|
||||
import { Secret, ServiceAccount } from "../../../api/endpoints";
|
||||
import { kubeObjectDetailRegistry } from "../../../api/kube-object-detail-registry";
|
||||
import { DrawerItem, DrawerTitle } from "../../drawer";
|
||||
import { Icon } from "../../icon";
|
||||
import { getDetailsUrl, KubeObjectDetailsProps } from "../../kube-object";
|
||||
import { KubeObjectMeta } from "../../kube-object/kube-object-meta";
|
||||
import { Spinner } from "../../spinner";
|
||||
import { ServiceAccountsSecret } from "./secret";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<ServiceAccount> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class ServiceAccountsDetails extends React.Component<Props> {
|
||||
@observable secrets: Secret[];
|
||||
@observable imagePullSecrets: Secret[];
|
||||
|
||||
@disposeOnUnmount
|
||||
loadSecrets = autorun(async () => {
|
||||
this.secrets = null;
|
||||
this.imagePullSecrets = null;
|
||||
const { object: serviceAccount } = this.props;
|
||||
|
||||
if (!serviceAccount) {
|
||||
return;
|
||||
}
|
||||
const namespace = serviceAccount.getNs();
|
||||
const secrets = serviceAccount.getSecrets().map(({ name }) => {
|
||||
return secretsStore.load({ name, namespace });
|
||||
});
|
||||
|
||||
this.secrets = await Promise.all(secrets);
|
||||
const imagePullSecrets = serviceAccount.getImagePullSecrets().map(async({ name }) => {
|
||||
return secretsStore.load({ name, namespace }).catch(() => this.generateDummySecretObject(name));
|
||||
});
|
||||
|
||||
this.imagePullSecrets = await Promise.all(imagePullSecrets);
|
||||
});
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
renderSecrets() {
|
||||
const { secrets } = this;
|
||||
|
||||
if (!secrets) {
|
||||
return <Spinner center/>;
|
||||
}
|
||||
|
||||
return secrets.map(secret =>
|
||||
<ServiceAccountsSecret key={secret.getId()} secret={secret}/>
|
||||
);
|
||||
}
|
||||
|
||||
renderImagePullSecrets() {
|
||||
const { imagePullSecrets } = this;
|
||||
|
||||
if (!imagePullSecrets) {
|
||||
return <Spinner center/>;
|
||||
}
|
||||
|
||||
return this.renderSecretLinks(imagePullSecrets);
|
||||
}
|
||||
|
||||
renderSecretLinks(secrets: Secret[]) {
|
||||
return secrets.map((secret) => {
|
||||
if (secret.getId() === null) {
|
||||
return (
|
||||
<div key={secret.getName()}>
|
||||
{secret.getName()}
|
||||
<Icon
|
||||
small material="warning"
|
||||
tooltip="Secret is not found"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Link key={secret.getId()} to={getDetailsUrl(secret.selfLink)}>
|
||||
{secret.getName()}
|
||||
</Link>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
generateDummySecretObject(name: string) {
|
||||
return new Secret({
|
||||
apiVersion: "v1",
|
||||
kind: "Secret",
|
||||
metadata: {
|
||||
name,
|
||||
uid: null,
|
||||
selfLink: null,
|
||||
resourceVersion: null
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { object: serviceAccount } = this.props;
|
||||
|
||||
if (!serviceAccount) {
|
||||
return null;
|
||||
}
|
||||
const tokens = secretsStore.items.filter(secret =>
|
||||
secret.getNs() == serviceAccount.getNs() &&
|
||||
secret.getAnnotations().some(annot => annot == `kubernetes.io/service-account.name: ${serviceAccount.getName()}`)
|
||||
);
|
||||
const imagePullSecrets = serviceAccount.getImagePullSecrets();
|
||||
|
||||
return (
|
||||
<div className="ServiceAccountsDetails">
|
||||
<KubeObjectMeta object={serviceAccount}/>
|
||||
|
||||
{tokens.length > 0 &&
|
||||
<DrawerItem name="Tokens" className="links">
|
||||
{this.renderSecretLinks(tokens)}
|
||||
</DrawerItem>
|
||||
}
|
||||
{imagePullSecrets.length > 0 &&
|
||||
<DrawerItem name="ImagePullSecrets" className="links">
|
||||
{this.renderImagePullSecrets()}
|
||||
</DrawerItem>
|
||||
}
|
||||
|
||||
<DrawerTitle title="Mountable secrets"/>
|
||||
<div className="secrets">
|
||||
{this.renderSecrets()}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
kubeObjectDetailRegistry.add({
|
||||
kind: "ServiceAccount",
|
||||
apiVersions: ["v1"],
|
||||
components: {
|
||||
Details: (props) => <ServiceAccountsDetails {...props} />
|
||||
}
|
||||
});
|
||||
kubeObjectDetailRegistry.add({
|
||||
kind: "ServiceAccount",
|
||||
apiVersions: ["v1"],
|
||||
priority: 5,
|
||||
components: {
|
||||
Details: (props) => <KubeEventDetails {...props} />
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
export * from "./view";
|
||||
export * from "./details";
|
||||
export * from "./create-dialog";
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.ServiceAccountsSecret {
|
||||
margin-bottom: $margin * 3;
|
||||
|
||||
&:nth-child(even) {
|
||||
margin-left: -$margin * 3;
|
||||
margin-right: -$margin * 3;
|
||||
padding: $padding $padding * 3;
|
||||
}
|
||||
|
||||
.secret-row {
|
||||
display: flex;
|
||||
border-bottom: 1px solid $borderFaintColor;
|
||||
padding: $padding 0;
|
||||
|
||||
&:first-child {
|
||||
padding-top: 0
|
||||
}
|
||||
}
|
||||
|
||||
.name {
|
||||
flex-basis: 23%;
|
||||
color: $drawerItemNameColor;
|
||||
}
|
||||
|
||||
.value {
|
||||
flex-basis: 76%;
|
||||
color: $drawerItemValueColor;
|
||||
word-break: break-all;
|
||||
|
||||
&:empty:after {
|
||||
content: '—'
|
||||
}
|
||||
}
|
||||
|
||||
.asterisks {
|
||||
font-size: large;
|
||||
margin-right: $margin / 2;
|
||||
line-height: 90%;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* 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 "./secret.scss";
|
||||
|
||||
import moment from "moment";
|
||||
import React from "react";
|
||||
|
||||
import type { Secret } from "../../../api/endpoints/secret.api";
|
||||
import { prevDefault } from "../../../utils";
|
||||
import { Icon } from "../../icon";
|
||||
|
||||
interface Props {
|
||||
secret: Secret;
|
||||
}
|
||||
|
||||
interface State {
|
||||
showToken: boolean;
|
||||
}
|
||||
|
||||
export class ServiceAccountsSecret extends React.Component<Props, State> {
|
||||
public state: State = {
|
||||
showToken: false,
|
||||
};
|
||||
|
||||
renderSecretValue() {
|
||||
const { secret } = this.props;
|
||||
const { showToken } = this.state;
|
||||
|
||||
return (
|
||||
<>
|
||||
{!showToken && (
|
||||
<>
|
||||
<span className="asterisks">{Array(16).fill("•").join("")}</span>
|
||||
<Icon
|
||||
small material="lock_open"
|
||||
tooltip="Show value"
|
||||
onClick={prevDefault(() => this.setState({ showToken: true }))}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{showToken && (
|
||||
<span className="raw-value">{secret.getToken()}</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { metadata: { name, creationTimestamp }, type } = this.props.secret;
|
||||
|
||||
return (
|
||||
<div className="ServiceAccountsSecret box grow-fixed">
|
||||
<div className="secret-row">
|
||||
<span className="name">Name: </span>
|
||||
<span className="value">{name}</span>
|
||||
</div>
|
||||
<div className="secret-row">
|
||||
<span className="name">Value: </span>
|
||||
<span className="value flex align-center">{this.renderSecretValue()}</span>
|
||||
</div>
|
||||
<div className="secret-row">
|
||||
<span className="name">Created at: </span>
|
||||
<span className="value" title={creationTimestamp}>
|
||||
{moment(creationTimestamp).format("LLL")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="secret-row">
|
||||
<span className="name">Type: </span>
|
||||
<span className="value">{type}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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 { apiManager } from "../../../api/api-manager";
|
||||
import { ServiceAccount, serviceAccountsApi } from "../../../api/endpoints";
|
||||
import { KubeObjectStore } from "../../../kube-object.store";
|
||||
import { autoBind } from "../../../utils";
|
||||
|
||||
export class ServiceAccountsStore extends KubeObjectStore<ServiceAccount> {
|
||||
api = serviceAccountsApi;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
autoBind(this);
|
||||
}
|
||||
|
||||
protected async createItem(params: { name: string; namespace?: string }) {
|
||||
await super.createItem(params);
|
||||
|
||||
return this.api.get(params); // hackfix: load freshly created account, cause it doesn't have "secrets" field yet
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceAccountsStore = new ServiceAccountsStore();
|
||||
apiManager.registerStore(serviceAccountsStore);
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.ServiceAccounts {
|
||||
.TableCell {
|
||||
&.warning {
|
||||
@include table-cell-warning;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* 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 "./view.scss";
|
||||
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import type { RouteComponentProps } from "react-router";
|
||||
import type { ServiceAccountsRouteParams } from "../user-management.route";
|
||||
import { kubeObjectMenuRegistry } from "../../../../extensions/registries/kube-object-menu-registry";
|
||||
import type { ServiceAccount } from "../../../api/endpoints/service-accounts.api";
|
||||
import { Icon } from "../../icon";
|
||||
import { KubeObjectListLayout } from "../../kube-object";
|
||||
import { KubeObjectStatusIcon } from "../../kube-object-status-icon";
|
||||
import type { KubeObjectMenuProps } from "../../kube-object/kube-object-menu";
|
||||
import { openServiceAccountKubeConfig } from "../../kubeconfig-dialog";
|
||||
import { MenuItem } from "../../menu";
|
||||
import { CreateServiceAccountDialog } from "./create-dialog";
|
||||
import { serviceAccountsStore } from "./store";
|
||||
|
||||
enum columnId {
|
||||
name = "name",
|
||||
namespace = "namespace",
|
||||
age = "age",
|
||||
}
|
||||
|
||||
interface Props extends RouteComponentProps<ServiceAccountsRouteParams> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class ServiceAccounts extends React.Component<Props> {
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
<KubeObjectListLayout
|
||||
isConfigurable
|
||||
tableId="access_service_accounts"
|
||||
className="ServiceAccounts" store={serviceAccountsStore}
|
||||
sortingCallbacks={{
|
||||
[columnId.name]: (account: ServiceAccount) => account.getName(),
|
||||
[columnId.namespace]: (account: ServiceAccount) => account.getNs(),
|
||||
[columnId.age]: (account: ServiceAccount) => account.getTimeDiffFromNow(),
|
||||
}}
|
||||
searchFilters={[
|
||||
(account: ServiceAccount) => account.getSearchFields(),
|
||||
]}
|
||||
renderHeaderTitle="Service Accounts"
|
||||
renderTableHeader={[
|
||||
{ title: "Name", className: "name", sortBy: columnId.name, id: columnId.name },
|
||||
{ className: "warning", showWithColumn: columnId.name },
|
||||
{ title: "Namespace", className: "namespace", sortBy: columnId.namespace, id: columnId.namespace },
|
||||
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
|
||||
]}
|
||||
renderTableContents={(account: ServiceAccount) => [
|
||||
account.getName(),
|
||||
<KubeObjectStatusIcon key="icon" object={account} />,
|
||||
account.getNs(),
|
||||
account.getAge(),
|
||||
]}
|
||||
renderItemMenu={(item: ServiceAccount) => {
|
||||
return <ServiceAccountMenu object={item}/>;
|
||||
}}
|
||||
addRemoveButtons={{
|
||||
onAdd: () => CreateServiceAccountDialog.open(),
|
||||
addTooltip: "Create new Service Account",
|
||||
}}
|
||||
/>
|
||||
<CreateServiceAccountDialog/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function ServiceAccountMenu(props: KubeObjectMenuProps<ServiceAccount>) {
|
||||
const { object, toolbar } = props;
|
||||
|
||||
return (
|
||||
<MenuItem onClick={() => openServiceAccountKubeConfig(object)}>
|
||||
<Icon material="insert_drive_file" title="Kubeconfig File" interactive={toolbar}/>
|
||||
<span className="title">Kubeconfig</span>
|
||||
</MenuItem>
|
||||
);
|
||||
}
|
||||
|
||||
kubeObjectMenuRegistry.add({
|
||||
kind: "ServiceAccount",
|
||||
apiVersions: ["v1"],
|
||||
components: {
|
||||
MenuItem: ServiceAccountMenu
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user