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,2 @@
|
||||
.RoleBindingDetails {
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* 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 { reaction } from "mobx";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import { KubeEventDetails } from "../../+events/kube-event-details";
|
||||
import type { RoleBinding, RoleBindingSubject } from "../../../api/endpoints";
|
||||
import { kubeObjectDetailRegistry } from "../../../api/kube-object-detail-registry";
|
||||
import { prevDefault, boundMethod } from "../../../utils";
|
||||
import { AddRemoveButtons } from "../../add-remove-buttons";
|
||||
import { ConfirmDialog } from "../../confirm-dialog";
|
||||
import { DrawerTitle } from "../../drawer";
|
||||
import type { KubeObjectDetailsProps } from "../../kube-object";
|
||||
import { KubeObjectMeta } from "../../kube-object/kube-object-meta";
|
||||
import { Table, TableCell, TableHead, TableRow } from "../../table";
|
||||
import { RoleBindingDialog } from "./dialog";
|
||||
import { roleBindingsStore } from "./store";
|
||||
import { ObservableHashSet } from "../../../../common/utils/hash-set";
|
||||
import { hashRoleBindingSubject } from "./hashers";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<RoleBinding> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class RoleBindingDetails extends React.Component<Props> {
|
||||
selectedSubjects = new ObservableHashSet<RoleBindingSubject>([], hashRoleBindingSubject);
|
||||
|
||||
async componentDidMount() {
|
||||
disposeOnUnmount(this, [
|
||||
reaction(() => this.props.object, () => {
|
||||
this.selectedSubjects.clear();
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
@boundMethod
|
||||
removeSelectedSubjects() {
|
||||
const { object: roleBinding } = this.props;
|
||||
const { selectedSubjects } = this;
|
||||
|
||||
ConfirmDialog.open({
|
||||
ok: () => roleBindingsStore.removeSubjects(roleBinding, selectedSubjects.toJSON()),
|
||||
labelOk: `Remove`,
|
||||
message: (
|
||||
<p>Remove selected bindings for <b>{roleBinding.getName()}</b>?</p>
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { selectedSubjects } = this;
|
||||
const { object: roleBinding } = this.props;
|
||||
|
||||
if (!roleBinding) {
|
||||
return null;
|
||||
}
|
||||
const { roleRef } = roleBinding;
|
||||
const subjects = roleBinding.getSubjects();
|
||||
|
||||
return (
|
||||
<div className="RoleBindingDetails">
|
||||
<KubeObjectMeta object={roleBinding} />
|
||||
|
||||
<DrawerTitle title="Reference" />
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableCell>Kind</TableCell>
|
||||
<TableCell>Name</TableCell>
|
||||
<TableCell>API Group</TableCell>
|
||||
</TableHead>
|
||||
<TableRow>
|
||||
<TableCell>{roleRef.kind}</TableCell>
|
||||
<TableCell>{roleRef.name}</TableCell>
|
||||
<TableCell>{roleRef.apiGroup}</TableCell>
|
||||
</TableRow>
|
||||
</Table>
|
||||
|
||||
<DrawerTitle title="Bindings" />
|
||||
{subjects.length > 0 && (
|
||||
<Table selectable className="bindings box grow">
|
||||
<TableHead>
|
||||
<TableCell checkbox />
|
||||
<TableCell className="binding">Name</TableCell>
|
||||
<TableCell className="type">Type</TableCell>
|
||||
<TableCell className="type">Namespace</TableCell>
|
||||
</TableHead>
|
||||
{
|
||||
subjects.map((subject, i) => {
|
||||
const { kind, name, namespace } = subject;
|
||||
const isSelected = selectedSubjects.has(subject);
|
||||
|
||||
return (
|
||||
<TableRow
|
||||
key={i}
|
||||
selected={isSelected}
|
||||
onClick={prevDefault(() => this.selectedSubjects.toggle(subject))}
|
||||
>
|
||||
<TableCell checkbox isChecked={isSelected} />
|
||||
<TableCell className="binding">{name}</TableCell>
|
||||
<TableCell className="type">{kind}</TableCell>
|
||||
<TableCell className="ns">{namespace || "-"}</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})
|
||||
}
|
||||
</Table>
|
||||
)}
|
||||
|
||||
<AddRemoveButtons
|
||||
onAdd={() => RoleBindingDialog.open(roleBinding)}
|
||||
onRemove={selectedSubjects.size ? this.removeSelectedSubjects : null}
|
||||
addTooltip={`Edit bindings of ${roleRef.name}`}
|
||||
removeTooltip={`Remove selected bindings from ${roleRef.name}`}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
kubeObjectDetailRegistry.add({
|
||||
kind: "RoleBinding",
|
||||
apiVersions: ["rbac.authorization.k8s.io/v1"],
|
||||
components: {
|
||||
Details: (props) => <RoleBindingDetails {...props} />
|
||||
}
|
||||
});
|
||||
kubeObjectDetailRegistry.add({
|
||||
kind: "RoleBinding",
|
||||
apiVersions: ["rbac.authorization.k8s.io/v1"],
|
||||
priority: 5,
|
||||
components: {
|
||||
Details: (props) => <KubeEventDetails {...props} />
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.AddRoleBindingDialog {
|
||||
.Select + .Select {
|
||||
margin-top: $margin /2;
|
||||
}
|
||||
.Checkbox {
|
||||
margin-top: $margin;
|
||||
}
|
||||
.name {
|
||||
color: #a0a0a0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
/**
|
||||
* 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 "./dialog.scss";
|
||||
|
||||
import { computed, observable, makeObservable, action } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
|
||||
import { rolesStore } from "../+roles/store";
|
||||
import { serviceAccountsStore } from "../+service-accounts/store";
|
||||
import { NamespaceSelect } from "../../+namespaces/namespace-select";
|
||||
import { ClusterRole, Role, roleApi, RoleBinding, RoleBindingSubject, ServiceAccount } from "../../../api/endpoints";
|
||||
import { Dialog, DialogProps } from "../../dialog";
|
||||
import { EditableList } from "../../editable-list";
|
||||
import { Icon } from "../../icon";
|
||||
import { showDetails } from "../../kube-object";
|
||||
import { SubTitle } from "../../layout/sub-title";
|
||||
import { Notifications } from "../../notifications";
|
||||
import { Select, SelectOption } from "../../select";
|
||||
import { Wizard, WizardStep } from "../../wizard";
|
||||
import { roleBindingsStore } from "./store";
|
||||
import { clusterRolesStore } from "../+cluster-roles/store";
|
||||
import { Input } from "../../input";
|
||||
import { getRoleRefSelectOption, ServiceAccountOption } from "../select-options";
|
||||
import { ObservableHashSet, nFircate } from "../../../utils";
|
||||
|
||||
interface Props extends Partial<DialogProps> {
|
||||
}
|
||||
|
||||
interface DialogState {
|
||||
isOpen: boolean;
|
||||
data?: RoleBinding;
|
||||
}
|
||||
|
||||
@observer
|
||||
export class RoleBindingDialog extends React.Component<Props> {
|
||||
static state = observable.object<DialogState>({
|
||||
isOpen: false,
|
||||
});
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
static open(roleBinding?: RoleBinding) {
|
||||
RoleBindingDialog.state.isOpen = true;
|
||||
RoleBindingDialog.state.data = roleBinding;
|
||||
}
|
||||
|
||||
static close() {
|
||||
RoleBindingDialog.state.isOpen = false;
|
||||
RoleBindingDialog.state.data = undefined;
|
||||
}
|
||||
|
||||
get roleBinding(): RoleBinding {
|
||||
return RoleBindingDialog.state.data;
|
||||
}
|
||||
|
||||
@computed get isEditing() {
|
||||
return !!this.roleBinding;
|
||||
}
|
||||
|
||||
@observable.ref selectedRoleRef: Role | ClusterRole | undefined = undefined;
|
||||
@observable bindingName = "";
|
||||
@observable bindingNamespace = "";
|
||||
selectedAccounts = new ObservableHashSet<ServiceAccount>([], sa => sa.metadata.uid);
|
||||
selectedUsers = observable.set<string>([]);
|
||||
selectedGroups = observable.set<string>([]);
|
||||
|
||||
@computed get selectedBindings(): RoleBindingSubject[] {
|
||||
const serviceAccounts = Array.from(this.selectedAccounts, sa => ({
|
||||
name: sa.getName(),
|
||||
kind: "ServiceAccount" as const,
|
||||
namespace: this.bindingNamespace,
|
||||
}));
|
||||
const users = Array.from(this.selectedUsers, user => ({
|
||||
name: user,
|
||||
kind: "User" as const,
|
||||
namespace: this.bindingNamespace,
|
||||
}));
|
||||
const groups = Array.from(this.selectedGroups, group => ({
|
||||
name: group,
|
||||
kind: "Group" as const,
|
||||
namespace: this.bindingNamespace,
|
||||
}));
|
||||
|
||||
return [
|
||||
...serviceAccounts,
|
||||
...users,
|
||||
...groups,
|
||||
];
|
||||
}
|
||||
|
||||
@computed get roleRefOptions(): SelectOption<Role | ClusterRole>[] {
|
||||
const roles = rolesStore.items
|
||||
.filter(role => role.getNs() === this.bindingNamespace)
|
||||
.map(getRoleRefSelectOption);
|
||||
const clusterRoles = clusterRolesStore.items
|
||||
.map(getRoleRefSelectOption);
|
||||
|
||||
return [
|
||||
...roles,
|
||||
...clusterRoles,
|
||||
];
|
||||
}
|
||||
|
||||
@computed get serviceAccountOptions(): ServiceAccountOption[] {
|
||||
return serviceAccountsStore.items.map(account => {
|
||||
const name = account.getName();
|
||||
const namespace = account.getNs();
|
||||
|
||||
return {
|
||||
value: `${account.getName()}%${account.getNs()}`,
|
||||
account,
|
||||
label: <><Icon small material="account_box" /> {name} ({namespace})</>
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@computed get selectedServiceAccountOptions(): ServiceAccountOption[] {
|
||||
return this.serviceAccountOptions.filter(({ account }) => this.selectedAccounts.has(account));
|
||||
}
|
||||
|
||||
@action
|
||||
onOpen = () => {
|
||||
const binding = this.roleBinding;
|
||||
|
||||
if (!binding) {
|
||||
return this.reset();
|
||||
}
|
||||
|
||||
this.selectedRoleRef = (binding.roleRef.kind === roleApi.kind ? rolesStore : clusterRolesStore)
|
||||
.items
|
||||
.find(item => item.getName() === binding.roleRef.name);
|
||||
|
||||
this.bindingName = binding.getName();
|
||||
this.bindingNamespace = binding.getNs();
|
||||
|
||||
const [saSubjects, uSubjects, gSubjects] = nFircate(binding.getSubjects(), "kind", ["ServiceAccount", "User", "Group"]);
|
||||
const accountNames = new Set(saSubjects.map(acc => acc.name));
|
||||
|
||||
this.selectedAccounts.replace(
|
||||
serviceAccountsStore.items
|
||||
.filter(sa => accountNames.has(sa.getName()))
|
||||
);
|
||||
this.selectedUsers.replace(uSubjects.map(user => user.name));
|
||||
this.selectedGroups.replace(gSubjects.map(group => group.name));
|
||||
};
|
||||
|
||||
@action
|
||||
reset = () => {
|
||||
this.selectedRoleRef = undefined;
|
||||
this.bindingName = "";
|
||||
this.bindingNamespace = "";
|
||||
this.selectedAccounts.clear();
|
||||
this.selectedUsers.clear();
|
||||
this.selectedGroups.clear();
|
||||
};
|
||||
|
||||
createBindings = async () => {
|
||||
const { selectedRoleRef, bindingNamespace: namespace, selectedBindings } = this;
|
||||
|
||||
try {
|
||||
const roleBinding = this.isEditing
|
||||
? await roleBindingsStore.updateSubjects(this.roleBinding, selectedBindings)
|
||||
: await roleBindingsStore.create({ name: this.bindingName, namespace }, {
|
||||
subjects: selectedBindings,
|
||||
roleRef: {
|
||||
name: selectedRoleRef.getName(),
|
||||
kind: selectedRoleRef.kind,
|
||||
}
|
||||
});
|
||||
|
||||
showDetails(roleBinding.selfLink);
|
||||
RoleBindingDialog.close();
|
||||
} catch (err) {
|
||||
Notifications.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
renderContents() {
|
||||
return (
|
||||
<>
|
||||
<SubTitle title="Namespace" />
|
||||
<NamespaceSelect
|
||||
themeName="light"
|
||||
isDisabled={this.isEditing}
|
||||
value={this.bindingNamespace}
|
||||
onChange={({ value }) => this.bindingNamespace = value}
|
||||
/>
|
||||
|
||||
<SubTitle title="Role Reference" />
|
||||
<Select
|
||||
themeName="light"
|
||||
placeholder="Select role or cluster role ..."
|
||||
isDisabled={this.isEditing}
|
||||
options={this.roleRefOptions}
|
||||
value={this.selectedRoleRef}
|
||||
onChange={({ value }) => {
|
||||
if (!this.selectedRoleRef || this.bindingName === this.selectedRoleRef.getName()) {
|
||||
this.bindingName = value.getName();
|
||||
}
|
||||
|
||||
this.selectedRoleRef = value;
|
||||
}}
|
||||
/>
|
||||
|
||||
<SubTitle title="Binding Name" />
|
||||
<Input
|
||||
disabled={this.isEditing}
|
||||
value={this.bindingName}
|
||||
onChange={value => this.bindingName = value}
|
||||
/>
|
||||
|
||||
<SubTitle title="Binding targets" />
|
||||
|
||||
<b>Users</b>
|
||||
<EditableList
|
||||
placeholder="Bind to User Account ..."
|
||||
add={(newUser) => this.selectedUsers.add(newUser)}
|
||||
items={Array.from(this.selectedUsers)}
|
||||
remove={({ oldItem }) => this.selectedUsers.delete(oldItem)}
|
||||
/>
|
||||
|
||||
<b>Groups</b>
|
||||
<EditableList
|
||||
placeholder="Bind to User Group ..."
|
||||
add={(newGroup) => this.selectedGroups.add(newGroup)}
|
||||
items={Array.from(this.selectedGroups)}
|
||||
remove={({ oldItem }) => this.selectedGroups.delete(oldItem)}
|
||||
/>
|
||||
|
||||
<b>Service Accounts</b>
|
||||
<Select
|
||||
isMulti
|
||||
themeName="light"
|
||||
placeholder="Select service accounts ..."
|
||||
autoConvertOptions={false}
|
||||
options={this.serviceAccountOptions}
|
||||
value={this.selectedServiceAccountOptions}
|
||||
onChange={(selected: ServiceAccountOption[] | null) => {
|
||||
if (selected) {
|
||||
this.selectedAccounts.replace(selected.map(opt => opt.account));
|
||||
} else {
|
||||
this.selectedAccounts.clear();
|
||||
}
|
||||
}}
|
||||
maxMenuHeight={200}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { ...dialogProps } = this.props;
|
||||
const [action, nextLabel] = this.isEditing ? ["Edit", "Update"] : ["Add", "Create"];
|
||||
const disableNext = !this.selectedRoleRef || !this.selectedBindings.length || !this.bindingNamespace || !this.bindingName;
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
{...dialogProps}
|
||||
className="AddRoleBindingDialog"
|
||||
isOpen={RoleBindingDialog.state.isOpen}
|
||||
close={RoleBindingDialog.close}
|
||||
onClose={this.reset}
|
||||
onOpen={this.onOpen}
|
||||
>
|
||||
<Wizard
|
||||
header={<h5>{action} RoleBinding</h5>}
|
||||
done={RoleBindingDialog.close}
|
||||
>
|
||||
<WizardStep
|
||||
nextLabel={nextLabel}
|
||||
next={this.createBindings}
|
||||
disabledNext={disableNext}
|
||||
>
|
||||
{this.renderContents()}
|
||||
</WizardStep>
|
||||
</Wizard>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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 { MD5 } from "crypto-js";
|
||||
import type { RoleBindingSubject } from "../../../api/endpoints";
|
||||
|
||||
export function hashRoleBindingSubject(subject: RoleBindingSubject): string {
|
||||
return MD5(JSON.stringify([
|
||||
["kind", subject.kind],
|
||||
["name", subject.name],
|
||||
["namespace", subject.namespace],
|
||||
["apiGroup", subject.apiGroup],
|
||||
])).toString();
|
||||
}
|
||||
@@ -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 "./dialog";
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* 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 { RoleBinding, roleBindingApi, RoleBindingSubject } from "../../../api/endpoints";
|
||||
import { KubeObjectStore } from "../../../kube-object.store";
|
||||
import { HashSet } from "../../../utils";
|
||||
import { hashRoleBindingSubject } from "./hashers";
|
||||
|
||||
export class RoleBindingsStore extends KubeObjectStore<RoleBinding> {
|
||||
api = roleBindingApi;
|
||||
|
||||
protected sortItems(items: RoleBinding[]) {
|
||||
return super.sortItems(items, [
|
||||
roleBinding => roleBinding.kind,
|
||||
roleBinding => roleBinding.getName()
|
||||
]);
|
||||
}
|
||||
|
||||
protected async createItem(params: { name: string; namespace: string }, data?: Partial<RoleBinding>) {
|
||||
return roleBindingApi.create(params, data);
|
||||
}
|
||||
|
||||
async updateSubjects(roleBinding: RoleBinding, subjects: RoleBindingSubject[]) {
|
||||
return this.update(roleBinding, {
|
||||
roleRef: roleBinding.roleRef,
|
||||
subjects,
|
||||
});
|
||||
}
|
||||
|
||||
async removeSubjects(roleBinding: RoleBinding, subjectsToRemove: Iterable<RoleBindingSubject>) {
|
||||
const currentSubjects = new HashSet(roleBinding.getSubjects(), hashRoleBindingSubject);
|
||||
|
||||
for (const subject of subjectsToRemove) {
|
||||
currentSubjects.delete(subject);
|
||||
}
|
||||
|
||||
return this.updateSubjects(roleBinding, currentSubjects.toJSON());
|
||||
}
|
||||
}
|
||||
|
||||
export const roleBindingsStore = new RoleBindingsStore();
|
||||
|
||||
apiManager.registerStore(roleBindingsStore);
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.RoleBindings {
|
||||
.help-icon {
|
||||
margin-left: $margin / 2;
|
||||
}
|
||||
|
||||
.TableCell {
|
||||
&.warning {
|
||||
@include table-cell-warning;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* 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 { RoleBinding } from "../../../api/endpoints";
|
||||
import { KubeObjectListLayout } from "../../kube-object";
|
||||
import { KubeObjectStatusIcon } from "../../kube-object-status-icon";
|
||||
import type { RoleBindingsRouteParams } from "../user-management.route";
|
||||
import { RoleBindingDialog } from "./dialog";
|
||||
import { roleBindingsStore } from "./store";
|
||||
import { rolesStore } from "../+roles/store";
|
||||
import { clusterRolesStore } from "../+cluster-roles/store";
|
||||
import { serviceAccountsStore } from "../+service-accounts/store";
|
||||
|
||||
enum columnId {
|
||||
name = "name",
|
||||
namespace = "namespace",
|
||||
bindings = "bindings",
|
||||
age = "age",
|
||||
}
|
||||
|
||||
interface Props extends RouteComponentProps<RoleBindingsRouteParams> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class RoleBindings extends React.Component<Props> {
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
<KubeObjectListLayout
|
||||
isConfigurable
|
||||
tableId="access_role_bindings"
|
||||
className="RoleBindings"
|
||||
store={roleBindingsStore}
|
||||
dependentStores={[rolesStore, clusterRolesStore, serviceAccountsStore]}
|
||||
sortingCallbacks={{
|
||||
[columnId.name]: (binding: RoleBinding) => binding.getName(),
|
||||
[columnId.namespace]: (binding: RoleBinding) => binding.getNs(),
|
||||
[columnId.bindings]: (binding: RoleBinding) => binding.getSubjectNames(),
|
||||
[columnId.age]: (binding: RoleBinding) => binding.getTimeDiffFromNow(),
|
||||
}}
|
||||
searchFilters={[
|
||||
(binding: RoleBinding) => binding.getSearchFields(),
|
||||
(binding: RoleBinding) => binding.getSubjectNames(),
|
||||
]}
|
||||
renderHeaderTitle="Role Bindings"
|
||||
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: "Bindings", className: "bindings", sortBy: columnId.bindings, id: columnId.bindings },
|
||||
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
|
||||
]}
|
||||
renderTableContents={(binding: RoleBinding) => [
|
||||
binding.getName(),
|
||||
<KubeObjectStatusIcon key="icon" object={binding} />,
|
||||
binding.getNs(),
|
||||
binding.getSubjectNames(),
|
||||
binding.getAge(),
|
||||
]}
|
||||
addRemoveButtons={{
|
||||
onAdd: () => RoleBindingDialog.open(),
|
||||
addTooltip: "Create new RoleBinding",
|
||||
}}
|
||||
/>
|
||||
<RoleBindingDialog />
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user