From d2ce2bd3f44db357e70a459c407e4e15276479e0 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Sat, 16 Nov 2024 17:31:23 -0700 Subject: [PATCH 1/5] mta - Removed usages and references of `@backstage/backend-common` Signed-off-by: Andre Wanlin --- .../mta/.changeset/fuzzy-lizards-notice.md | 7 + workspaces/mta/packages/backend/package.json | 1 - .../mta/packages/backend/src/index.test.ts | 8 - workspaces/mta/packages/backend/src/types.ts | 25 --- .../package.json | 4 +- .../src/module.ts | 7 +- .../src/provider/MTAEntityProvider.ts | 191 +----------------- .../mta/plugins/mta-backend/api-report.md | 12 +- .../mta/plugins/mta-backend/package.json | 2 - .../mta-backend/src/database/storage.ts | 11 +- .../mta/plugins/mta-backend/src/plugin.ts | 47 +---- .../plugins/mta-backend/src/service/router.ts | 52 ++--- .../api-report.md | 2 +- .../package.json | 1 - .../src/module.ts | 9 +- workspaces/mta/yarn.lock | 80 +------- 16 files changed, 61 insertions(+), 398 deletions(-) create mode 100644 workspaces/mta/.changeset/fuzzy-lizards-notice.md delete mode 100644 workspaces/mta/packages/backend/src/index.test.ts delete mode 100644 workspaces/mta/packages/backend/src/types.ts diff --git a/workspaces/mta/.changeset/fuzzy-lizards-notice.md b/workspaces/mta/.changeset/fuzzy-lizards-notice.md new file mode 100644 index 0000000000..e4238a69d6 --- /dev/null +++ b/workspaces/mta/.changeset/fuzzy-lizards-notice.md @@ -0,0 +1,7 @@ +--- +'@backstage-community/backstage-plugin-catalog-backend-module-mta-entity-provider': patch +'@backstage-community/backstage-plugin-scaffolder-backend-module-mta': patch +'@backstage-community/backstage-plugin-mta-backend': patch +--- + +Removed usages and references of `@backstage/backend-common` diff --git a/workspaces/mta/packages/backend/package.json b/workspaces/mta/packages/backend/package.json index bd4ce015f7..be3c8537d5 100644 --- a/workspaces/mta/packages/backend/package.json +++ b/workspaces/mta/packages/backend/package.json @@ -24,7 +24,6 @@ "@backstage-community/backstage-plugin-catalog-backend-module-mta-entity-provider": "workspace:^", "@backstage-community/backstage-plugin-mta-backend": "workspace:^", "@backstage-community/backstage-plugin-scaffolder-backend-module-mta": "workspace:^", - "@backstage/backend-common": "^0.21.7", "@backstage/backend-defaults": "^0.3.3", "@backstage/backend-dynamic-feature-service": "^0.2.15", "@backstage/backend-tasks": "^0.5.22", diff --git a/workspaces/mta/packages/backend/src/index.test.ts b/workspaces/mta/packages/backend/src/index.test.ts deleted file mode 100644 index 7814b8cadf..0000000000 --- a/workspaces/mta/packages/backend/src/index.test.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PluginEnvironment } from './types'; - -describe('test', () => { - it('unbreaks the test runner', () => { - const unbreaker = {} as PluginEnvironment; - expect(unbreaker).toBeTruthy(); - }); -}); diff --git a/workspaces/mta/packages/backend/src/types.ts b/workspaces/mta/packages/backend/src/types.ts deleted file mode 100644 index 9cd2c74be3..0000000000 --- a/workspaces/mta/packages/backend/src/types.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Logger } from 'winston'; -import { Config } from '@backstage/config'; -import { - PluginCacheManager, - PluginDatabaseManager, - PluginEndpointDiscovery, - TokenManager, - UrlReader, -} from '@backstage/backend-common'; -import { PluginTaskScheduler } from '@backstage/backend-tasks'; -import { PermissionEvaluator } from '@backstage/plugin-permission-common'; -import { IdentityApi } from '@backstage/plugin-auth-node'; - -export type PluginEnvironment = { - logger: Logger; - database: PluginDatabaseManager; - cache: PluginCacheManager; - config: Config; - reader: UrlReader; - discovery: PluginEndpointDiscovery; - tokenManager: TokenManager; - scheduler: PluginTaskScheduler; - permissions: PermissionEvaluator; - identity: IdentityApi; -}; diff --git a/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/package.json b/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/package.json index 106f5dd085..22b01354e3 100644 --- a/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/package.json +++ b/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/package.json @@ -31,15 +31,13 @@ "tsc": "tsc" }, "dependencies": { - "@backstage/backend-common": "^0.23.3", "@backstage/backend-dynamic-feature-service": "^0.2.15", "@backstage/backend-plugin-api": "^0.6.18", "@backstage/catalog-model": "^1.5.0", "@backstage/config": "^1.2.0", "@backstage/plugin-catalog-common": "^1.0.22", "@backstage/plugin-catalog-node": "^1.12.4", - "openid-client": "^5.6.5", - "winston": "^3.13.0" + "openid-client": "^5.6.5" }, "devDependencies": { "@backstage/backend-test-utils": "^0.3.6", diff --git a/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/src/module.ts b/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/src/module.ts index 8e7596df76..379cb0e26f 100644 --- a/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/src/module.ts +++ b/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/src/module.ts @@ -3,7 +3,6 @@ import { createBackendModule, } from '@backstage/backend-plugin-api'; import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha'; -import { loggerToWinstonLogger } from '@backstage/backend-common'; import { MTAProvider } from './provider/MTAEntityProvider'; /** * A backend module that integrates with the catalog to provide MTA entities. @@ -22,11 +21,7 @@ export const catalogModuleMtaEntityProvider = createBackendModule({ }, async init({ config, catalog, logger, scheduler }) { catalog.addEntityProvider( - MTAProvider.newProvider( - config, - loggerToWinstonLogger(logger), - scheduler, - ), + MTAProvider.newProvider(config, logger, scheduler), ); }, }); diff --git a/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/src/provider/MTAEntityProvider.ts b/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/src/provider/MTAEntityProvider.ts index 6bd4a4cc1a..3568bcb2aa 100644 --- a/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/src/provider/MTAEntityProvider.ts +++ b/workspaces/mta/plugins/catalog-backend-module-mta-entity-provider/src/provider/MTAEntityProvider.ts @@ -4,21 +4,20 @@ import { EntityProvider, EntityProviderConnection, } from '@backstage/plugin-catalog-node'; -import { Logger } from 'winston'; -import { SchedulerService } from '@backstage/backend-plugin-api'; -// +import { LoggerService, SchedulerService } from '@backstage/backend-plugin-api'; + /** - * Provides entities from fictional frobs service. + * Provides entities from MTA service. */ export class MTAProvider implements EntityProvider { private connection?: EntityProviderConnection; private readonly config: Config; - private readonly logger: Logger; + private readonly logger: LoggerService; private readonly scheduler: SchedulerService; static newProvider( config: Config, - logger: Logger, + logger: LoggerService, scheduler: SchedulerService, ): MTAProvider { const p = new MTAProvider(config, logger, scheduler); @@ -31,20 +30,22 @@ export class MTAProvider implements EntityProvider { return p; } - /** [1] */ - constructor(config: Config, logger: Logger, scheduler: SchedulerService) { + + constructor( + config: Config, + logger: LoggerService, + scheduler: SchedulerService, + ) { this.config = config; this.logger = logger; this.scheduler = scheduler; this.run = this.run.bind(this); } - /** [2] */ getProviderName(): string { return `MTAProvider`; } - /** [3] */ async connect(connection: EntityProviderConnection): Promise { this.logger.info('connecting'); this.connection = connection; @@ -83,63 +84,7 @@ export class MTAProvider implements EntityProvider { } } - // if (!this.connection) { - // throw new Error('Not initialized'); - // } - // this.logger.info('here'); async authenticate() { - // try { - // // const baseURLAuth = `${this.config.getString( - // // 'mta.url', - // // )}/auth/realms/${this.config.getString('mta.providerAuth.realm')}`; - // const baseUrl = this.config.getString('mta.url'); - // const baseUrlHub = `${baseUrl}/hub`; - // const baseUrlMta = `${baseUrl}`; - // const realm = this.config.getString('mta.providerAuth.realm'); - // const clientID = this.config.getString('mta.providerAuth.clientID'); - // const secret = this.config.getString('mta.providerAuth.secret'); - // const baseURLAuth = `${baseUrl}/auth/realms/${realm}`; - // this.logger.info(`Discovering issuer from ${baseURLAuth}`); - - // // const mtaAuthIssuer = await Issuer.discover(baseURLAuth); - // custom.setHttpOptionsDefaults({ - // timeout: 5000, // Adjust the timeout to 5000ms or higher based on your requirements - // }); - - // try { - // const mtaAuthIssuer = await Issuer.discover(baseURLAuth); - // this.logger.info('Issuer discovered successfully'); - - // const authClient = new mtaAuthIssuer.Client({ - // client_id: this.config.getString('mta.providerAuth.clientID'), - // client_secret: this.config.getString('mta.providerAuth.secret'), - // response_types: ['code'], - // }); - - // this.logger.info('Client created successfully'); - - // const code_verifier = generators.codeVerifier(); - // const code_challenge = generators.codeChallenge(code_verifier); - - // this.logger.info('Attempting to obtain grant'); - - // const grant = await authClient.grant({ - // grant_type: 'client_credentials', - // }); - - // this.logger.info('Grant obtained successfully'); - - // return grant; - // } catch (error) { - // this.logger.error( - // `Initial discovery failed: ${error.message}, retrying...`, - // ); - // // Implement retry logic here - // } - // } catch (error) { - // this.logger.error(`Authentication error: ${error.message}`); - // throw new Error(`Failed to authenticate: ${error.message}`); - // } const baseUrl = this.config.getString('mta.url'); const realm = this.config.getString('mta.providerAuth.realm'); const clientID = this.config.getString('mta.providerAuth.clientID'); @@ -297,117 +242,3 @@ export class MTAProvider implements EntityProvider { this.logger.info('Data refresh triggered for entities.'); } } - -// const getResponse = await fetch(`${baseUrlHub}/applications`, { -// credentials: 'include', -// headers: { -// Accept: 'application/json, text/plain, */*', -// Authorization: `Bearer ${tokenSet.access_token}`, -// }, -// method: 'GET', -// }); - -// if (getResponse.status !== 200) { -// this.logger.info( -// `unable to call hub ${getResponse.status} message ${JSON.stringify( -// await getResponse.text(), -// )}`, -// ); -// return; -// } -// const j = await getResponse.json(); -// if (!Array.isArray(j)) { -// this.logger.info('expecting array of applications'); -// return; -// } - -// this.logger.info(`status: ${getResponse.status} json ${JSON.stringify(j)}`); -// mapApplicationToEntity - -// await this.connection -// .applyMutation({ -// type: 'full', -// entities: j.map(application => { -// const name = application.name.replace(/ /g, '-'); -// const encodedAppName = encodeURIComponent( -// JSON.stringify(application.name), -// ); // Ensure the application name is URI-encoded -// const issuesUrl = `${baseUrlMta}/issues?i%3Afilters=%7B%22application.name%22%3A%5B${encodedAppName}%5D%7D&i%3AitemsPerPage=10&i%3ApageNumber=1&i%3AsortColumn=description&i%3AsortDirection=asc`; - -// return { -// key: application.id, -// locationKey: this.getProviderName(), -// entity: { -// apiVersion: 'backstage.io/v1alpha1', -// kind: 'Component', -// metadata: { -// annotations: { -// 'backstage.io/managed-by-location': `url:${baseUrlMta}/application/${application.id}`, -// 'backstage.io/managed-by-origin-location': `url:${baseUrlMta}/application/${application.id}`, -// 'issues-url': `${issuesUrl}`, -// }, -// name: name, -// id: application.id, -// namespace: 'default', -// application: application, -// }, -// spec: { -// type: 'service', -// lifecycle: 'experimental', -// owner: 'unknown', -// }, -// }, -// }; -// }), -// }) -// .then(() => { -// console.log('REFRESHING'); -// this.logger.info('refreshing'); -// this.connection?.refresh({ -// keys: j.map(application => application.id), -// }); -// }) -// .catch(e => { -// this.logger.info(`error applying mutation ${e}`); -// }); -// } -// } -// const baseUrl = this.config.getString('mta.url'); -// const baseUrlHub = `${baseUrl}/hub`; -// const baseUrlMta = `${baseUrl}`; -// const realm = this.config.getString('mta.providerAuth.realm'); -// const clientID = this.config.getString('mta.providerAuth.clientID'); -// const secret = this.config.getString('mta.providerAuth.secret'); -// const baseURLAuth = `${baseUrl}/auth/realms/${realm}`; -// const mtaAuthIssuer = await Issuer.discover(baseURLAuth); -// const authClient = new mtaAuthIssuer.Client({ -// client_id: clientID, -// client_secret: secret, -// response_types: ['code'], -// }); -// const code_verifier = generators.codeVerifier(); -// const code_challenge = generators.codeChallenge(code_verifier); - -// const tokenSet = await authClient.grant({ -// grant_type: 'client_credentials', -// }); -// if (!tokenSet.access_token) { -// this.logger.info('unable to access hub'); -// } - -// console.log({ -// code_verifier, -// code_challenge, -// tokenSet, -// baseURLAuth, -// baseUrlHub, -// }); - -// this.logger.info({ -// code_verifier, -// code_challenge, -// tokenSet, -// baseURLAuth, -// baseUrlHub, -// }); -// } diff --git a/workspaces/mta/plugins/mta-backend/api-report.md b/workspaces/mta/plugins/mta-backend/api-report.md index 5113b3c59e..a115a5aa5a 100644 --- a/workspaces/mta/plugins/mta-backend/api-report.md +++ b/workspaces/mta/plugins/mta-backend/api-report.md @@ -5,12 +5,12 @@ ```ts import { BackendFeatureCompat } from '@backstage/backend-plugin-api'; +import { CacheService } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; +import { DatabaseService } from '@backstage/backend-plugin-api'; import express from 'express'; import { HttpAuthService } from '@backstage/backend-plugin-api'; -import { Logger } from 'winston'; -import { PluginCacheManager } from '@backstage/backend-common'; -import { PluginDatabaseManager } from '@backstage/backend-common'; +import { LoggerService } from '@backstage/backend-plugin-api'; import { UserInfoService } from '@backstage/backend-plugin-api'; // @public (undocumented) @@ -23,15 +23,15 @@ export default mtaPlugin; // @public (undocumented) export interface RouterOptions { // (undocumented) - cache: PluginCacheManager; + cache: CacheService; // (undocumented) config: Config; // (undocumented) - database: PluginDatabaseManager; + database: DatabaseService; // (undocumented) httpAuth: HttpAuthService; // (undocumented) - logger: Logger; + logger: LoggerService; // (undocumented) userInfo: UserInfoService; } diff --git a/workspaces/mta/plugins/mta-backend/package.json b/workspaces/mta/plugins/mta-backend/package.json index 2c4ad8686d..55b702cbaf 100644 --- a/workspaces/mta/plugins/mta-backend/package.json +++ b/workspaces/mta/plugins/mta-backend/package.json @@ -32,7 +32,6 @@ "tsc": "tsc" }, "dependencies": { - "@backstage/backend-common": "^0.23.3", "@backstage/backend-dynamic-feature-service": "^0.2.15", "@backstage/backend-plugin-api": "^0.8.0", "@backstage/config": "^1.2.0", @@ -46,7 +45,6 @@ "knex": "^3.1.0", "node-fetch": "^2.6.7", "openid-client": "^5.6.4", - "winston": "^3.2.1", "yn": "^4.0.0" }, "devDependencies": { diff --git a/workspaces/mta/plugins/mta-backend/src/database/storage.ts b/workspaces/mta/plugins/mta-backend/src/database/storage.ts index ba767c034d..066d26750e 100644 --- a/workspaces/mta/plugins/mta-backend/src/database/storage.ts +++ b/workspaces/mta/plugins/mta-backend/src/database/storage.ts @@ -1,8 +1,10 @@ -import { resolvePackagePath } from '@backstage/backend-common'; import { Knex } from 'knex'; -import { Logger } from 'winston'; import path from 'path'; import dotenv from 'dotenv'; +import { + LoggerService, + resolvePackagePath, +} from '@backstage/backend-plugin-api'; const ENTITY_APPLICATION_TABLE = 'entity-application-mapping'; const OAUTH_MAPPING_TABLE = 'oauth-mapping'; @@ -50,12 +52,12 @@ export class DataBaseEntityApplicationStorage { public constructor( private readonly knex: Knex, - private readonly logger: Logger, + private readonly logger: LoggerService, ) {} static async create( knex: Knex, - logger: Logger, + logger: LoggerService, ): Promise { logger.info('Starting to migrate database'); await knex.migrate.latest({ @@ -93,7 +95,6 @@ export class DataBaseEntityApplicationStorage entityID: string, applicationID: string, ): Promise { - // this.logger.info('saving in storage: ' + entityID + ' ' + applicatonID); this.logger.info(`saving in storage: ${entityID} ${applicationID}`); if (!entityID || !applicationID) { diff --git a/workspaces/mta/plugins/mta-backend/src/plugin.ts b/workspaces/mta/plugins/mta-backend/src/plugin.ts index 20eb5737a8..02a06fe12a 100644 --- a/workspaces/mta/plugins/mta-backend/src/plugin.ts +++ b/workspaces/mta/plugins/mta-backend/src/plugin.ts @@ -1,22 +1,9 @@ -// plugins/example-backend/src/plugin.ts -// import { MTAProvider } from '../../catalog-backend-module-mta/src/provider/MTAEntityProvider'; - -// eslint-disable-next-line @backstage/no-relative-monorepo-imports -// import { MTAProvider } from '../../catalog-backend-module-mta/src/provider/MTAEntityProvider'; - -// import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha'; import { coreServices, createBackendPlugin, - // createBackendModule, - // HttpRouterService, HttpRouterServiceAuthPolicy, } from '@backstage/backend-plugin-api'; import { createRouter } from './service/router'; -import { - cacheToPluginCacheManager, - loggerToWinstonLogger, -} from '@backstage/backend-common'; /** @public */ export const mtaPlugin = createBackendPlugin({ @@ -41,21 +28,16 @@ export const mtaPlugin = createBackendPlugin({ userInfo, cache, }) { - logger.info('Hello from example plugin'); - const winstonLogger = loggerToWinstonLogger(logger); + logger.info(`Url: ${config.getString('mta.url')}`); - winstonLogger.info(`Url: ${config.getString('mta.url')}`); - - const pluginCacheManager = cacheToPluginCacheManager(cache); - // http.addAuthPolicy({ path: '/api/mta/*', allow: 'unauthenticated' }); const policyConfig: HttpRouterServiceAuthPolicy = { path: '/api/mta/cb/:rest', allow: 'unauthenticated', }; httpRouter.use( await createRouter({ - logger: winstonLogger, - cache: pluginCacheManager, + logger, + cache, httpAuth, database, config, @@ -63,29 +45,6 @@ export const mtaPlugin = createBackendPlugin({ }), ); httpRouter.addAuthPolicy(policyConfig); - - // httpRouter.use((req, res, next) => { - // if (req.path.startsWith('/api/mta/cb/:username')) { - // // Bypassing authentication for specific callback route - // next(); - // } else { - // // Apply authentication middleware - // // authenticateRequest(req, res, next); - // } - // }); - - // function authenticateRequest(req, res, next) { - // const token = req.headers.authorization?.split(' ')[1]; - // if (!token) { - // return res.status(401).json({ error: 'No token provided' }); - // } - // // Proceed with token verification and identity setting - // verifyToken(token, identity, (err) => { - // if (err) { - // return res.status(401).json({ error: 'Unauthorized' }); - // } - // next(); - // }); }, }); }, diff --git a/workspaces/mta/plugins/mta-backend/src/service/router.ts b/workspaces/mta/plugins/mta-backend/src/service/router.ts index d5bff92b84..47a112e815 100644 --- a/workspaces/mta/plugins/mta-backend/src/service/router.ts +++ b/workspaces/mta/plugins/mta-backend/src/service/router.ts @@ -1,27 +1,24 @@ -import { errorHandler } from '@backstage/backend-common'; import express, { Router } from 'express'; -import { - PluginCacheManager, - PluginDatabaseManager, -} from '@backstage/backend-common'; import { Config } from '@backstage/config'; -import { Logger } from 'winston'; import { Issuer, generators } from 'openid-client'; import { isTokenExpired } from '../utils'; import { DataBaseEntityApplicationStorage } from '../database/storage'; import { + CacheService, + DatabaseService, HttpAuthService, + LoggerService, UserInfoService, } from '@backstage/backend-plugin-api'; /** @public */ export interface RouterOptions { - logger: Logger; - database: PluginDatabaseManager; + logger: LoggerService; + database: DatabaseService; httpAuth: HttpAuthService; config: Config; userInfo: UserInfoService; - cache: PluginCacheManager; + cache: CacheService; } /** @public */ @@ -33,7 +30,7 @@ export async function createRouter( const dbClient = await database.getClient(); const entityApplicationStorage = await DataBaseEntityApplicationStorage.create(dbClient, logger); - const cacheClient = await cache.getClient(); + const cacheClient = cache; const frontEndBaseURL = config.getString('app.baseUrl'); const backstageBaseURL = config.getString('backend.baseUrl'); const baseUrl = config.getString('mta.url'); @@ -98,12 +95,9 @@ export async function createRouter( logger.info( `backstageID id for userEntityRef: ${backstageID?.userEntityRef}`, ); - logger.info({ - backstageBaseURL, - frontEndBaseURL, - requestHeaders: request.headers, - referer: request.headers.referer, - }); + logger.info( + `${backstageBaseURL}, ${frontEndBaseURL}, requestHeaders: ${request.headers}, referer: ${request.headers.referer}`, + ); const id = backstageID?.userEntityRef ?? 'undefined'; const u = new URL(`${backstageBaseURL}/api/mta/cb/${id}`); const org = request.headers.referer; @@ -356,7 +350,7 @@ export async function createRouter( response.json(entities); } catch (error) { - logger.error('Failed to fetch entities:', error); + logger.error('Failed to fetch entities:', error as Error); response.status(500).json({ error: 'Failed to fetch entities' }); } @@ -370,7 +364,7 @@ export async function createRouter( const { entityID, applicationID } = request.body; try { - logger.info('Attempting to save:', entityID, applicationID); + logger.info(`Attempting to save: ${entityID} ${applicationID}`); const res = await entityApplicationStorage.saveApplicationIDForEntity( entityID, applicationID, @@ -380,10 +374,10 @@ export async function createRouter( response.status(500).json({ error: 'Failed to save data' }); return; } - logger.info('Successfully saved:', entityID, applicationID); + logger.info(`Successfully saved: ${entityID} ${applicationID}`); response.status(201).json({ entityID, applicationID }); } catch (error) { - logger.error('Error in /application/entity:', error); + logger.error('Error in /application/entity:', error as Error); response.status(500).json({ error: 'Internal Server Error' }); } }); @@ -403,7 +397,7 @@ export async function createRouter( const status = await (await getResponse).status; if (status !== 200) { - logger.error('response does not make sense %s', getResponse); + logger.error(`response does not make sense ${await getResponse}`); response.status(status); response.json({ status: status }); return; @@ -457,10 +451,7 @@ export async function createRouter( const { application, targetList } = analysisOptions; logger.info( - 'Received request to analyze application:', - applicationId, - 'with options:', - analysisOptions, + `Received request to analyze application: ${applicationId} with options: ${analysisOptions}`, ); const TASKGROUPS = `${baseURLHub}/taskgroups`; @@ -591,11 +582,6 @@ export async function createRouter( taskgroupResponse.data.rules = { labels: { excluded: [], - // included: [ - // 'konveyor.io/target=eap8', - // 'konveyor.io/target=cloud-readiness', - // 'konveyor.io/target=quarkus', - // ], included: targetList, }, }; @@ -607,9 +593,8 @@ export async function createRouter( await new Promise(resolve => setTimeout(resolve, 1000)); } catch (error: any) { logger.error( - 'Error during analysis of application:', - applicationId, - error, + `Error during analysis of application: ${applicationId}`, + error as Error, ); response .status(500) @@ -618,7 +603,6 @@ export async function createRouter( }, ); - router.use(errorHandler()); return router; } diff --git a/workspaces/mta/plugins/scaffolder-backend-module-mta/api-report.md b/workspaces/mta/plugins/scaffolder-backend-module-mta/api-report.md index a7c4695284..5915549b91 100644 --- a/workspaces/mta/plugins/scaffolder-backend-module-mta/api-report.md +++ b/workspaces/mta/plugins/scaffolder-backend-module-mta/api-report.md @@ -16,7 +16,7 @@ branch: string; rootPath: string; }, JsonObject>; -// @public (undocumented) +// @public const mtaScaffolderModule: BackendFeatureCompat; export default mtaScaffolderModule; diff --git a/workspaces/mta/plugins/scaffolder-backend-module-mta/package.json b/workspaces/mta/plugins/scaffolder-backend-module-mta/package.json index 7f57370ac4..e5e04b56ab 100644 --- a/workspaces/mta/plugins/scaffolder-backend-module-mta/package.json +++ b/workspaces/mta/plugins/scaffolder-backend-module-mta/package.json @@ -30,7 +30,6 @@ "postpack": "backstage-cli package postpack" }, "dependencies": { - "@backstage/backend-common": "^0.21.6", "@backstage/backend-dynamic-feature-service": "^0.2.15", "@backstage/backend-plugin-api": "^0.6.17", "@backstage/catalog-client": "^1.6.5", diff --git a/workspaces/mta/plugins/scaffolder-backend-module-mta/src/module.ts b/workspaces/mta/plugins/scaffolder-backend-module-mta/src/module.ts index 6710a40a4c..281eb00222 100644 --- a/workspaces/mta/plugins/scaffolder-backend-module-mta/src/module.ts +++ b/workspaces/mta/plugins/scaffolder-backend-module-mta/src/module.ts @@ -4,11 +4,12 @@ import { } from '@backstage/backend-plugin-api'; import { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha'; import { createMTAApplicationAction } from './actions/mta/create-application'; -import { loggerToWinstonLogger } from '@backstage/backend-common'; -/* + +/** * A backend module that integrates with the scaffolder to provide MTA application creation. + * + * @public */ -/** @public */ export const mtaScaffolderModule = createBackendModule({ pluginId: 'scaffolder', moduleId: 'mta', @@ -23,7 +24,7 @@ export const mtaScaffolderModule = createBackendModule({ async init({ scaffolder, config, logger, discovery }) { const createAction = createMTAApplicationAction({ config: config, - logger: loggerToWinstonLogger(logger), + logger: logger, discovery, }); scaffolder.addActions(createAction); diff --git a/workspaces/mta/yarn.lock b/workspaces/mta/yarn.lock index 7dd3f070b4..cb67f17537 100644 --- a/workspaces/mta/yarn.lock +++ b/workspaces/mta/yarn.lock @@ -2675,7 +2675,6 @@ __metadata: version: 0.0.0-use.local resolution: "@backstage-community/backstage-plugin-catalog-backend-module-mta-entity-provider@workspace:plugins/catalog-backend-module-mta-entity-provider" dependencies: - "@backstage/backend-common": ^0.23.3 "@backstage/backend-dynamic-feature-service": ^0.2.15 "@backstage/backend-plugin-api": ^0.6.18 "@backstage/backend-test-utils": ^0.3.6 @@ -2685,7 +2684,6 @@ __metadata: "@backstage/plugin-catalog-common": ^1.0.22 "@backstage/plugin-catalog-node": ^1.12.4 openid-client: ^5.6.5 - winston: ^3.13.0 languageName: unknown linkType: soft @@ -2693,7 +2691,6 @@ __metadata: version: 0.0.0-use.local resolution: "@backstage-community/backstage-plugin-mta-backend@workspace:plugins/mta-backend" dependencies: - "@backstage/backend-common": ^0.23.3 "@backstage/backend-defaults": ^0.5.0 "@backstage/backend-dynamic-feature-service": ^0.2.15 "@backstage/backend-plugin-api": ^0.8.0 @@ -2714,7 +2711,6 @@ __metadata: node-fetch: ^2.6.7 openid-client: ^5.6.4 supertest: ^6.2.4 - winston: ^3.2.1 yn: ^4.0.0 languageName: unknown linkType: soft @@ -2755,7 +2751,6 @@ __metadata: version: 0.0.0-use.local resolution: "@backstage-community/backstage-plugin-scaffolder-backend-module-mta@workspace:plugins/scaffolder-backend-module-mta" dependencies: - "@backstage/backend-common": ^0.21.6 "@backstage/backend-dynamic-feature-service": ^0.2.15 "@backstage/backend-plugin-api": ^0.6.17 "@backstage/catalog-client": ^1.6.5 @@ -2788,7 +2783,7 @@ __metadata: languageName: node linkType: hard -"@backstage/backend-app-api@npm:^0.7.0, @backstage/backend-app-api@npm:^0.7.3, @backstage/backend-app-api@npm:^0.7.9": +"@backstage/backend-app-api@npm:^0.7.3, @backstage/backend-app-api@npm:^0.7.9": version: 0.7.9 resolution: "@backstage/backend-app-api@npm:0.7.9" dependencies: @@ -2921,76 +2916,6 @@ __metadata: languageName: node linkType: hard -"@backstage/backend-common@npm:^0.21.6, @backstage/backend-common@npm:^0.21.7": - version: 0.21.7 - resolution: "@backstage/backend-common@npm:0.21.7" - dependencies: - "@aws-sdk/abort-controller": ^3.347.0 - "@aws-sdk/client-codecommit": ^3.350.0 - "@aws-sdk/client-s3": ^3.350.0 - "@aws-sdk/credential-providers": ^3.350.0 - "@aws-sdk/types": ^3.347.0 - "@backstage/backend-app-api": ^0.7.0 - "@backstage/backend-dev-utils": ^0.1.4 - "@backstage/backend-plugin-api": ^0.6.17 - "@backstage/cli-common": ^0.1.13 - "@backstage/config": ^1.2.0 - "@backstage/config-loader": ^1.8.0 - "@backstage/errors": ^1.2.4 - "@backstage/integration": ^1.10.0 - "@backstage/integration-aws-node": ^0.1.12 - "@backstage/plugin-auth-node": ^0.4.12 - "@backstage/types": ^1.1.1 - "@google-cloud/storage": ^7.0.0 - "@keyv/memcache": ^1.3.5 - "@keyv/redis": ^2.5.3 - "@kubernetes/client-node": 0.20.0 - "@manypkg/get-packages": ^1.1.3 - "@octokit/rest": ^19.0.3 - "@types/cors": ^2.8.6 - "@types/dockerode": ^3.3.0 - "@types/express": ^4.17.6 - "@types/luxon": ^3.0.0 - "@types/webpack-env": ^1.15.2 - archiver: ^6.0.0 - base64-stream: ^1.0.0 - compression: ^1.7.4 - concat-stream: ^2.0.0 - cors: ^2.8.5 - dockerode: ^4.0.0 - express: ^4.17.1 - express-promise-router: ^4.1.0 - fs-extra: ^11.2.0 - git-url-parse: ^14.0.0 - helmet: ^6.0.0 - isomorphic-git: ^1.23.0 - jose: ^5.0.0 - keyv: ^4.5.2 - knex: ^3.0.0 - lodash: ^4.17.21 - logform: ^2.3.2 - luxon: ^3.0.0 - minimatch: ^9.0.0 - mysql2: ^3.0.0 - node-fetch: ^2.6.7 - p-limit: ^3.1.0 - pg: ^8.11.3 - raw-body: ^2.4.1 - tar: ^6.1.12 - uuid: ^9.0.0 - winston: ^3.2.1 - winston-transport: ^4.5.0 - yauzl: ^3.0.0 - yn: ^4.0.0 - peerDependencies: - pg-connection-string: ^2.3.0 - peerDependenciesMeta: - pg-connection-string: - optional: true - checksum: a774e8556d2286fe4648a669c96cece8f831db11b1d7c1075a6bf8da43318ce53e064543b173b7ecc347a23c738e2b52a74168d5f9403fc20fa14eaf2d1fc83b - languageName: node - linkType: hard - "@backstage/backend-common@npm:^0.22.0": version: 0.22.0 resolution: "@backstage/backend-common@npm:0.22.0" @@ -16269,7 +16194,6 @@ __metadata: "@backstage-community/backstage-plugin-catalog-backend-module-mta-entity-provider": "workspace:^" "@backstage-community/backstage-plugin-mta-backend": "workspace:^" "@backstage-community/backstage-plugin-scaffolder-backend-module-mta": "workspace:^" - "@backstage/backend-common": ^0.21.7 "@backstage/backend-defaults": ^0.3.3 "@backstage/backend-dynamic-feature-service": ^0.2.15 "@backstage/backend-tasks": ^0.5.22 @@ -36272,7 +36196,7 @@ __metadata: languageName: node linkType: hard -"winston@npm:^3.13.0, winston@npm:^3.2.1": +"winston@npm:^3.2.1": version: 3.15.0 resolution: "winston@npm:3.15.0" dependencies: From cfb985ab0447c759fbc38c4f7ebf54af0f6ee7a1 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Mon, 18 Nov 2024 13:13:34 -0600 Subject: [PATCH 2/5] Added error middleware Signed-off-by: Andre Wanlin --- workspaces/mta/plugins/mta-backend/package.json | 2 +- workspaces/mta/plugins/mta-backend/src/service/router.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/workspaces/mta/plugins/mta-backend/package.json b/workspaces/mta/plugins/mta-backend/package.json index 55b702cbaf..91f48c754c 100644 --- a/workspaces/mta/plugins/mta-backend/package.json +++ b/workspaces/mta/plugins/mta-backend/package.json @@ -32,6 +32,7 @@ "tsc": "tsc" }, "dependencies": { + "@backstage/backend-defaults": "^0.5.0", "@backstage/backend-dynamic-feature-service": "^0.2.15", "@backstage/backend-plugin-api": "^0.8.0", "@backstage/config": "^1.2.0", @@ -48,7 +49,6 @@ "yn": "^4.0.0" }, "devDependencies": { - "@backstage/backend-defaults": "^0.5.0", "@backstage/cli": "^0.26.11", "@backstage/plugin-auth-backend": "^0.23.0", "@backstage/plugin-auth-backend-module-guest-provider": "^0.2.0", diff --git a/workspaces/mta/plugins/mta-backend/src/service/router.ts b/workspaces/mta/plugins/mta-backend/src/service/router.ts index 47a112e815..43a7a4f8b0 100644 --- a/workspaces/mta/plugins/mta-backend/src/service/router.ts +++ b/workspaces/mta/plugins/mta-backend/src/service/router.ts @@ -10,6 +10,7 @@ import { LoggerService, UserInfoService, } from '@backstage/backend-plugin-api'; +import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter'; /** @public */ export interface RouterOptions { @@ -603,6 +604,7 @@ export async function createRouter( }, ); + router.use(MiddlewareFactory.create({ config, logger }).error()); return router; } From d08b9d128a8314ee0a45901e2c05e50e8d729675 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Mon, 18 Nov 2024 13:34:29 -0600 Subject: [PATCH 3/5] Added deprecation Signed-off-by: Andre Wanlin --- .../nomad/plugins/nomad-backend/src/service/router.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/workspaces/nomad/plugins/nomad-backend/src/service/router.ts b/workspaces/nomad/plugins/nomad-backend/src/service/router.ts index 10dd4a4128..d4388b88bb 100644 --- a/workspaces/nomad/plugins/nomad-backend/src/service/router.ts +++ b/workspaces/nomad/plugins/nomad-backend/src/service/router.ts @@ -22,13 +22,19 @@ import express from 'express'; import Router from 'express-promise-router'; import { LoggerService } from '@backstage/backend-plugin-api'; -/** @public */ +/** + * @deprecated Please migrate to the new backend system as this will be removed in the future. + * + * @public */ export interface RouterOptions { logger: LoggerService; config: Config; } -/** @public */ +/** + * @deprecated Please migrate to the new backend system as this will be removed in the future. + * + * @public */ export async function createRouter( options: RouterOptions, ): Promise { From b3615984bd0410b327e4d24a13ebda0df16cf5c5 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Mon, 18 Nov 2024 13:53:58 -0600 Subject: [PATCH 4/5] Various updates Signed-off-by: Andre Wanlin --- workspaces/mta/.changeset/fuzzy-lizards-notice.md | 1 - workspaces/mta/.changeset/thirty-seas-attend.md | 7 +++++++ workspaces/mta/plugins/mta-backend/api-report.md | 4 ++-- .../mta/plugins/mta-backend/src/service/router.ts | 10 ++++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 workspaces/mta/.changeset/thirty-seas-attend.md diff --git a/workspaces/mta/.changeset/fuzzy-lizards-notice.md b/workspaces/mta/.changeset/fuzzy-lizards-notice.md index e4238a69d6..686d5dbe24 100644 --- a/workspaces/mta/.changeset/fuzzy-lizards-notice.md +++ b/workspaces/mta/.changeset/fuzzy-lizards-notice.md @@ -1,7 +1,6 @@ --- '@backstage-community/backstage-plugin-catalog-backend-module-mta-entity-provider': patch '@backstage-community/backstage-plugin-scaffolder-backend-module-mta': patch -'@backstage-community/backstage-plugin-mta-backend': patch --- Removed usages and references of `@backstage/backend-common` diff --git a/workspaces/mta/.changeset/thirty-seas-attend.md b/workspaces/mta/.changeset/thirty-seas-attend.md new file mode 100644 index 0000000000..c1df77efcb --- /dev/null +++ b/workspaces/mta/.changeset/thirty-seas-attend.md @@ -0,0 +1,7 @@ +--- +'@backstage-community/backstage-plugin-mta-backend': patch +--- + +Deprecated `createRouter` and its router options in favour of the new backend system. + +Removed usages and references of `@backstage/backend-common` diff --git a/workspaces/mta/plugins/mta-backend/api-report.md b/workspaces/mta/plugins/mta-backend/api-report.md index a115a5aa5a..936f2e0408 100644 --- a/workspaces/mta/plugins/mta-backend/api-report.md +++ b/workspaces/mta/plugins/mta-backend/api-report.md @@ -13,14 +13,14 @@ import { HttpAuthService } from '@backstage/backend-plugin-api'; import { LoggerService } from '@backstage/backend-plugin-api'; import { UserInfoService } from '@backstage/backend-plugin-api'; -// @public (undocumented) +// @public @deprecated (undocumented) export function createRouter(options: RouterOptions): Promise; // @public (undocumented) const mtaPlugin: BackendFeatureCompat; export default mtaPlugin; -// @public (undocumented) +// @public @deprecated (undocumented) export interface RouterOptions { // (undocumented) cache: CacheService; diff --git a/workspaces/mta/plugins/mta-backend/src/service/router.ts b/workspaces/mta/plugins/mta-backend/src/service/router.ts index 43a7a4f8b0..bcd2259dfe 100644 --- a/workspaces/mta/plugins/mta-backend/src/service/router.ts +++ b/workspaces/mta/plugins/mta-backend/src/service/router.ts @@ -12,7 +12,10 @@ import { } from '@backstage/backend-plugin-api'; import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter'; -/** @public */ +/** + * @deprecated Please migrate to the new backend system as this will be removed in the future. + * + * @public */ export interface RouterOptions { logger: LoggerService; database: DatabaseService; @@ -22,7 +25,10 @@ export interface RouterOptions { cache: CacheService; } -/** @public */ +/** + * @deprecated Please migrate to the new backend system as this will be removed in the future. + * + * @public */ export async function createRouter( options: RouterOptions, ): Promise { From 0774062ff2363da240cdd39d41589acd6c7ad1d9 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Mon, 18 Nov 2024 14:26:51 -0600 Subject: [PATCH 5/5] Undo nomad change in mta pr Signed-off-by: Andre Wanlin --- .../nomad/plugins/nomad-backend/src/service/router.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/workspaces/nomad/plugins/nomad-backend/src/service/router.ts b/workspaces/nomad/plugins/nomad-backend/src/service/router.ts index d4388b88bb..10dd4a4128 100644 --- a/workspaces/nomad/plugins/nomad-backend/src/service/router.ts +++ b/workspaces/nomad/plugins/nomad-backend/src/service/router.ts @@ -22,19 +22,13 @@ import express from 'express'; import Router from 'express-promise-router'; import { LoggerService } from '@backstage/backend-plugin-api'; -/** - * @deprecated Please migrate to the new backend system as this will be removed in the future. - * - * @public */ +/** @public */ export interface RouterOptions { logger: LoggerService; config: Config; } -/** - * @deprecated Please migrate to the new backend system as this will be removed in the future. - * - * @public */ +/** @public */ export async function createRouter( options: RouterOptions, ): Promise {