diff --git a/.changeset/pretty-chicken-eat.md b/.changeset/pretty-chicken-eat.md new file mode 100644 index 0000000000..32b89a1337 --- /dev/null +++ b/.changeset/pretty-chicken-eat.md @@ -0,0 +1,7 @@ +--- +'@backstage/plugin-user-settings-backend': minor +--- + +**BREAKING**: Removed support for the old backend system. + +As part of this change the plugin export from `/alpha` as been removed. If you are currently importing `@backstage/plugin-user-settings-backend/alpha`, please update your import to `@backstage/plugin-user-settings-backend`. diff --git a/plugins/user-settings-backend/package.json b/plugins/user-settings-backend/package.json index c23c03185a..4980d73661 100644 --- a/plugins/user-settings-backend/package.json +++ b/plugins/user-settings-backend/package.json @@ -23,16 +23,12 @@ "license": "Apache-2.0", "exports": { ".": "./src/index.ts", - "./alpha": "./src/alpha.ts", "./package.json": "./package.json" }, "main": "src/index.ts", "types": "src/index.ts", "typesVersions": { "*": { - "alpha": [ - "src/alpha.ts" - ], "package.json": [ "package.json" ] @@ -54,22 +50,20 @@ "dependencies": { "@backstage/backend-defaults": "workspace:^", "@backstage/backend-plugin-api": "workspace:^", - "@backstage/config": "workspace:^", "@backstage/errors": "workspace:^", "@backstage/plugin-auth-node": "workspace:^", "@backstage/plugin-signals-node": "workspace:^", "@backstage/plugin-user-settings-common": "workspace:^", "@backstage/types": "workspace:^", - "@types/express": "^4.17.6", "express": "^4.17.1", "express-promise-router": "^4.1.0", - "knex": "^3.0.0", - "yn": "^4.0.0" + "knex": "^3.0.0" }, "devDependencies": { "@backstage/backend-defaults": "workspace:^", "@backstage/backend-test-utils": "workspace:^", "@backstage/cli": "workspace:^", + "@types/express": "^4.17.6", "@types/supertest": "^2.0.8", "supertest": "^7.0.0" } diff --git a/plugins/user-settings-backend/report-alpha.api.md b/plugins/user-settings-backend/report-alpha.api.md deleted file mode 100644 index 8ed6505934..0000000000 --- a/plugins/user-settings-backend/report-alpha.api.md +++ /dev/null @@ -1,13 +0,0 @@ -## API Report File for "@backstage/plugin-user-settings-backend" - -> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). - -```ts -import { BackendFeature } from '@backstage/backend-plugin-api'; - -// @alpha (undocumented) -const _feature: BackendFeature; -export default _feature; - -// (No @packageDocumentation comment for this package) -``` diff --git a/plugins/user-settings-backend/report.api.md b/plugins/user-settings-backend/report.api.md index cbbd8d5d6d..1ef2ef2877 100644 --- a/plugins/user-settings-backend/report.api.md +++ b/plugins/user-settings-backend/report.api.md @@ -4,24 +4,10 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; -import { DatabaseService } from '@backstage/backend-plugin-api'; -import express from 'express'; -import { IdentityApi } from '@backstage/plugin-auth-node'; -import { SignalsService } from '@backstage/plugin-signals-node'; - -// @public @deprecated -export function createRouter(options: RouterOptions): Promise; // @public const _default: BackendFeature; export default _default; -// @public @deprecated -export type RouterOptions = { - database: DatabaseService; - identity: IdentityApi; - signals?: SignalsService; -}; - // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/user-settings-backend/src/alpha.ts b/plugins/user-settings-backend/src/alpha.ts deleted file mode 100644 index a8c814004b..0000000000 --- a/plugins/user-settings-backend/src/alpha.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2024 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { default as feature } from './plugin'; - -/** @alpha */ -const _feature = feature; -export default _feature; diff --git a/plugins/user-settings-backend/src/database/index.ts b/plugins/user-settings-backend/src/database/index.ts deleted file mode 100644 index 813cdeaae3..0000000000 --- a/plugins/user-settings-backend/src/database/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2022 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export {}; diff --git a/plugins/user-settings-backend/src/deprecated.ts b/plugins/user-settings-backend/src/deprecated.ts deleted file mode 100644 index 2631236d44..0000000000 --- a/plugins/user-settings-backend/src/deprecated.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2024 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import express from 'express'; -import { DatabaseService } from '@backstage/backend-plugin-api'; -import { SignalsService } from '@backstage/plugin-signals-node'; - -import { createRouter as internalCreateRouter } from './service'; -import { IdentityApi } from '@backstage/plugin-auth-node'; - -/** - * Type for the options passed to the "createRouter" function. - * - * @public - * @deprecated This type is only exported for legacy reasons and will be removed in the future. - */ -export type RouterOptions = { - database: DatabaseService; - identity: IdentityApi; - signals?: SignalsService; -}; - -/** - * Create the user settings backend routes. - * - * @public - * @deprecated This function is only exported for legacy reasons and will be removed in the future. - * Please {@link https://backstage.io/docs/backend-system/building-backends/migrating | migrate } to use the new backend system and follow these {@link https://github.com/backstage/backstage/tree/master/plugins/user-settings-backend#new-backend | instructions } to install the user settings backend plugin. - */ -export async function createRouter( - options: RouterOptions, -): Promise { - return await internalCreateRouter(options); -} diff --git a/plugins/user-settings-backend/src/index.ts b/plugins/user-settings-backend/src/index.ts index daf59c47e0..47c96de5a4 100644 --- a/plugins/user-settings-backend/src/index.ts +++ b/plugins/user-settings-backend/src/index.ts @@ -15,5 +15,3 @@ */ export { default } from './plugin'; -export * from './deprecated'; -export * from './database'; diff --git a/plugins/user-settings-backend/src/plugin.ts b/plugins/user-settings-backend/src/plugin.ts index 26fd3de908..8004819ea0 100644 --- a/plugins/user-settings-backend/src/plugin.ts +++ b/plugins/user-settings-backend/src/plugin.ts @@ -18,7 +18,7 @@ import { coreServices, createBackendPlugin, } from '@backstage/backend-plugin-api'; -import { createRouterInternal } from './service/router'; +import { createRouter } from './service/router'; import { signalsServiceRef } from '@backstage/plugin-signals-node'; import { DatabaseUserSettingsStore } from './database/DatabaseUserSettingsStore'; @@ -42,7 +42,7 @@ export default createBackendPlugin({ database, }); httpRouter.use( - await createRouterInternal({ userSettingsStore, httpAuth, signals }), + await createRouter({ userSettingsStore, httpAuth, signals }), ); }, }); diff --git a/plugins/user-settings-backend/src/service/index.ts b/plugins/user-settings-backend/src/service/index.ts index 8ec00d13c8..434446cf3f 100644 --- a/plugins/user-settings-backend/src/service/index.ts +++ b/plugins/user-settings-backend/src/service/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export { createRouter, type RouterOptions } from './router'; +export { createRouter } from './router'; diff --git a/plugins/user-settings-backend/src/service/router.test.ts b/plugins/user-settings-backend/src/service/router.test.ts index 366d3828a0..afc725025c 100644 --- a/plugins/user-settings-backend/src/service/router.test.ts +++ b/plugins/user-settings-backend/src/service/router.test.ts @@ -17,7 +17,7 @@ import express from 'express'; import request from 'supertest'; import { UserSettingsStore } from '../database/UserSettingsStore'; -import { createRouterInternal } from './router'; +import { createRouter } from './router'; import { SignalsService } from '@backstage/plugin-signals-node'; import { mockCredentials, @@ -38,7 +38,7 @@ describe('createRouter', () => { let app: express.Express; beforeEach(async () => { - const router = await createRouterInternal({ + const router = await createRouter({ userSettingsStore, httpAuth: mockServices.httpAuth(), signals: signalService as SignalsService, diff --git a/plugins/user-settings-backend/src/service/router.ts b/plugins/user-settings-backend/src/service/router.ts index eacc35a5ae..07b4443551 100644 --- a/plugins/user-settings-backend/src/service/router.ts +++ b/plugins/user-settings-backend/src/service/router.ts @@ -14,60 +14,19 @@ * limitations under the License. */ -import { AuthenticationError, InputError } from '@backstage/errors'; -import { IdentityApi } from '@backstage/plugin-auth-node'; +import { InputError } from '@backstage/errors'; import express, { Request } from 'express'; import Router from 'express-promise-router'; -import { DatabaseUserSettingsStore } from '../database/DatabaseUserSettingsStore'; import { UserSettingsStore } from '../database/UserSettingsStore'; import { SignalsService } from '@backstage/plugin-signals-node'; import { UserSettingsSignal } from '@backstage/plugin-user-settings-common'; -import { - DatabaseService, - HttpAuthService, -} from '@backstage/backend-plugin-api'; +import { HttpAuthService } from '@backstage/backend-plugin-api'; -/** - * @public - */ -export interface RouterOptions { - database: DatabaseService; - identity: IdentityApi; - signals?: SignalsService; -} - -/** - * Create the user settings backend routes. - * - * @public - */ -export async function createRouter( - options: RouterOptions, -): Promise { - const userSettingsStore = await DatabaseUserSettingsStore.create({ - database: options.database, - }); - - return await createRouterInternal({ - userSettingsStore, - identity: options.identity, - signals: options.signals, - }); -} - -export async function createRouterInternal( - options: - | { - identity: IdentityApi; - userSettingsStore: UserSettingsStore; - signals?: SignalsService; - } - | { - httpAuth: HttpAuthService; - userSettingsStore: UserSettingsStore; - signals?: SignalsService; - }, -): Promise { +export async function createRouter(options: { + httpAuth: HttpAuthService; + userSettingsStore: UserSettingsStore; + signals: SignalsService; +}): Promise { const router = Router(); router.use(express.json()); @@ -75,20 +34,10 @@ export async function createRouterInternal( * Helper method to extract the userEntityRef from the request. */ const getUserEntityRef = async (req: Request): Promise => { - if ('httpAuth' in options) { - const credentials = await options.httpAuth.credentials(req, { - allow: ['user'], - }); - return credentials.principal.userEntityRef; - } - - // throws an AuthenticationError in case the token exists but is invalid - const identity = await options.identity.getIdentity({ request: req }); - if (!identity) { - throw new AuthenticationError(`Missing token in 'authorization' header`); - } - - return identity.identity.userEntityRef; + const credentials = await options.httpAuth.credentials(req, { + allow: ['user'], + }); + return credentials.principal.userEntityRef; }; // get a single value diff --git a/yarn.lock b/yarn.lock index 378e56eb4a..eb15c4bf14 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8525,7 +8525,6 @@ __metadata: "@backstage/backend-plugin-api": "workspace:^" "@backstage/backend-test-utils": "workspace:^" "@backstage/cli": "workspace:^" - "@backstage/config": "workspace:^" "@backstage/errors": "workspace:^" "@backstage/plugin-auth-node": "workspace:^" "@backstage/plugin-signals-node": "workspace:^" @@ -8537,7 +8536,6 @@ __metadata: express-promise-router: ^4.1.0 knex: ^3.0.0 supertest: ^7.0.0 - yn: ^4.0.0 languageName: unknown linkType: soft