diff --git a/.changeset/rich-vans-hope.md b/.changeset/rich-vans-hope.md new file mode 100644 index 0000000000..3e219a13b6 --- /dev/null +++ b/.changeset/rich-vans-hope.md @@ -0,0 +1,12 @@ +--- +'@backstage/backend-dynamic-feature-service': patch +'@backstage/plugin-catalog-backend-module-github': patch +'@backstage/plugin-scaffolder-backend': patch +'@backstage/backend-defaults': patch +'@backstage/plugin-catalog-backend': patch +'@backstage/plugin-auth-backend': patch +'@backstage/plugin-app-backend': patch +'@backstage/plugin-auth-node': patch +--- + +Remove usages of `PluginDatabaseManager` and `PluginEndpointDiscovery` and replace with their equivalent service types diff --git a/packages/backend-defaults/src/entrypoints/database/DatabaseManager.ts b/packages/backend-defaults/src/entrypoints/database/DatabaseManager.ts index 75e7d35eee..5ca70cab86 100644 --- a/packages/backend-defaults/src/entrypoints/database/DatabaseManager.ts +++ b/packages/backend-defaults/src/entrypoints/database/DatabaseManager.ts @@ -28,7 +28,7 @@ import { Knex } from 'knex'; import { MysqlConnector } from './connectors/mysql'; import { PgConnector } from './connectors/postgres'; import { Sqlite3Connector } from './connectors/sqlite3'; -import { Connector, PluginDatabaseManager } from './types'; +import { Connector } from './types'; /** * Provides a config lookup path for a plugin's config block. @@ -72,7 +72,7 @@ export class DatabaseManagerImpl { } /** - * Generates a PluginDatabaseManager for consumption by plugins. + * Generates a DatabaseService for consumption by plugins. * * @param pluginId - The plugin that the database manager should be created for. Plugin names * should be unique as they are used to look up database config overrides under @@ -84,7 +84,7 @@ export class DatabaseManagerImpl { logger: LoggerService; lifecycle: LifecycleService; }, - ): PluginDatabaseManager { + ): DatabaseService { const client = this.getClientType(pluginId).client; const connector = this.connectors[client]; if (!connector) { @@ -265,7 +265,7 @@ export class DatabaseManager { private constructor(private readonly impl: DatabaseManagerImpl) {} /** - * Generates a PluginDatabaseManager for consumption by plugins. + * Generates a DatabaseService for consumption by plugins. * * @param pluginId - The plugin that the database manager should be created for. Plugin names * should be unique as they are used to look up database config overrides under @@ -277,7 +277,7 @@ export class DatabaseManager { logger: LoggerService; lifecycle: LifecycleService; }, - ): PluginDatabaseManager { + ): DatabaseService { return this.impl.forPlugin(pluginId, deps); } } diff --git a/packages/backend-defaults/src/entrypoints/database/types.ts b/packages/backend-defaults/src/entrypoints/database/types.ts index beded85d65..2a264ed928 100644 --- a/packages/backend-defaults/src/entrypoints/database/types.ts +++ b/packages/backend-defaults/src/entrypoints/database/types.ts @@ -17,8 +17,6 @@ import { LifecycleService, LoggerService } from '@backstage/backend-plugin-api'; import { Knex } from 'knex'; -export type { DatabaseService as PluginDatabaseManager } from '@backstage/backend-plugin-api'; - export interface Connector { getClient( pluginId: string, diff --git a/packages/backend-defaults/src/entrypoints/discovery/HostDiscovery.ts b/packages/backend-defaults/src/entrypoints/discovery/HostDiscovery.ts index 47793c82f7..b6c2c38d8a 100644 --- a/packages/backend-defaults/src/entrypoints/discovery/HostDiscovery.ts +++ b/packages/backend-defaults/src/entrypoints/discovery/HostDiscovery.ts @@ -24,7 +24,7 @@ import { readHttpServerOptions } from '../rootHttpRouter/http/config'; type Target = string | { internal: string; external: string }; /** - * HostDiscovery is a basic PluginEndpointDiscovery implementation + * HostDiscovery is a basic DiscoveryService implementation * that can handle plugins that are hosted in a single or multiple deployments. * * The deployment may be scaled horizontally, as long as the external URL diff --git a/packages/backend-dynamic-feature-service/report.api.md b/packages/backend-dynamic-feature-service/report.api.md index 6e53f3747f..e2ad34c84d 100644 --- a/packages/backend-dynamic-feature-service/report.api.md +++ b/packages/backend-dynamic-feature-service/report.api.md @@ -8,6 +8,8 @@ import { BackstagePackageJson } from '@backstage/cli-node'; import { CatalogBuilder } from '@backstage/plugin-catalog-backend'; import { Config } from '@backstage/config'; import { ConfigSchema } from '@backstage/config-loader'; +import { DatabaseService } from '@backstage/backend-plugin-api'; +import { DiscoveryService } from '@backstage/backend-plugin-api'; import { EventBroker } from '@backstage/plugin-events-node'; import { EventsBackend } from '@backstage/plugin-events-backend'; import { EventsService } from '@backstage/plugin-events-node'; @@ -22,8 +24,6 @@ import { PackageRole } from '@backstage/cli-node'; import { PermissionEvaluator } from '@backstage/plugin-permission-common'; import { PermissionPolicy } from '@backstage/plugin-permission-node'; import { PluginCacheManager } from '@backstage/backend-common'; -import { PluginDatabaseManager } from '@backstage/backend-common'; -import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { RootLoggerService } from '@backstage/backend-plugin-api'; import { Router } from 'express'; import { SchedulerService } from '@backstage/backend-plugin-api'; @@ -274,10 +274,10 @@ export interface LegacyBackendPluginInstaller { export type LegacyPluginEnvironment = { logger: Logger; cache: PluginCacheManager; - database: PluginDatabaseManager; + database: DatabaseService; config: Config; reader: UrlReaderService; - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; tokenManager: TokenManager; permissions: PermissionEvaluator; scheduler: SchedulerService; diff --git a/packages/backend-dynamic-feature-service/src/manager/types.ts b/packages/backend-dynamic-feature-service/src/manager/types.ts index 89ac140bc6..d056a9a1b2 100644 --- a/packages/backend-dynamic-feature-service/src/manager/types.ts +++ b/packages/backend-dynamic-feature-service/src/manager/types.ts @@ -16,12 +16,7 @@ import { Logger } from 'winston'; import { Config } from '@backstage/config'; -import { - PluginCacheManager, - PluginDatabaseManager, - PluginEndpointDiscovery, - TokenManager, -} from '@backstage/backend-common'; +import { PluginCacheManager, TokenManager } from '@backstage/backend-common'; import { Router } from 'express'; import { IdentityApi } from '@backstage/plugin-auth-node'; import { PermissionEvaluator } from '@backstage/plugin-permission-common'; @@ -36,6 +31,8 @@ import { UrlReaderService, SchedulerService, SchedulerServiceTaskRunner, + DatabaseService, + DiscoveryService, } from '@backstage/backend-plugin-api'; import { PackagePlatform, PackageRole } from '@backstage/cli-node'; import { CatalogBuilder } from '@backstage/plugin-catalog-backend'; @@ -60,10 +57,10 @@ import { ScannedPluginPackage } from '../scanner'; export type LegacyPluginEnvironment = { logger: Logger; cache: PluginCacheManager; - database: PluginDatabaseManager; + database: DatabaseService; config: Config; reader: UrlReaderService; - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; tokenManager: TokenManager; permissions: PermissionEvaluator; scheduler: SchedulerService; diff --git a/packages/backend-legacy/src/types.ts b/packages/backend-legacy/src/types.ts index 3f5d163925..b106f5d85a 100644 --- a/packages/backend-legacy/src/types.ts +++ b/packages/backend-legacy/src/types.ts @@ -16,12 +16,7 @@ import { Logger } from 'winston'; import { Config } from '@backstage/config'; -import { - PluginCacheManager, - PluginDatabaseManager, - PluginEndpointDiscovery, - TokenManager, -} from '@backstage/backend-common'; +import { PluginCacheManager, TokenManager } from '@backstage/backend-common'; import { IdentityApi } from '@backstage/plugin-auth-node'; import { PermissionEvaluator } from '@backstage/plugin-permission-common'; import { EventBroker, EventsService } from '@backstage/plugin-events-node'; @@ -29,15 +24,17 @@ import { SignalsService } from '@backstage/plugin-signals-node'; import { UrlReaderService, SchedulerService, + DatabaseService, + DiscoveryService, } from '@backstage/backend-plugin-api'; export type PluginEnvironment = { logger: Logger; cache: PluginCacheManager; - database: PluginDatabaseManager; + database: DatabaseService; config: Config; reader: UrlReaderService; - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; tokenManager: TokenManager; permissions: PermissionEvaluator; scheduler: SchedulerService; diff --git a/plugins/app-backend/package.json b/plugins/app-backend/package.json index 712b06f090..c0afac060f 100644 --- a/plugins/app-backend/package.json +++ b/plugins/app-backend/package.json @@ -57,7 +57,6 @@ "test": "backstage-cli package test" }, "dependencies": { - "@backstage/backend-common": "^0.25.0", "@backstage/backend-plugin-api": "workspace:^", "@backstage/config": "workspace:^", "@backstage/config-loader": "workspace:^", diff --git a/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts b/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts index 1179a11ef3..86e8119cb2 100644 --- a/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts +++ b/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts @@ -14,12 +14,12 @@ * limitations under the License. */ -import { PluginDatabaseManager } from '@backstage/backend-common'; import { Knex } from 'knex'; import { DateTime } from 'luxon'; import partition from 'lodash/partition'; import { StaticAsset, StaticAssetInput, StaticAssetProvider } from './types'; import { + DatabaseService, LoggerService, resolvePackagePath, } from '@backstage/backend-plugin-api'; @@ -38,7 +38,7 @@ interface StaticAssetRow { /** @internal */ export interface StaticAssetsStoreOptions { - database: PluginDatabaseManager; + database: DatabaseService; logger: LoggerService; } diff --git a/plugins/auth-backend/src/database/AuthDatabase.ts b/plugins/auth-backend/src/database/AuthDatabase.ts index ec4d2034e7..43b48401e2 100644 --- a/plugins/auth-backend/src/database/AuthDatabase.ts +++ b/plugins/auth-backend/src/database/AuthDatabase.ts @@ -14,11 +14,11 @@ * limitations under the License. */ +import { DatabaseManager } from '@backstage/backend-common'; import { - DatabaseManager, - PluginDatabaseManager, -} from '@backstage/backend-common'; -import { resolvePackagePath } from '@backstage/backend-plugin-api'; + DatabaseService, + resolvePackagePath, +} from '@backstage/backend-plugin-api'; import { ConfigReader } from '@backstage/config'; import { Knex } from 'knex'; @@ -32,10 +32,10 @@ const migrationsDir = resolvePackagePath( * asked for, and runs migrations. */ export class AuthDatabase { - readonly #database: PluginDatabaseManager; + readonly #database: DatabaseService; #promise: Promise | undefined; - static create(database: PluginDatabaseManager): AuthDatabase { + static create(database: DatabaseService): AuthDatabase { return new AuthDatabase(database); } @@ -60,7 +60,7 @@ export class AuthDatabase { }); } - private constructor(database: PluginDatabaseManager) { + private constructor(database: DatabaseService) { this.#database = database; } diff --git a/plugins/auth-backend/src/providers/router.ts b/plugins/auth-backend/src/providers/router.ts index e449372143..2867611075 100644 --- a/plugins/auth-backend/src/providers/router.ts +++ b/plugins/auth-backend/src/providers/router.ts @@ -14,12 +14,10 @@ * limitations under the License. */ -import { - PluginEndpointDiscovery, - TokenManager, -} from '@backstage/backend-common'; +import { TokenManager } from '@backstage/backend-common'; import { AuthService, + DiscoveryService, HttpAuthService, LoggerService, } from '@backstage/backend-plugin-api'; @@ -47,7 +45,7 @@ export function bindProviderRouters( baseUrl: string; config: Config; logger: LoggerService; - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; auth: AuthService; httpAuth: HttpAuthService; tokenManager?: TokenManager; diff --git a/plugins/auth-node/report.api.md b/plugins/auth-node/report.api.md index db61257f7a..e5f33b4e7e 100644 --- a/plugins/auth-node/report.api.md +++ b/plugins/auth-node/report.api.md @@ -6,6 +6,7 @@ import { BackstageIdentityResponse as BackstageIdentityResponse_2 } from '@backstage/plugin-auth-node'; import { BackstageSignInResult as BackstageSignInResult_2 } from '@backstage/plugin-auth-node'; import { Config } from '@backstage/config'; +import { DiscoveryService } from '@backstage/backend-plugin-api'; import { Entity } from '@backstage/catalog-model'; import { EntityFilterQuery } from '@backstage/catalog-client'; import express from 'express'; @@ -13,7 +14,6 @@ import { ExtensionPoint } from '@backstage/backend-plugin-api'; import { JsonObject } from '@backstage/types'; import { JsonValue } from '@backstage/types'; import { LoggerService } from '@backstage/backend-plugin-api'; -import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { Profile } from 'passport'; import { Request as Request_2 } from 'express'; import { Response as Response_2 } from 'express'; @@ -265,7 +265,7 @@ export class IdentityClient { // @public export type IdentityClientOptions = { - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; issuer?: string; algorithms?: string[]; }; diff --git a/plugins/auth-node/src/identity/DefaultIdentityClient.test.ts b/plugins/auth-node/src/identity/DefaultIdentityClient.test.ts index b9bf3cabd2..68765c6bef 100644 --- a/plugins/auth-node/src/identity/DefaultIdentityClient.test.ts +++ b/plugins/auth-node/src/identity/DefaultIdentityClient.test.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { PluginEndpointDiscovery } from '@backstage/backend-common'; + import { decodeProtectedHeader, exportJWK, @@ -27,6 +27,7 @@ import { v4 as uuid } from 'uuid'; import { DefaultIdentityClient } from './DefaultIdentityClient'; import { IdentityApiGetIdentityRequest } from './IdentityApi'; +import { DiscoveryService } from '@backstage/backend-plugin-api'; interface AnyJWK extends Record { use: 'sig'; @@ -87,7 +88,7 @@ function jwtKid(jwt: string): string { const server = setupServer(); const mockBaseUrl = 'http://backstage:9191/i-am-a-mock-base'; -const discovery: PluginEndpointDiscovery = { +const discovery: DiscoveryService = { async getBaseUrl() { return mockBaseUrl; }, diff --git a/plugins/auth-node/src/identity/DefaultIdentityClient.ts b/plugins/auth-node/src/identity/DefaultIdentityClient.ts index 1095609dec..6c417cc5c9 100644 --- a/plugins/auth-node/src/identity/DefaultIdentityClient.ts +++ b/plugins/auth-node/src/identity/DefaultIdentityClient.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { AuthenticationError } from '@backstage/errors'; import { createRemoteJWKSet, @@ -28,6 +27,7 @@ import { GetKeyFunction } from 'jose/dist/types/types'; import { getBearerTokenFromAuthorizationHeader } from './getBearerTokenFromAuthorizationHeader'; import { IdentityApi, IdentityApiGetIdentityRequest } from './IdentityApi'; import { BackstageIdentityResponse } from '../types'; +import { DiscoveryService } from '@backstage/backend-plugin-api'; const CLOCK_MARGIN_S = 10; @@ -38,7 +38,7 @@ const CLOCK_MARGIN_S = 10; * @public */ export type IdentityClientOptions = { - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; issuer?: string; /** JWS "alg" (Algorithm) Header Parameter values. Defaults to an array containing just ES256. @@ -54,7 +54,7 @@ export type IdentityClientOptions = { * @public */ export class DefaultIdentityClient implements IdentityApi { - private readonly discovery: PluginEndpointDiscovery; + private readonly discovery: DiscoveryService; private readonly issuer?: string; private readonly algorithms?: string[]; private keyStore?: GetKeyFunction; diff --git a/plugins/auth-node/src/identity/IdentityClient.test.ts b/plugins/auth-node/src/identity/IdentityClient.test.ts index 418eb544ad..91cd1759aa 100644 --- a/plugins/auth-node/src/identity/IdentityClient.test.ts +++ b/plugins/auth-node/src/identity/IdentityClient.test.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { registerMswTestHooks } from '@backstage/backend-test-utils'; import { decodeProtectedHeader, @@ -28,6 +27,7 @@ import { setupServer } from 'msw/node'; import { v4 as uuid } from 'uuid'; import { IdentityClient } from './IdentityClient'; +import { DiscoveryService } from '@backstage/backend-plugin-api'; interface AnyJWK extends Record { use: 'sig'; @@ -88,7 +88,7 @@ function jwtKid(jwt: string): string { const server = setupServer(); const mockBaseUrl = 'http://backstage:9191/i-am-a-mock-base'; -const discovery: PluginEndpointDiscovery = { +const discovery: DiscoveryService = { async getBaseUrl() { return mockBaseUrl; }, diff --git a/plugins/catalog-backend-module-github/report.api.md b/plugins/catalog-backend-module-github/report.api.md index dcc94e47bc..8cd87f646a 100644 --- a/plugins/catalog-backend-module-github/report.api.md +++ b/plugins/catalog-backend-module-github/report.api.md @@ -10,6 +10,7 @@ import { CatalogApi } from '@backstage/catalog-client'; import { CatalogProcessor } from '@backstage/plugin-catalog-node'; import { CatalogProcessorEmit } from '@backstage/plugin-catalog-node'; import { Config } from '@backstage/config'; +import { DiscoveryService } from '@backstage/backend-plugin-api'; import { Entity } from '@backstage/catalog-model'; import { EntityProvider } from '@backstage/plugin-catalog-node'; import { EntityProviderConnection } from '@backstage/plugin-catalog-node'; @@ -21,7 +22,6 @@ import { GithubIntegrationConfig } from '@backstage/integration'; import { graphql } from '@octokit/graphql'; import { LocationSpec } from '@backstage/plugin-catalog-node'; import { LoggerService } from '@backstage/backend-plugin-api'; -import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { SchedulerService } from '@backstage/backend-plugin-api'; import { SchedulerServiceTaskRunner } from '@backstage/backend-plugin-api'; import { ScmIntegrationRegistry } from '@backstage/integration'; @@ -127,7 +127,7 @@ export class GithubLocationAnalyzer implements ScmLocationAnalyzer { // @public (undocumented) export type GithubLocationAnalyzerOptions = { config: Config; - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; tokenManager?: TokenManager; auth?: AuthService; githubCredentialsProvider?: GithubCredentialsProvider; diff --git a/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.test.ts b/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.test.ts index d3be18f489..25a19ba1ff 100644 --- a/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.test.ts +++ b/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.test.ts @@ -32,7 +32,6 @@ jest.mock('@octokit/rest', () => { return { Octokit }; }); -import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { GithubLocationAnalyzer } from './GithubLocationAnalyzer'; import { registerMswTestHooks, @@ -40,26 +39,21 @@ import { } from '@backstage/backend-test-utils'; import { setupServer } from 'msw/node'; import { http, HttpResponse } from 'msw'; -import { ConfigReader } from '@backstage/config'; const server = setupServer(); describe('GithubLocationAnalyzer', () => { - const mockDiscoveryApi: jest.Mocked = { - getBaseUrl: jest.fn().mockResolvedValue('http://localhost:7007'), - getExternalBaseUrl: jest.fn(), - }; + const mockDiscovery = mockServices.discovery.mock({ + getBaseUrl: async () => 'http://localhost:7007', + }); const mockAuthService = mockServices.auth.mock({ getPluginRequestToken: async () => ({ token: 'abc123' }), }); - const config = new ConfigReader({ - integrations: { - github: [ - { - host: 'h.com', - token: 't', - }, - ], + const config = mockServices.rootConfig({ + data: { + integrations: { + github: [{ host: 'h.com', token: 't' }], + }, }, }); @@ -121,7 +115,7 @@ describe('GithubLocationAnalyzer', () => { }); const analyzer = new GithubLocationAnalyzer({ - discovery: mockDiscoveryApi, + discovery: mockDiscovery, auth: mockAuthService, config, }); @@ -148,7 +142,7 @@ describe('GithubLocationAnalyzer', () => { }); const analyzer = new GithubLocationAnalyzer({ - discovery: mockDiscoveryApi, + discovery: mockDiscovery, auth: mockAuthService, config, }); @@ -174,7 +168,7 @@ describe('GithubLocationAnalyzer', () => { }); const analyzer = new GithubLocationAnalyzer({ - discovery: mockDiscoveryApi, + discovery: mockDiscovery, auth: mockAuthService, config, }); diff --git a/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.ts b/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.ts index b635878f92..cbf43287a3 100644 --- a/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.ts +++ b/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.ts @@ -29,18 +29,17 @@ import { ScmLocationAnalyzer, } from '@backstage/plugin-catalog-node'; import { - PluginEndpointDiscovery, TokenManager, createLegacyAuthAdapters, } from '@backstage/backend-common'; import { Config } from '@backstage/config'; -import { AuthService } from '@backstage/backend-plugin-api'; +import { AuthService, DiscoveryService } from '@backstage/backend-plugin-api'; import { extname } from 'path'; /** @public */ export type GithubLocationAnalyzerOptions = { config: Config; - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; tokenManager?: TokenManager; auth?: AuthService; githubCredentialsProvider?: GithubCredentialsProvider; diff --git a/plugins/catalog-backend/report.api.md b/plugins/catalog-backend/report.api.md index dc277026f4..ea7e11d0d7 100644 --- a/plugins/catalog-backend/report.api.md +++ b/plugins/catalog-backend/report.api.md @@ -56,7 +56,6 @@ import { PlaceholderResolver as PlaceholderResolver_2 } from '@backstage/plugin- import { PlaceholderResolverParams as PlaceholderResolverParams_2 } from '@backstage/plugin-catalog-node'; import { PlaceholderResolverRead as PlaceholderResolverRead_2 } from '@backstage/plugin-catalog-node'; import { PlaceholderResolverResolveUrl as PlaceholderResolverResolveUrl_2 } from '@backstage/plugin-catalog-node'; -import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { RootConfigService } from '@backstage/backend-plugin-api'; import { Router } from 'express'; import { SchedulerService } from '@backstage/backend-plugin-api'; @@ -283,7 +282,7 @@ export function createRandomProcessingInterval(options: { // @public @deprecated (undocumented) export class DefaultCatalogCollator { constructor(options: { - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; tokenManager: TokenManager; locationTemplate?: string; filter?: GetEntitiesRequest['filter']; @@ -297,7 +296,7 @@ export class DefaultCatalogCollator { // (undocumented) protected readonly catalogClient: CatalogApi; // (undocumented) - protected discovery: PluginEndpointDiscovery; + protected discovery: DiscoveryService; // (undocumented) execute(): Promise; // (undocumented) @@ -306,7 +305,7 @@ export class DefaultCatalogCollator { static fromConfig( _config: Config, options: { - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; tokenManager: TokenManager; filter?: GetEntitiesRequest['filter']; }, diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts index aee65bd2e1..9473d45bb6 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts @@ -14,11 +14,11 @@ * limitations under the License. */ +import { TokenManager } from '@backstage/backend-common'; import { - PluginEndpointDiscovery, - TokenManager, -} from '@backstage/backend-common'; -import { registerMswTestHooks } from '@backstage/backend-test-utils'; + mockServices, + registerMswTestHooks, +} from '@backstage/backend-test-utils'; import { Entity } from '@backstage/catalog-model'; import { DefaultCatalogCollator } from './DefaultCatalogCollator'; import { setupServer } from 'msw/node'; @@ -58,22 +58,20 @@ const expectedEntities: Entity[] = [ ]; describe('DefaultCatalogCollator', () => { - let mockDiscoveryApi: jest.Mocked; + const mockDiscovery = mockServices.discovery.mock({ + getBaseUrl: async () => 'http://localhost:7007', + }); let mockTokenManager: jest.Mocked; let collator: DefaultCatalogCollator; registerMswTestHooks(server); beforeAll(() => { - mockDiscoveryApi = { - getBaseUrl: jest.fn().mockResolvedValue('http://localhost:7007'), - getExternalBaseUrl: jest.fn(), - }; mockTokenManager = { getToken: jest.fn().mockResolvedValue({ token: '' }), authenticate: jest.fn(), }; collator = new DefaultCatalogCollator({ - discovery: mockDiscoveryApi, + discovery: mockDiscovery, tokenManager: mockTokenManager, }); }); @@ -98,7 +96,7 @@ describe('DefaultCatalogCollator', () => { it('fetches from the configured catalog service', async () => { const documents = await collator.execute(); - expect(mockDiscoveryApi.getBaseUrl).toHaveBeenCalledWith('catalog'); + expect(mockDiscovery.getBaseUrl).toHaveBeenCalledWith('catalog'); expect(documents).toHaveLength(expectedEntities.length); }); @@ -133,7 +131,7 @@ describe('DefaultCatalogCollator', () => { it('maps a returned entity with a custom locationTemplate', async () => { // Provide an alternate location template. collator = new DefaultCatalogCollator({ - discovery: mockDiscoveryApi, + discovery: mockDiscovery, tokenManager: mockTokenManager, locationTemplate: '/software/:name', }); @@ -147,7 +145,7 @@ describe('DefaultCatalogCollator', () => { it('allows filtering of the retrieved catalog entities', async () => { // Provide an alternate location template. collator = DefaultCatalogCollator.fromConfig(new ConfigReader({}), { - discovery: mockDiscoveryApi, + discovery: mockDiscovery, tokenManager: mockTokenManager, filter: { kind: ['Foo', 'Bar'], diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index 74aab07fc3..11f6030ce6 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -14,10 +14,7 @@ * limitations under the License. */ -import { - PluginEndpointDiscovery, - TokenManager, -} from '@backstage/backend-common'; +import { TokenManager } from '@backstage/backend-common'; import { Entity, isUserEntity, @@ -32,6 +29,7 @@ import { import { catalogEntityReadPermission } from '@backstage/plugin-catalog-common/alpha'; import { CatalogEntityDocument } from '@backstage/plugin-catalog-common'; import { Permission } from '@backstage/plugin-permission-common'; +import { DiscoveryService } from '@backstage/backend-plugin-api'; /** * @public @@ -39,7 +37,7 @@ import { Permission } from '@backstage/plugin-permission-common'; * use `DefaultCatalogCollatorFactory` instead. */ export class DefaultCatalogCollator { - protected discovery: PluginEndpointDiscovery; + protected discovery: DiscoveryService; protected locationTemplate: string; protected filter?: GetEntitiesRequest['filter']; protected readonly catalogClient: CatalogApi; @@ -51,7 +49,7 @@ export class DefaultCatalogCollator { static fromConfig( _config: Config, options: { - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; tokenManager: TokenManager; filter?: GetEntitiesRequest['filter']; }, @@ -62,7 +60,7 @@ export class DefaultCatalogCollator { } constructor(options: { - discovery: PluginEndpointDiscovery; + discovery: DiscoveryService; tokenManager: TokenManager; locationTemplate?: string; filter?: GetEntitiesRequest['filter']; diff --git a/plugins/scaffolder-backend/report.api.md b/plugins/scaffolder-backend/report.api.md index c2e6c18ad8..20273697d3 100644 --- a/plugins/scaffolder-backend/report.api.md +++ b/plugins/scaffolder-backend/report.api.md @@ -39,7 +39,6 @@ import { PermissionEvaluator } from '@backstage/plugin-permission-common'; import { PermissionRule } from '@backstage/plugin-permission-node'; import { PermissionRuleParams } from '@backstage/plugin-permission-common'; import { PermissionsService } from '@backstage/backend-plugin-api'; -import { PluginDatabaseManager } from '@backstage/backend-common'; import { RESOURCE_TYPE_SCAFFOLDER_ACTION } from '@backstage/plugin-scaffolder-common/alpha'; import { RESOURCE_TYPE_SCAFFOLDER_TEMPLATE } from '@backstage/plugin-scaffolder-common/alpha'; import { ScaffolderEntitiesProcessor as ScaffolderEntitiesProcessor_2 } from '@backstage/plugin-catalog-backend-module-scaffolder-entity-model'; @@ -520,7 +519,7 @@ export class DatabaseTaskStore implements TaskStore { // @public export type DatabaseTaskStoreOptions = { - database: PluginDatabaseManager | Knex; + database: DatabaseService | Knex; events?: EventsService; }; diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/DatabaseTaskStore.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/DatabaseTaskStore.ts index 8114532566..4dbe938679 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/DatabaseTaskStore.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/DatabaseTaskStore.ts @@ -15,8 +15,10 @@ */ import { JsonObject } from '@backstage/types'; -import { PluginDatabaseManager } from '@backstage/backend-common'; -import { resolvePackagePath } from '@backstage/backend-plugin-api'; +import { + DatabaseService, + resolvePackagePath, +} from '@backstage/backend-plugin-api'; import { ConflictError, NotFoundError } from '@backstage/errors'; import { Knex } from 'knex'; import { v4 as uuid } from 'uuid'; @@ -78,19 +80,19 @@ export type RawDbTaskEventRow = { * @public */ export type DatabaseTaskStoreOptions = { - database: PluginDatabaseManager | Knex; + database: DatabaseService | Knex; events?: EventsService; }; /** - * Type guard to help DatabaseTaskStore understand when database is PluginDatabaseManager vs. when database is a Knex instance. + * Type guard to help DatabaseTaskStore understand when database is DatabaseService vs. when database is a Knex instance. * * * @public */ -function isPluginDatabaseManager( - opt: PluginDatabaseManager | Knex, -): opt is PluginDatabaseManager { - return (opt as PluginDatabaseManager).getClient !== undefined; +function isDatabaseService( + opt: DatabaseService | Knex, +): opt is DatabaseService { + return (opt as DatabaseService).getClient !== undefined; } const parseSqlDateToIsoString = (input: T): T | string => { @@ -152,9 +154,9 @@ export class DatabaseTaskStore implements TaskStore { } private static async getClient( - database: PluginDatabaseManager | Knex, + database: DatabaseService | Knex, ): Promise { - if (isPluginDatabaseManager(database)) { + if (isDatabaseService(database)) { return database.getClient(); } @@ -162,10 +164,10 @@ export class DatabaseTaskStore implements TaskStore { } private static async runMigrations( - database: PluginDatabaseManager | Knex, + database: DatabaseService | Knex, client: Knex, ): Promise { - if (!isPluginDatabaseManager(database)) { + if (!isDatabaseService(database)) { await client.migrate.latest({ directory: migrationsDir, }); diff --git a/plugins/scaffolder-backend/src/service/router.test.ts b/plugins/scaffolder-backend/src/service/router.test.ts index 55d8b91293..42a89cc7f3 100644 --- a/plugins/scaffolder-backend/src/service/router.test.ts +++ b/plugins/scaffolder-backend/src/service/router.test.ts @@ -17,7 +17,6 @@ import { DatabaseManager, loggerToWinstonLogger, - PluginDatabaseManager, } from '@backstage/backend-common'; import { ConfigReader } from '@backstage/config'; import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common'; @@ -52,6 +51,7 @@ import { AutocompleteHandler } from '@backstage/plugin-scaffolder-node/alpha'; import { UrlReaders } from '@backstage/backend-defaults/urlReader'; import { catalogServiceMock } from '@backstage/plugin-catalog-node/testUtils'; import { EventsService } from '@backstage/plugin-events-node'; +import { DatabaseService } from '@backstage/backend-plugin-api'; const mockAccess = jest.fn(); @@ -68,7 +68,7 @@ jest.mock('fs-extra', () => ({ remove: jest.fn(), })); -function createDatabase(): PluginDatabaseManager { +function createDatabase(): DatabaseService { return DatabaseManager.fromConfig( new ConfigReader({ backend: { diff --git a/yarn.lock b/yarn.lock index 2446999bfd..5cd3455dbd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4809,7 +4809,6 @@ __metadata: resolution: "@backstage/plugin-app-backend@workspace:plugins/app-backend" dependencies: "@backstage/backend-app-api": "workspace:^" - "@backstage/backend-common": ^0.25.0 "@backstage/backend-defaults": "workspace:^" "@backstage/backend-plugin-api": "workspace:^" "@backstage/backend-test-utils": "workspace:^"