adr-backend: migrated to support new auth services
Co-authored-by: Fredrik Adelöw <freben@gmail.com> Co-authored-by: Carl-Erik Bergström <cbergstrom@spotify.com> Co-authored-by: blam <ben@blam.sh> Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-adr-backend': patch
|
||||
---
|
||||
|
||||
Migrated `DefaultAdrCollatorFactory` to support new auth services.
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import { AdrDocument } from '@backstage/plugin-adr-common';
|
||||
import { AdrFilePathFilterFn } from '@backstage/plugin-adr-common';
|
||||
import { AuthService } from '@backstage/backend-plugin-api';
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { CacheClient } from '@backstage/backend-common';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
@@ -32,6 +33,7 @@ export type AdrCollatorFactoryOptions = {
|
||||
parser?: AdrParser;
|
||||
reader: UrlReader;
|
||||
tokenManager: TokenManager;
|
||||
auth?: AuthService;
|
||||
};
|
||||
|
||||
// @public
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
PluginEndpointDiscovery,
|
||||
TokenManager,
|
||||
UrlReader,
|
||||
createLegacyAuthAdapters,
|
||||
} from '@backstage/backend-common';
|
||||
import {
|
||||
CatalogApi,
|
||||
@@ -46,6 +47,7 @@ import { DocumentCollatorFactory } from '@backstage/plugin-search-common';
|
||||
|
||||
import { createMadrParser } from './createMadrParser';
|
||||
import { AdrParser } from './types';
|
||||
import { AuthService } from '@backstage/backend-plugin-api';
|
||||
|
||||
/**
|
||||
* Options to configure the AdrCollatorFactory
|
||||
@@ -89,6 +91,10 @@ export type AdrCollatorFactoryOptions = {
|
||||
* Token Manager
|
||||
*/
|
||||
tokenManager: TokenManager;
|
||||
/**
|
||||
* Auth Service
|
||||
*/
|
||||
auth?: AuthService;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -103,8 +109,8 @@ export class DefaultAdrCollatorFactory implements DocumentCollatorFactory {
|
||||
private readonly logger: Logger;
|
||||
private readonly parser: AdrParser;
|
||||
private readonly reader: UrlReader;
|
||||
private readonly auth: AuthService;
|
||||
private readonly scmIntegrations: ScmIntegrationRegistry;
|
||||
private readonly tokenManager: TokenManager;
|
||||
|
||||
private constructor(options: AdrCollatorFactoryOptions) {
|
||||
this.adrFilePathFilterFn =
|
||||
@@ -117,7 +123,8 @@ export class DefaultAdrCollatorFactory implements DocumentCollatorFactory {
|
||||
this.parser = options.parser ?? createMadrParser();
|
||||
this.reader = options.reader;
|
||||
this.scmIntegrations = ScmIntegrations.fromConfig(options.config);
|
||||
this.tokenManager = options.tokenManager;
|
||||
|
||||
this.auth = createLegacyAuthAdapters(options).auth;
|
||||
}
|
||||
|
||||
static fromConfig(options: AdrCollatorFactoryOptions) {
|
||||
@@ -129,7 +136,11 @@ export class DefaultAdrCollatorFactory implements DocumentCollatorFactory {
|
||||
}
|
||||
|
||||
async *execute(): AsyncGenerator<AdrDocument> {
|
||||
const { token } = await this.tokenManager.getToken();
|
||||
const { token } = await this.auth.getPluginRequestToken({
|
||||
onBehalfOf: await this.auth.getOwnServiceCredentials(),
|
||||
targetPluginId: 'catalog',
|
||||
});
|
||||
|
||||
const entities = (
|
||||
await this.catalogClient.getEntities(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user