Add new extension point for catalog permissions
Signed-off-by: lshwayne96 <lshwayne96@gmail.com>
This commit is contained in:
committed by
Fredrik Adelöw
parent
24ab4464e7
commit
1663303ab8
@@ -3,4 +3,4 @@
|
||||
'@backstage/plugin-catalog-node': minor
|
||||
---
|
||||
|
||||
Permission rules can now be added for the Catalog plugin through the `CatalogProcessingExtensionPoint` interface.
|
||||
Permission rules can now be added for the Catalog plugin through the `CatalogPermissionExtensionPoint` interface.
|
||||
|
||||
@@ -23,6 +23,8 @@ import {
|
||||
catalogAnalysisExtensionPoint,
|
||||
CatalogProcessingExtensionPoint,
|
||||
catalogProcessingExtensionPoint,
|
||||
CatalogPermissionExtensionPoint,
|
||||
catalogPermissionExtensionPoint,
|
||||
} from '@backstage/plugin-catalog-node/alpha';
|
||||
import {
|
||||
CatalogProcessor,
|
||||
@@ -38,7 +40,6 @@ class CatalogProcessingExtensionPointImpl
|
||||
#processors = new Array<CatalogProcessor>();
|
||||
#entityProviders = new Array<EntityProvider>();
|
||||
#placeholderResolvers: Record<string, PlaceholderResolver> = {};
|
||||
#permissionRules = new Array<CatalogPermissionRuleInput>();
|
||||
|
||||
addProcessor(
|
||||
...processors: Array<CatalogProcessor | Array<CatalogProcessor>>
|
||||
@@ -60,14 +61,6 @@ class CatalogProcessingExtensionPointImpl
|
||||
this.#placeholderResolvers[key] = resolver;
|
||||
}
|
||||
|
||||
addPermissionRules(
|
||||
...rules: Array<
|
||||
CatalogPermissionRuleInput | Array<CatalogPermissionRuleInput>
|
||||
>
|
||||
): void {
|
||||
this.#permissionRules.push(...rules.flat());
|
||||
}
|
||||
|
||||
get processors() {
|
||||
return this.#processors;
|
||||
}
|
||||
@@ -79,10 +72,6 @@ class CatalogProcessingExtensionPointImpl
|
||||
get placeholderResolvers() {
|
||||
return this.#placeholderResolvers;
|
||||
}
|
||||
|
||||
get permissionRules() {
|
||||
return this.#permissionRules;
|
||||
}
|
||||
}
|
||||
|
||||
class CatalogAnalysisExtensionPointImpl
|
||||
@@ -99,6 +88,24 @@ class CatalogAnalysisExtensionPointImpl
|
||||
}
|
||||
}
|
||||
|
||||
class CatalogPermissionExtensionPointImpl
|
||||
implements CatalogPermissionExtensionPoint
|
||||
{
|
||||
#permissionRules = new Array<CatalogPermissionRuleInput>();
|
||||
|
||||
addPermissionRules(
|
||||
...rules: Array<
|
||||
CatalogPermissionRuleInput | Array<CatalogPermissionRuleInput>
|
||||
>
|
||||
): void {
|
||||
this.#permissionRules.push(...rules.flat());
|
||||
}
|
||||
|
||||
get permissionRules() {
|
||||
return this.#permissionRules;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Catalog plugin
|
||||
* @alpha
|
||||
@@ -119,6 +126,12 @@ export const catalogPlugin = createBackendPlugin({
|
||||
analysisExtensions,
|
||||
);
|
||||
|
||||
const permissionExtensions = new CatalogPermissionExtensionPointImpl();
|
||||
env.registerExtensionPoint(
|
||||
catalogPermissionExtensionPoint,
|
||||
permissionExtensions,
|
||||
);
|
||||
|
||||
env.registerInit({
|
||||
deps: {
|
||||
logger: coreServices.logger,
|
||||
@@ -155,7 +168,7 @@ export const catalogPlugin = createBackendPlugin({
|
||||
([key, resolver]) => builder.setPlaceholderResolver(key, resolver),
|
||||
);
|
||||
builder.addLocationAnalyzers(...analysisExtensions.locationAnalyzers);
|
||||
builder.addPermissionRules(...processingExtensions.permissionRules);
|
||||
builder.addPermissionRules(...permissionExtensions.permissionRules);
|
||||
|
||||
const { processingEngine, router } = await builder.build();
|
||||
|
||||
|
||||
@@ -23,6 +23,19 @@ export interface CatalogAnalysisExtensionPoint {
|
||||
// @alpha (undocumented)
|
||||
export const catalogAnalysisExtensionPoint: ExtensionPoint<CatalogAnalysisExtensionPoint>;
|
||||
|
||||
// @alpha (undocumented)
|
||||
export interface CatalogPermissionExtensionPoint {
|
||||
// (undocumented)
|
||||
addPermissionRules(
|
||||
...rules: Array<
|
||||
CatalogPermissionRuleInput | Array<CatalogPermissionRuleInput>
|
||||
>
|
||||
): void;
|
||||
}
|
||||
|
||||
// @alpha (undocumented)
|
||||
export const catalogPermissionExtensionPoint: ExtensionPoint<CatalogPermissionExtensionPoint>;
|
||||
|
||||
// @alpha (undocumented)
|
||||
export type CatalogPermissionRuleInput<
|
||||
TParams extends PermissionRuleParams = PermissionRuleParams,
|
||||
@@ -35,12 +48,6 @@ export interface CatalogProcessingExtensionPoint {
|
||||
...providers: Array<EntityProvider | Array<EntityProvider>>
|
||||
): void;
|
||||
// (undocumented)
|
||||
addPermissionRules(
|
||||
...rules: Array<
|
||||
CatalogPermissionRuleInput | Array<CatalogPermissionRuleInput>
|
||||
>
|
||||
): void;
|
||||
// (undocumented)
|
||||
addPlaceholderResolver(key: string, resolver: PlaceholderResolver): void;
|
||||
// (undocumented)
|
||||
addProcessor(
|
||||
|
||||
@@ -23,3 +23,5 @@ export type {
|
||||
EntitiesSearchFilter,
|
||||
CatalogPermissionRuleInput,
|
||||
} from './extensions';
|
||||
export type { CatalogPermissionExtensionPoint } from './extensions';
|
||||
export { catalogPermissionExtensionPoint } from './extensions';
|
||||
|
||||
@@ -14,30 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { PermissionRuleParams } from '@backstage/plugin-permission-common';
|
||||
import { PermissionRule } from '@backstage/plugin-permission-node';
|
||||
import {
|
||||
EntityProvider,
|
||||
CatalogProcessor,
|
||||
PlaceholderResolver,
|
||||
ScmLocationAnalyzer,
|
||||
} from '@backstage/plugin-catalog-node';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export type EntitiesSearchFilter = {
|
||||
key: string;
|
||||
values?: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export type CatalogPermissionRuleInput<
|
||||
TParams extends PermissionRuleParams = PermissionRuleParams,
|
||||
> = PermissionRule<Entity, EntitiesSearchFilter, 'catalog-entity', TParams>;
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { PermissionRuleParams } from '@backstage/plugin-permission-common';
|
||||
import { PermissionRule } from '@backstage/plugin-permission-node';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
@@ -50,11 +35,6 @@ export interface CatalogProcessingExtensionPoint {
|
||||
...providers: Array<EntityProvider | Array<EntityProvider>>
|
||||
): void;
|
||||
addPlaceholderResolver(key: string, resolver: PlaceholderResolver): void;
|
||||
addPermissionRules(
|
||||
...rules: Array<
|
||||
CatalogPermissionRuleInput | Array<CatalogPermissionRuleInput>
|
||||
>
|
||||
): void;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,3 +59,37 @@ export const catalogAnalysisExtensionPoint =
|
||||
createExtensionPoint<CatalogAnalysisExtensionPoint>({
|
||||
id: 'catalog.analysis',
|
||||
});
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export type EntitiesSearchFilter = {
|
||||
key: string;
|
||||
values?: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export type CatalogPermissionRuleInput<
|
||||
TParams extends PermissionRuleParams = PermissionRuleParams,
|
||||
> = PermissionRule<Entity, EntitiesSearchFilter, 'catalog-entity', TParams>;
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export interface CatalogPermissionExtensionPoint {
|
||||
addPermissionRules(
|
||||
...rules: Array<
|
||||
CatalogPermissionRuleInput | Array<CatalogPermissionRuleInput>
|
||||
>
|
||||
): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export const catalogPermissionExtensionPoint =
|
||||
createExtensionPoint<CatalogPermissionExtensionPoint>({
|
||||
id: 'catalog.permission',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user