tech-insights-backend: added auth service support
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-tech-insights-node': minor
|
||||
---
|
||||
|
||||
**BREAKING**: The `FactRetrieverContext` type now contains an additional `auth` field.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-tech-insights-backend': patch
|
||||
---
|
||||
|
||||
Added support for the new `AuthService`.
|
||||
@@ -3,6 +3,7 @@
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
import { AuthService } from '@backstage/backend-plugin-api';
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { CheckResult } from '@backstage/plugin-tech-insights-common';
|
||||
import { Config } from '@backstage/config';
|
||||
@@ -110,6 +111,8 @@ export interface TechInsightsOptions<
|
||||
CheckType extends TechInsightCheck,
|
||||
CheckResultType extends CheckResult,
|
||||
> {
|
||||
// (undocumented)
|
||||
auth?: AuthService;
|
||||
// (undocumented)
|
||||
config: Config;
|
||||
// (undocumented)
|
||||
|
||||
@@ -102,6 +102,7 @@ export const techInsightsPlugin = createBackendPlugin({
|
||||
logger: coreServices.logger,
|
||||
scheduler: coreServices.scheduler,
|
||||
tokenManager: coreServices.tokenManager,
|
||||
auth: coreServices.auth,
|
||||
},
|
||||
async init({
|
||||
config,
|
||||
@@ -111,6 +112,7 @@ export const techInsightsPlugin = createBackendPlugin({
|
||||
logger,
|
||||
scheduler,
|
||||
tokenManager,
|
||||
auth,
|
||||
}) {
|
||||
const winstonLogger = loggerToWinstonLogger(logger);
|
||||
const factRetrievers: FactRetrieverRegistration[] = Object.entries(
|
||||
@@ -136,6 +138,7 @@ export const techInsightsPlugin = createBackendPlugin({
|
||||
persistenceContext,
|
||||
scheduler,
|
||||
tokenManager,
|
||||
auth,
|
||||
});
|
||||
|
||||
httpRouter.use(
|
||||
|
||||
@@ -32,7 +32,11 @@ import {
|
||||
ServerTokenManager,
|
||||
} from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { TestDatabaseId, TestDatabases } from '@backstage/backend-test-utils';
|
||||
import {
|
||||
TestDatabaseId,
|
||||
TestDatabases,
|
||||
mockServices,
|
||||
} from '@backstage/backend-test-utils';
|
||||
import { TaskScheduler } from '@backstage/backend-tasks';
|
||||
|
||||
jest.setTimeout(60_000);
|
||||
@@ -140,6 +144,7 @@ describe('FactRetrieverEngine', () => {
|
||||
logger: getVoidLogger(),
|
||||
config: ConfigReader.fromConfigs([]),
|
||||
tokenManager: ServerTokenManager.noop(),
|
||||
auth: mockServices.auth(),
|
||||
discovery: {
|
||||
getBaseUrl: (_: string) => Promise.resolve('http://mock.url'),
|
||||
getExternalBaseUrl: (_: string) => Promise.resolve('http://mock.url'),
|
||||
|
||||
+2
@@ -23,6 +23,7 @@ import {
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { GetEntitiesResponse } from '@backstage/catalog-client';
|
||||
import { entityMetadataFactRetriever } from './entityMetadataFactRetriever';
|
||||
import { mockServices } from '@backstage/backend-test-utils';
|
||||
|
||||
const getEntitiesMock = jest.fn();
|
||||
jest.mock('@backstage/catalog-client', () => {
|
||||
@@ -104,6 +105,7 @@ const defaultEntityListResponse: GetEntitiesResponse = {
|
||||
const handlerContext = {
|
||||
discovery,
|
||||
logger: getVoidLogger(),
|
||||
auth: mockServices.auth(),
|
||||
config: ConfigReader.fromConfigs([]),
|
||||
tokenManager: ServerTokenManager.noop(),
|
||||
};
|
||||
|
||||
+5
-6
@@ -47,12 +47,11 @@ export const entityMetadataFactRetriever: FactRetriever = {
|
||||
description: 'The entity has tags in metadata',
|
||||
},
|
||||
},
|
||||
handler: async ({
|
||||
discovery,
|
||||
entityFilter,
|
||||
tokenManager,
|
||||
}: FactRetrieverContext) => {
|
||||
const { token } = await tokenManager.getToken();
|
||||
handler: async ({ discovery, entityFilter, auth }: FactRetrieverContext) => {
|
||||
const { token } = await auth.getPluginRequestToken({
|
||||
onBehalfOf: await auth.getOwnServiceCredentials(),
|
||||
targetPluginId: 'catalog',
|
||||
});
|
||||
const catalogClient = new CatalogClient({
|
||||
discoveryApi: discovery,
|
||||
});
|
||||
|
||||
+2
@@ -23,6 +23,7 @@ import {
|
||||
} from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { GetEntitiesResponse } from '@backstage/catalog-client';
|
||||
import { mockServices } from '@backstage/backend-test-utils';
|
||||
|
||||
const getEntitiesMock = jest.fn();
|
||||
jest.mock('@backstage/catalog-client', () => {
|
||||
@@ -104,6 +105,7 @@ const defaultEntityListResponse: GetEntitiesResponse = {
|
||||
const handlerContext = {
|
||||
discovery,
|
||||
logger: getVoidLogger(),
|
||||
auth: mockServices.auth(),
|
||||
config: ConfigReader.fromConfigs([]),
|
||||
tokenManager: ServerTokenManager.noop(),
|
||||
};
|
||||
|
||||
+5
-6
@@ -45,12 +45,11 @@ export const entityOwnershipFactRetriever: FactRetriever = {
|
||||
description: 'The spec.owner field is set and refers to a group',
|
||||
},
|
||||
},
|
||||
handler: async ({
|
||||
discovery,
|
||||
entityFilter,
|
||||
tokenManager,
|
||||
}: FactRetrieverContext) => {
|
||||
const { token } = await tokenManager.getToken();
|
||||
handler: async ({ discovery, entityFilter, auth }: FactRetrieverContext) => {
|
||||
const { token } = await auth.getPluginRequestToken({
|
||||
onBehalfOf: await auth.getOwnServiceCredentials(),
|
||||
targetPluginId: 'catalog',
|
||||
});
|
||||
const catalogClient = new CatalogClient({
|
||||
discoveryApi: discovery,
|
||||
});
|
||||
|
||||
+2
@@ -23,6 +23,7 @@ import {
|
||||
} from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { GetEntitiesResponse } from '@backstage/catalog-client';
|
||||
import { mockServices } from '@backstage/backend-test-utils';
|
||||
|
||||
const getEntitiesMock = jest.fn();
|
||||
jest.mock('@backstage/catalog-client', () => {
|
||||
@@ -104,6 +105,7 @@ const defaultEntityListResponse: GetEntitiesResponse = {
|
||||
const handlerContext = {
|
||||
discovery,
|
||||
logger: getVoidLogger(),
|
||||
auth: mockServices.auth(),
|
||||
config: ConfigReader.fromConfigs([]),
|
||||
tokenManager: ServerTokenManager.noop(),
|
||||
};
|
||||
|
||||
+5
-6
@@ -43,12 +43,11 @@ export const techdocsFactRetriever: FactRetriever = {
|
||||
description: 'The entity has a TechDocs reference annotation',
|
||||
},
|
||||
},
|
||||
handler: async ({
|
||||
discovery,
|
||||
entityFilter,
|
||||
tokenManager,
|
||||
}: FactRetrieverContext) => {
|
||||
const { token } = await tokenManager.getToken();
|
||||
handler: async ({ discovery, entityFilter, auth }: FactRetrieverContext) => {
|
||||
const { token } = await auth.getPluginRequestToken({
|
||||
onBehalfOf: await auth.getOwnServiceCredentials(),
|
||||
targetPluginId: 'catalog',
|
||||
});
|
||||
const catalogClient = new CatalogClient({
|
||||
discoveryApi: discovery,
|
||||
});
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
PluginDatabaseManager,
|
||||
PluginEndpointDiscovery,
|
||||
TokenManager,
|
||||
createLegacyAuthAdapters,
|
||||
} from '@backstage/backend-common';
|
||||
import {
|
||||
FactChecker,
|
||||
@@ -37,6 +38,7 @@ import {
|
||||
import { initializePersistenceContext } from './persistence';
|
||||
import { CheckResult } from '@backstage/plugin-tech-insights-common';
|
||||
import { PluginTaskScheduler } from '@backstage/backend-tasks';
|
||||
import { AuthService } from '@backstage/backend-plugin-api';
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -82,6 +84,7 @@ export interface TechInsightsOptions<
|
||||
database: PluginDatabaseManager;
|
||||
scheduler: PluginTaskScheduler;
|
||||
tokenManager: TokenManager;
|
||||
auth?: AuthService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,6 +150,12 @@ export const buildTechInsightsContext = async <
|
||||
logger,
|
||||
}));
|
||||
|
||||
const { auth } = createLegacyAuthAdapters({
|
||||
auth: options.auth,
|
||||
tokenManager,
|
||||
discovery,
|
||||
});
|
||||
|
||||
const factRetrieverEngine = await DefaultFactRetrieverEngine.create({
|
||||
scheduler,
|
||||
repository: persistenceContext.techInsightsStore,
|
||||
@@ -156,6 +165,7 @@ export const buildTechInsightsContext = async <
|
||||
discovery,
|
||||
logger,
|
||||
tokenManager,
|
||||
auth,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
import { AuthService } from '@backstage/backend-plugin-api';
|
||||
import { CheckResult } from '@backstage/plugin-tech-insights-common';
|
||||
import { Config } from '@backstage/config';
|
||||
import { DateTime } from 'luxon';
|
||||
@@ -66,6 +67,7 @@ export type FactRetrieverContext = {
|
||||
discovery: PluginEndpointDiscovery;
|
||||
logger: Logger;
|
||||
tokenManager: TokenManager;
|
||||
auth: AuthService;
|
||||
entityFilter?:
|
||||
| Record<string, string | symbol | (string | symbol)[]>[]
|
||||
| Record<string, string | symbol | (string | symbol)[]>;
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
} from '@backstage/backend-common';
|
||||
import { FactSchema } from '@backstage/plugin-tech-insights-common';
|
||||
import { Logger } from 'winston';
|
||||
import { AuthService } from '@backstage/backend-plugin-api';
|
||||
|
||||
/**
|
||||
* A container for facts. The shape of the fact records needs to correspond to the FactSchema with same `ref` value.
|
||||
@@ -92,6 +93,7 @@ export type FactRetrieverContext = {
|
||||
discovery: PluginEndpointDiscovery;
|
||||
logger: Logger;
|
||||
tokenManager: TokenManager;
|
||||
auth: AuthService;
|
||||
entityFilter?:
|
||||
| Record<string, string | symbol | (string | symbol)[]>[]
|
||||
| Record<string, string | symbol | (string | symbol)[]>;
|
||||
|
||||
Reference in New Issue
Block a user