backend-plugin-api: remove identity and token manager services

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-08-21 15:31:15 +02:00
parent 337a4704a6
commit 1780a67bc5
47 changed files with 86 additions and 507 deletions
-24
View File
@@ -23,7 +23,6 @@ import { ExtendedHttpServer } from '@backstage/backend-defaults/rootHttpRouter';
import { ExtensionPoint } from '@backstage/backend-plugin-api';
import { HttpAuthService } from '@backstage/backend-plugin-api';
import { HttpRouterService } from '@backstage/backend-plugin-api';
import { IdentityService } from '@backstage/backend-plugin-api';
import { JsonObject } from '@backstage/types';
import Keyv from 'keyv';
import { Knex } from 'knex';
@@ -39,7 +38,6 @@ import { RootLoggerService } from '@backstage/backend-plugin-api';
import { SchedulerService } from '@backstage/backend-plugin-api';
import { ServiceFactory } from '@backstage/backend-plugin-api';
import { ServiceRef } from '@backstage/backend-plugin-api';
import { TokenManagerService } from '@backstage/backend-plugin-api';
import { UrlReaderService } from '@backstage/backend-plugin-api';
import { UserInfoService } from '@backstage/backend-plugin-api';
@@ -217,17 +215,6 @@ export namespace mockServices {
) => ServiceMock<HttpRouterService>;
}
// (undocumented)
export function identity(): IdentityService;
// (undocumented)
export namespace identity {
const // (undocumented)
factory: () => ServiceFactory<IdentityService, 'plugin', 'singleton'>;
const // (undocumented)
mock: (
partialImpl?: Partial<IdentityService> | undefined,
) => ServiceMock<IdentityService>;
}
// (undocumented)
export namespace lifecycle {
const // (undocumented)
factory: () => ServiceFactory<LifecycleService, 'plugin', 'singleton'>;
@@ -324,17 +311,6 @@ export namespace mockServices {
) => ServiceMock<SchedulerService>;
}
// (undocumented)
export function tokenManager(): TokenManagerService;
// (undocumented)
export namespace tokenManager {
const // (undocumented)
factory: () => ServiceFactory<TokenManagerService, 'plugin', 'singleton'>;
const // (undocumented)
mock: (
partialImpl?: Partial<TokenManagerService> | undefined,
) => ServiceMock<TokenManagerService>;
}
// (undocumented)
export namespace urlReader {
const // (undocumented)
factory: () => ServiceFactory<UrlReaderService, 'plugin', 'singleton'>;
@@ -1,35 +0,0 @@
/*
* Copyright 2023 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 { IdentityService } from '@backstage/backend-plugin-api';
import {
IdentityApiGetIdentityRequest,
BackstageIdentityResponse,
} from '@backstage/plugin-auth-node';
export class MockIdentityService implements IdentityService {
getIdentity(
_options: IdentityApiGetIdentityRequest,
): Promise<BackstageIdentityResponse | undefined> {
return Promise.resolve({
token: 'mock-token',
identity: {
type: 'user',
userEntityRef: 'user:default/mock-user',
ownershipEntityRefs: [],
},
});
}
}
@@ -35,12 +35,10 @@ import {
BackstageUserInfo,
DiscoveryService,
HttpAuthService,
IdentityService,
LoggerService,
RootConfigService,
ServiceFactory,
ServiceRef,
TokenManagerService,
UserInfoService,
coreServices,
createServiceFactory,
@@ -53,7 +51,6 @@ import {
import { JsonObject } from '@backstage/types';
import { MockAuthService } from './MockAuthService';
import { MockHttpAuthService } from './MockHttpAuthService';
import { MockIdentityService } from './MockIdentityService';
import { MockRootLoggerService } from './MockRootLoggerService';
import { MockUserInfoService } from './MockUserInfoService';
import { mockCredentials } from './mockCredentials';
@@ -167,46 +164,6 @@ export namespace mockServices {
}));
}
export function tokenManager(): TokenManagerService {
return {
async getToken(): Promise<{ token: string }> {
return { token: 'mock-token' };
},
async authenticate(token: string): Promise<void> {
if (token !== 'mock-token') {
throw new Error('Invalid token');
}
},
};
}
export namespace tokenManager {
export const factory = () =>
createServiceFactory({
service: coreServices.tokenManager,
deps: {},
factory: () => tokenManager(),
});
export const mock = simpleMock(coreServices.tokenManager, () => ({
authenticate: jest.fn(),
getToken: jest.fn(),
}));
}
export function identity(): IdentityService {
return new MockIdentityService();
}
export namespace identity {
export const factory = () =>
createServiceFactory({
service: coreServices.identity,
deps: {},
factory: () => identity(),
});
export const mock = simpleMock(coreServices.identity, () => ({
getIdentity: jest.fn(),
}));
}
export function auth(options?: {
pluginId?: string;
disableDefaultAuthPolicy?: boolean;
@@ -198,13 +198,12 @@ describe('TestBackend', () => {
rootLifecycle: coreServices.rootLifecycle,
rootLogger: coreServices.rootLogger,
scheduler: coreServices.scheduler,
tokenManager: coreServices.tokenManager,
urlReader: coreServices.urlReader,
auth: coreServices.auth,
httpAuth: coreServices.httpAuth,
},
async init(deps) {
expect(Object.keys(deps)).toHaveLength(17);
expect(Object.keys(deps)).toHaveLength(16);
expect(Object.values(deps)).not.toContain(undefined);
},
});
@@ -72,7 +72,6 @@ export const defaultServiceFactories = [
mockServices.database.factory(),
mockServices.httpAuth.factory(),
mockServices.httpRouter.factory(),
mockServices.identity.factory(),
mockServices.lifecycle.factory(),
mockServices.logger.factory(),
mockServices.permissions.factory(),
@@ -80,7 +79,6 @@ export const defaultServiceFactories = [
mockServices.rootLifecycle.factory(),
mockServices.rootLogger.factory(),
mockServices.scheduler.factory(),
mockServices.tokenManager.factory(),
mockServices.userInfo.factory(),
mockServices.urlReader.factory(),
mockServices.events.factory(),