Merge pull request #27499 from dzemanov/add-kubernetes-permission

feat(kubernetes): introduce kubernetes permission
This commit is contained in:
Ben Lambert
2025-02-04 13:10:16 +01:00
committed by GitHub
25 changed files with 594 additions and 134 deletions
+17 -3
View File
@@ -10,9 +10,7 @@
]
},
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
"access": "public"
},
"keywords": [
"backstage",
@@ -26,8 +24,23 @@
},
"license": "Apache-2.0",
"sideEffects": false,
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts",
"./package.json": "./package.json"
},
"main": "src/index.ts",
"types": "src/index.ts",
"typesVersions": {
"*": {
"alpha": [
"src/alpha.ts"
],
"package.json": [
"package.json"
]
}
},
"files": [
"dist"
],
@@ -47,6 +60,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",
@@ -0,0 +1,18 @@
## API Report File for "@backstage/plugin-kubernetes-cluster"
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { TranslationRef } from '@backstage/core-plugin-api/alpha';
// @alpha (undocumented)
export const kubernetesClusterTranslationRef: TranslationRef<
'kubernetes-cluster',
{
readonly 'kubernetesClusterContentPage.permissionAlert.message': "To view Kubernetes objects, contact your portal administrator to give you the 'kubernetes.clusters.read' permission.";
readonly 'kubernetesClusterContentPage.permissionAlert.title': 'Permission required';
}
>;
// (No @packageDocumentation comment for this package)
```
+17
View File
@@ -0,0 +1,17 @@
/*
* 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.
*/
export { kubernetesClusterTranslationRef } from './translation';
@@ -24,6 +24,10 @@ import {
useKubernetesClusterError,
} from '../KubernetesClusterErrorContext/KubernetesClusterErrorContext';
import { WarningPanel } from '@backstage/core-components';
import { kubernetesClustersReadPermission } from '@backstage/plugin-kubernetes-common';
import { RequirePermission } from '@backstage/plugin-permission-react';
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
import { kubernetesClusterTranslationRef } from '../../translation';
const ContentGrid = () => {
const { error } = useKubernetesClusterError();
@@ -57,9 +61,21 @@ const ContentGrid = () => {
* @public
*/
export const KubernetesClusterContent = () => {
const { t } = useTranslationRef(kubernetesClusterTranslationRef);
return (
<KubernetesClusterErrorProvider>
<ContentGrid />
</KubernetesClusterErrorProvider>
<RequirePermission
permission={kubernetesClustersReadPermission}
errorPage={
<WarningPanel
title={t('kubernetesClusterContentPage.permissionAlert.title')}
message={t('kubernetesClusterContentPage.permissionAlert.message')}
/>
}
>
<KubernetesClusterErrorProvider>
<ContentGrid />
</KubernetesClusterErrorProvider>
</RequirePermission>
);
};
@@ -0,0 +1,30 @@
/*
* 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 { createTranslationRef } from '@backstage/core-plugin-api/alpha';
/** @alpha */
export const kubernetesClusterTranslationRef = createTranslationRef({
id: 'kubernetes-cluster',
messages: {
kubernetesClusterContentPage: {
permissionAlert: {
title: 'Permission required',
message:
"To view Kubernetes objects, contact your portal administrator to give you the 'kubernetes.clusters.read' permission.",
},
},
},
});