Skip to content

Commit

Permalink
entity-feedback - Removed usages and references of `@backstage/backen…
Browse files Browse the repository at this point in the history
…d-common` (#1972)

Signed-off-by: Andre Wanlin <[email protected]>
  • Loading branch information
awanlin authored Nov 18, 2024
1 parent 8634a13 commit fcf6f84
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 41 deletions.
7 changes: 7 additions & 0 deletions workspaces/entity-feedback/.changeset/short-rules-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@backstage-community/plugin-entity-feedback-backend': minor
---

**BREAKING** `auth`, `config`, and `httpAuth` are now required, please migrate to the new backend system as the best path forward for this change.

Also, removed usages and references of `@backstage/backend-common`
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"@backstage-community/plugin-entity-feedback-common": "workspace:^",
"@backstage/backend-common": "^0.25.0",
"@backstage/backend-defaults": "^0.5.2",
"@backstage/backend-plugin-api": "^1.0.1",
"@backstage/catalog-client": "^1.7.1",
"@backstage/catalog-model": "^1.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```ts
import { AuthService } from '@backstage/backend-plugin-api';
import { BackendFeature } from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
import { DatabaseService } from '@backstage/backend-plugin-api';
import { DiscoveryService } from '@backstage/backend-plugin-api';
import express from 'express';
Expand All @@ -22,13 +23,15 @@ export default entityFeedbackPlugin;
// @public (undocumented)
export interface RouterOptions {
// (undocumented)
auth?: AuthService;
auth: AuthService;
// (undocumented)
config: Config;
// (undocumented)
database: DatabaseService;
// (undocumented)
discovery: DiscoveryService;
// (undocumented)
httpAuth?: HttpAuthService;
httpAuth: HttpAuthService;
// (undocumented)
identity?: IdentityApi;
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,25 @@ export const entityFeedbackPlugin = createBackendPlugin({
httpAuth: coreServices.httpAuth,
httpRouter: coreServices.httpRouter,
logger: coreServices.logger,
config: coreServices.rootConfig,
},
async init({ database, discovery, logger, httpRouter, auth, httpAuth }) {
async init({
database,
discovery,
logger,
httpRouter,
auth,
httpAuth,
config,
}) {
httpRouter.use(
await createRouter({
auth,
database,
discovery,
httpAuth,
logger,
config,
}),
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@
* limitations under the License.
*/

import {
DatabaseManager,
getVoidLogger,
PluginEndpointDiscovery,
} from '@backstage/backend-common';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { ConfigReader } from '@backstage/config';
import express from 'express';
import request from 'supertest';

Expand Down Expand Up @@ -133,30 +127,14 @@ jest.mock('./DatabaseHandler', () => ({
describe('createRouter', () => {
let app: express.Express;

const createDatabase = () =>
DatabaseManager.fromConfig(
new ConfigReader({
backend: {
database: {
client: 'better-sqlite3',
connection: ':memory:',
},
},
}),
).forPlugin('entity-feedback');

const discovery: jest.Mocked<PluginEndpointDiscovery> = {
getBaseUrl: jest.fn(),
getExternalBaseUrl: jest.fn(),
};

beforeEach(async () => {
const router = await createRouter({
database: createDatabase(),
discovery,
logger: getVoidLogger(),
database: mockServices.database.mock(),
discovery: mockServices.discovery(),
logger: mockServices.rootLogger(),
auth: mockServices.auth(),
httpAuth: mockServices.httpAuth(),
config: mockServices.rootConfig(),
});

app = express().use(router);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
* limitations under the License.
*/

import {
createLegacyAuthAdapters,
errorHandler,
} from '@backstage/backend-common';
import {
AuthService,
DatabaseService,
Expand All @@ -35,8 +31,9 @@ import {
import { InputError } from '@backstage/errors';
import express from 'express';
import Router from 'express-promise-router';

import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter';
import { DatabaseHandler } from './DatabaseHandler';
import { Config } from '@backstage/config';

/**
* @public
Expand All @@ -46,8 +43,9 @@ export interface RouterOptions {
discovery: DiscoveryService;
identity?: IdentityApi;
logger: LoggerService;
auth?: AuthService;
httpAuth?: HttpAuthService;
auth: AuthService;
httpAuth: HttpAuthService;
config: Config;
}

/**
Expand All @@ -56,10 +54,9 @@ export interface RouterOptions {
export async function createRouter(
options: RouterOptions,
): Promise<express.Router> {
const { database, discovery, logger } = options;
const { database, discovery, logger, httpAuth, auth, config } = options;

logger.info('Initializing Entity Feedback backend');
const { auth, httpAuth } = createLegacyAuthAdapters(options);

const catalogClient = new CatalogClient({ discoveryApi: discovery });
const db = await database.getClient();
Expand Down Expand Up @@ -231,6 +228,6 @@ export async function createRouter(
res.json(responses.filter(r => accessibleEntityRefs.includes(r.userRef)));
});

router.use(errorHandler());
router.use(MiddlewareFactory.create({ config, logger }).error());
return router;
}
1 change: 0 additions & 1 deletion workspaces/entity-feedback/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2528,7 +2528,6 @@ __metadata:
resolution: "@backstage-community/plugin-entity-feedback-backend@workspace:plugins/entity-feedback-backend"
dependencies:
"@backstage-community/plugin-entity-feedback-common": "workspace:^"
"@backstage/backend-common": ^0.25.0
"@backstage/backend-defaults": ^0.5.2
"@backstage/backend-plugin-api": ^1.0.1
"@backstage/backend-test-utils": ^1.0.2
Expand Down

0 comments on commit fcf6f84

Please sign in to comment.