lighthouse to support authenticated catalog api
Signed-off-by: Brian Fletcher <brian@roadie.io>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-lighthouse-backend': minor
|
||||
---
|
||||
|
||||
Lighthouse backend plugin can now use an authenticated catalog backend API.
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user