user-settings-backend: remove support for old backend system

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-02-27 19:03:32 +01:00
parent d74c59cc8f
commit e202017550
13 changed files with 25 additions and 191 deletions
+7
View File
@@ -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`.
+2 -8
View File
@@ -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"
}
@@ -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)
```
@@ -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<express.Router>;
// @public
const _default: BackendFeature;
export default _default;
// @public @deprecated
export type RouterOptions = {
database: DatabaseService;
identity: IdentityApi;
signals?: SignalsService;
};
// (No @packageDocumentation comment for this package)
```
@@ -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;
@@ -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 {};
@@ -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<express.Router> {
return await internalCreateRouter(options);
}
@@ -15,5 +15,3 @@
*/
export { default } from './plugin';
export * from './deprecated';
export * from './database';
+2 -2
View File
@@ -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 }),
);
},
});
@@ -14,4 +14,4 @@
* limitations under the License.
*/
export { createRouter, type RouterOptions } from './router';
export { createRouter } from './router';
@@ -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,
@@ -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<express.Router> {
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<express.Router> {
export async function createRouter(options: {
httpAuth: HttpAuthService;
userSettingsStore: UserSettingsStore;
signals: SignalsService;
}): Promise<express.Router> {
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<string> => {
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
-2
View File
@@ -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