Introduce permission check in kubernetes frontend

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>
This commit is contained in:
Dominika Zemanovicova
2025-01-08 17:45:01 +01:00
parent 07efa3a8d8
commit 51c1a5f606
8 changed files with 114 additions and 1 deletions
+1
View File
@@ -47,6 +47,7 @@
"@backstage/plugin-catalog-react": "workspace:^",
"@backstage/plugin-kubernetes-common": "workspace:^",
"@backstage/plugin-kubernetes-react": "workspace:^",
"@backstage/plugin-permission-react": "workspace:^",
"@kubernetes-models/apimachinery": "^2.0.0",
"@kubernetes-models/base": "^5.0.0",
"@material-ui/core": "^4.12.2",
@@ -24,6 +24,8 @@ import {
useKubernetesClusterError,
} from '../KubernetesClusterErrorContext/KubernetesClusterErrorContext';
import { WarningPanel } from '@backstage/core-components';
import { useKubernetesClustersPermission } from '../../hooks/useKubernetesClustersPermission';
import { kubernetesClustersPermission } from '@backstage/plugin-kubernetes-common';
const ContentGrid = () => {
const { error } = useKubernetesClusterError();
@@ -57,7 +59,15 @@ const ContentGrid = () => {
* @public
*/
export const KubernetesClusterContent = () => {
return (
const hasKubernetesClustersPermission = useKubernetesClustersPermission();
return !hasKubernetesClustersPermission ? (
<WarningPanel
title="Permission required"
message={`To view Kubernetes objects, contact your administrator to give you the
'${kubernetesClustersPermission.name}' permission.`}
/>
) : (
<KubernetesClusterErrorProvider>
<ContentGrid />
</KubernetesClusterErrorProvider>
@@ -0,0 +1,26 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { kubernetesClustersPermission } from '@backstage/plugin-kubernetes-common';
import { usePermission } from '@backstage/plugin-permission-react';
export const useKubernetesClustersPermission = () => {
const kubernetesClustersPermissionResult = usePermission({
permission: kubernetesClustersPermission,
});
return kubernetesClustersPermissionResult.allowed;
};