From 4f5bde47e9a6b011b8b73bf701cd0f19a927782c Mon Sep 17 00:00:00 2001 From: MT Lewis Date: Mon, 17 Jan 2022 18:03:42 +0000 Subject: [PATCH] catalog-backend: support authorization in DefaultCatalogCollator Signed-off-by: MT Lewis --- .changeset/angry-jeans-bow.md | 5 +++++ plugins/catalog-backend/api-report.md | 3 +++ .../src/search/DefaultCatalogCollator.test.ts | 6 ++++++ .../src/search/DefaultCatalogCollator.ts | 11 ++++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .changeset/angry-jeans-bow.md diff --git a/.changeset/angry-jeans-bow.md b/.changeset/angry-jeans-bow.md new file mode 100644 index 0000000000..6f28797c42 --- /dev/null +++ b/.changeset/angry-jeans-bow.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +Add support for permissions to the DefaultCatalogCollator by adding the visibilityPermission prop and including authorization.resourceRef on indexed documents. diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 6cd386c122..deed3e2d8b 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -26,6 +26,7 @@ import { Location as Location_2 } from '@backstage/catalog-model'; import { LocationSpec } from '@backstage/catalog-model'; import { Logger as Logger_2 } from 'winston'; import { Organizations } from 'aws-sdk'; +import { Permission } from '@backstage/plugin-permission-common'; import { PermissionAuthorizer } from '@backstage/plugin-permission-common'; import { PermissionCondition } from '@backstage/plugin-permission-common'; import { PermissionCriteria } from '@backstage/plugin-permission-common'; @@ -539,6 +540,8 @@ export class DefaultCatalogCollator implements DocumentCollator { protected tokenManager: TokenManager; // (undocumented) readonly type: string; + // (undocumented) + readonly visibilityPermission: Permission; } // Warning: (ae-missing-release-tag) "DefaultCatalogProcessingOrchestrator" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts index 1360ca2647..81abb91328 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts @@ -113,6 +113,9 @@ describe('DefaultCatalogCollator', () => { componentType: expectedEntities[0]!.spec!.type, lifecycle: expectedEntities[0]!.spec!.lifecycle, owner: expectedEntities[0]!.spec!.owner, + authorization: { + resourceRef: 'component:default/test-entity', + }, }); expect(documents[1]).toMatchObject({ title: expectedEntities[1].metadata.title, @@ -122,6 +125,9 @@ describe('DefaultCatalogCollator', () => { componentType: expectedEntities[1]!.spec!.type, lifecycle: expectedEntities[1]!.spec!.lifecycle, owner: expectedEntities[1]!.spec!.owner, + authorization: { + resourceRef: 'component:default/test-entity-2', + }, }); }); diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index ebad95e72f..93ef6968d1 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -18,7 +18,11 @@ import { PluginEndpointDiscovery, TokenManager, } from '@backstage/backend-common'; -import { Entity, UserEntity } from '@backstage/catalog-model'; +import { + Entity, + stringifyEntityRef, + UserEntity, +} from '@backstage/catalog-model'; import { IndexableDocument, DocumentCollator } from '@backstage/search-common'; import { Config } from '@backstage/config'; import { @@ -26,6 +30,7 @@ import { CatalogClient, CatalogEntitiesRequest, } from '@backstage/catalog-client'; +import { catalogEntityReadPermission } from '@backstage/plugin-catalog-common'; export interface CatalogEntityDocument extends IndexableDocument { componentType: string; @@ -41,6 +46,7 @@ export class DefaultCatalogCollator implements DocumentCollator { protected filter?: CatalogEntitiesRequest['filter']; protected readonly catalogClient: CatalogApi; public readonly type: string = 'software-catalog'; + public readonly visibilityPermission = catalogEntityReadPermission; protected tokenManager: TokenManager; static fromConfig( @@ -126,6 +132,9 @@ export class DefaultCatalogCollator implements DocumentCollator { kind: entity.kind, lifecycle: (entity.spec?.lifecycle as string) || '', owner: (entity.spec?.owner as string) || '', + authorization: { + resourceRef: stringifyEntityRef(entity), + }, }; }); }