Merge pull request #17277 from RoadieHQ/lighthouse-token
lighthouse to support authenticated catalog api
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
---
|
||||
'@backstage/plugin-lighthouse-backend': minor
|
||||
---
|
||||
|
||||
Lighthouse backend plugin can now use an authenticated catalog backend API.
|
||||
|
||||
- Breaking \* You must now pass the `tokenManager` to the lighthouse `createScheduler`.
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { CatalogClient } from '@backstage/catalog-client';
|
||||
import { Config } from '@backstage/config';
|
||||
import { Logger } from 'winston';
|
||||
import { PluginTaskScheduler } from '@backstage/backend-tasks';
|
||||
import { TokenManager } from '@backstage/backend-common';
|
||||
|
||||
// @public (undocumented)
|
||||
export interface CreateLighthouseSchedulerOptions {
|
||||
@@ -18,6 +19,8 @@ export interface CreateLighthouseSchedulerOptions {
|
||||
logger: Logger;
|
||||
// (undocumented)
|
||||
scheduler?: PluginTaskScheduler;
|
||||
// (undocumented)
|
||||
tokenManager: TokenManager;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -18,15 +18,24 @@ 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,
|
||||
};
|
||||
|
||||
return await catalogClient.getEntities({
|
||||
filter: [filter],
|
||||
});
|
||||
const { token } = await tokenManager.getToken();
|
||||
|
||||
return await catalogClient.getEntities(
|
||||
{
|
||||
filter: [filter],
|
||||
},
|
||||
{ token },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import { Config } from '@backstage/config';
|
||||
import { LighthouseRestApi } from '@backstage/plugin-lighthouse-common';
|
||||
import { stringifyEntityRef } from '@backstage/catalog-model';
|
||||
import { LighthouseAuditScheduleImpl } from '../config';
|
||||
import { TokenManager } from '@backstage/backend-common';
|
||||
|
||||
/** @public **/
|
||||
export interface CreateLighthouseSchedulerOptions {
|
||||
@@ -31,13 +32,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,9 +79,13 @@ export async function createScheduler(
|
||||
|
||||
logger.info('Running Lighthouse Audit Task');
|
||||
|
||||
const websitesWithUrl = await catalogClient.getEntities({
|
||||
filter: [filter],
|
||||
});
|
||||
const { token } = await tokenManager.getToken();
|
||||
const websitesWithUrl = await catalogClient.getEntities(
|
||||
{
|
||||
filter: [filter],
|
||||
},
|
||||
{ token },
|
||||
);
|
||||
|
||||
let index = 0;
|
||||
for (const entity of websitesWithUrl.items) {
|
||||
|
||||
Reference in New Issue
Block a user