lighthouse to support authenticated catalog api

Signed-off-by: Brian Fletcher <brian@roadie.io>
This commit is contained in:
Brian Fletcher
2023-04-06 10:48:38 +01:00
parent 2f0a3e0e6f
commit 7a89555e73
4 changed files with 25 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-lighthouse-backend': minor
---
Lighthouse backend plugin can now use an authenticated catalog backend API.
+8 -2
View File
@@ -19,11 +19,17 @@ import { PluginEnvironment } from '../types';
import { CatalogClient } from '@backstage/catalog-client';
export default async function createPlugin(env: PluginEnvironment) {
const { logger, scheduler, config } = env;
const { logger, scheduler, config, tokenManager } = env;
const catalogClient = new CatalogClient({
discoveryApi: env.discovery,
});
await createScheduler({ logger, scheduler, config, catalogClient });
await createScheduler({
logger,
scheduler,
config,
catalogClient,
tokenManager,
});
}
@@ -18,15 +18,22 @@ import {
CatalogClient,
CATALOG_FILTER_EXISTS,
} from '@backstage/catalog-client';
import { TokenManager } from '@backstage/backend-common';
export async function loadLighthouseEntities(catalogClient: CatalogClient) {
export async function loadLighthouseEntities(
catalogClient: CatalogClient,
tokenManager: TokenManager,
) {
const filter: Record<string, symbol | string> = {
kind: 'Component',
'spec.type': 'website',
['lighthouse.com/website-url']: CATALOG_FILTER_EXISTS,
};
const { token } = await tokenManager.getToken();
return await catalogClient.getEntities({
filter: [filter],
token,
});
}
@@ -31,13 +31,14 @@ export interface CreateLighthouseSchedulerOptions {
config: Config;
scheduler?: PluginTaskScheduler;
catalogClient: CatalogClient;
tokenManager: TokenManager;
}
/** @public **/
export async function createScheduler(
options: CreateLighthouseSchedulerOptions,
) {
const { logger, scheduler, catalogClient, config } = options;
const { logger, scheduler, catalogClient, config, tokenManager } = options;
const lighthouseApi = LighthouseRestApi.fromConfig(config);
const lighthouseAuditConfig = LighthouseAuditScheduleImpl.fromConfig(config);
@@ -77,8 +78,10 @@ export async function createScheduler(
logger.info('Running Lighthouse Audit Task');
const { token } = await tokenManager.getToken();
const websitesWithUrl = await catalogClient.getEntities({
filter: [filter],
token,
});
let index = 0;