techdocs-backend: support authorization in DefaultTechDocsCollator

Signed-off-by: MT Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
MT Lewis
2022-01-17 18:10:56 +00:00
parent 4f5bde47e9
commit 4682340457
5 changed files with 22 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs-backend': patch
---
Add support for permissions to the DefaultTechDocsCollator by adding the visibilityPermission prop and including authorization.resourceRef on indexed documents.
+3
View File
@@ -10,6 +10,7 @@ import express from 'express';
import { GeneratorBuilder } from '@backstage/techdocs-common';
import { Knex } from 'knex';
import { Logger as Logger_2 } from 'winston';
import { Permission } from '@backstage/plugin-permission-common';
import { PluginCacheManager } from '@backstage/backend-common';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { PreparerBuilder } from '@backstage/techdocs-common';
@@ -46,6 +47,8 @@ export class DefaultTechDocsCollator implements DocumentCollator {
protected locationTemplate: string;
// (undocumented)
readonly type: string;
// (undocumented)
readonly visibilityPermission: Permission;
}
// Warning: (ae-missing-release-tag) "OutOfTheBoxDeploymentOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
+1
View File
@@ -37,6 +37,7 @@
"@backstage/config": "^0.1.13",
"@backstage/errors": "^0.2.0",
"@backstage/integration": "^0.7.2",
"@backstage/plugin-catalog-common": "^0.1.1-next.0",
"@backstage/search-common": "^0.2.1",
"@backstage/techdocs-common": "^0.11.4",
"@types/express": "^4.17.6",
@@ -200,6 +200,9 @@ describe('DefaultTechDocsCollator', () => {
owner: '',
kind: entity.kind,
name: entity.metadata.name,
authorization: {
resourceRef: `component:default/${entity.metadata.name}`,
},
});
});
});
@@ -18,13 +18,18 @@ import {
PluginEndpointDiscovery,
TokenManager,
} from '@backstage/backend-common';
import { Entity, RELATION_OWNED_BY } from '@backstage/catalog-model';
import {
Entity,
RELATION_OWNED_BY,
stringifyEntityRef,
} from '@backstage/catalog-model';
import { DocumentCollator } from '@backstage/search-common';
import fetch from 'node-fetch';
import unescape from 'lodash/unescape';
import { Logger } from 'winston';
import pLimit from 'p-limit';
import { Config } from '@backstage/config';
import { catalogEntityReadPermission } from '@backstage/plugin-catalog-common';
import { CatalogApi, CatalogClient } from '@backstage/catalog-client';
import { TechDocsDocument } from '@backstage/techdocs-common';
@@ -59,6 +64,7 @@ export class DefaultTechDocsCollator implements DocumentCollator {
private readonly parallelismLimit: number;
private readonly legacyPathCasing: boolean;
public readonly type: string = 'techdocs';
public readonly visibilityPermission = catalogEntityReadPermission;
/**
* @deprecated use static fromConfig method instead.
@@ -148,6 +154,9 @@ export class DefaultTechDocsCollator implements DocumentCollator {
owner:
entity.relations?.find(r => r.type === RELATION_OWNED_BY)
?.target?.name || '',
authorization: {
resourceRef: stringifyEntityRef(entity),
},
}));
} catch (e) {
this.logger.debug(