From eb1ee0331e80e7d0d95c5813001ce6bd285381ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 5 Jun 2025 11:37:23 +0200 Subject: [PATCH 1/2] remove some usages of the old alpha catalog service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- ...talogModuleBitbucketCloudEntityProvider.ts | 16 ++- .../BitbucketCloudEntityProvider.test.ts | 115 +++++++++--------- .../providers/BitbucketCloudEntityProvider.ts | 24 ++-- .../src/module.ts | 3 +- .../processor/NotificationsEmailProcessor.ts | 17 +-- plugins/notifications-backend/package.json | 1 - plugins/notifications-backend/src/plugin.ts | 2 +- .../src/service/getUsersForEntityRef.test.ts | 22 ++-- .../src/service/getUsersForEntityRef.ts | 24 ++-- .../src/service/router.ts | 6 +- yarn.lock | 1 - 11 files changed, 107 insertions(+), 124 deletions(-) diff --git a/plugins/catalog-backend-module-bitbucket-cloud/src/module/catalogModuleBitbucketCloudEntityProvider.ts b/plugins/catalog-backend-module-bitbucket-cloud/src/module/catalogModuleBitbucketCloudEntityProvider.ts index 91f20c157c..3ff6556d40 100644 --- a/plugins/catalog-backend-module-bitbucket-cloud/src/module/catalogModuleBitbucketCloudEntityProvider.ts +++ b/plugins/catalog-backend-module-bitbucket-cloud/src/module/catalogModuleBitbucketCloudEntityProvider.ts @@ -18,10 +18,8 @@ import { coreServices, createBackendModule, } from '@backstage/backend-plugin-api'; -import { - catalogProcessingExtensionPoint, - catalogServiceRef, -} from '@backstage/plugin-catalog-node/alpha'; +import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha'; +import { catalogServiceRef } from '@backstage/plugin-catalog-node'; import { eventsServiceRef } from '@backstage/plugin-events-node'; import { BitbucketCloudEntityProvider } from '../providers/BitbucketCloudEntityProvider'; @@ -35,8 +33,8 @@ export const catalogModuleBitbucketCloudEntityProvider = createBackendModule({ env.registerInit({ deps: { auth: coreServices.auth, - catalog: catalogProcessingExtensionPoint, - catalogApi: catalogServiceRef, + catalogProcessing: catalogProcessingExtensionPoint, + catalog: catalogServiceRef, config: coreServices.rootConfig, events: eventsServiceRef, logger: coreServices.logger, @@ -44,8 +42,8 @@ export const catalogModuleBitbucketCloudEntityProvider = createBackendModule({ }, async init({ auth, + catalogProcessing, catalog, - catalogApi, config, events, logger, @@ -53,13 +51,13 @@ export const catalogModuleBitbucketCloudEntityProvider = createBackendModule({ }) { const providers = BitbucketCloudEntityProvider.fromConfig(config, { auth, - catalogApi, + catalog, events, logger, scheduler, }); - catalog.addEntityProvider(providers); + catalogProcessing.addEntityProvider(providers); }, }); }, diff --git a/plugins/catalog-backend-module-bitbucket-cloud/src/providers/BitbucketCloudEntityProvider.test.ts b/plugins/catalog-backend-module-bitbucket-cloud/src/providers/BitbucketCloudEntityProvider.test.ts index 6ea92dac96..1b8d4b4e03 100644 --- a/plugins/catalog-backend-module-bitbucket-cloud/src/providers/BitbucketCloudEntityProvider.test.ts +++ b/plugins/catalog-backend-module-bitbucket-cloud/src/providers/BitbucketCloudEntityProvider.test.ts @@ -15,6 +15,7 @@ */ import { + BackstageCredentials, SchedulerServiceTaskInvocationDefinition, SchedulerServiceTaskRunner, } from '@backstage/backend-plugin-api'; @@ -201,13 +202,13 @@ describe('BitbucketCloudEntityProvider', () => { }); it('no provider config', () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); const config = new ConfigReader({}); const events = DefaultEventsService.create({ logger }); const providers = BitbucketCloudEntityProvider.fromConfig(config, { auth, - catalogApi, + catalog, events, logger, schedule, @@ -217,12 +218,12 @@ describe('BitbucketCloudEntityProvider', () => { }); it('single simple provider config', () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); const events = DefaultEventsService.create({ logger }); const providers = BitbucketCloudEntityProvider.fromConfig(simpleConfig, { auth, - catalogApi, + catalog, events, logger, schedule, @@ -235,14 +236,14 @@ describe('BitbucketCloudEntityProvider', () => { }); it('fail without schedule and scheduler', () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); const events = DefaultEventsService.create({ logger }); expect(() => BitbucketCloudEntityProvider.fromConfig(simpleConfig, { auth, - catalogApi, + catalog, events, logger, }), @@ -250,8 +251,8 @@ describe('BitbucketCloudEntityProvider', () => { }); it('fail with scheduler but no schedule config', () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); const events = DefaultEventsService.create({ logger }); const scheduler = mockServices.scheduler.mock(); const config = new ConfigReader({ @@ -267,7 +268,7 @@ describe('BitbucketCloudEntityProvider', () => { expect(() => BitbucketCloudEntityProvider.fromConfig(config, { auth, - catalogApi, + catalog, events, logger, scheduler, @@ -278,8 +279,8 @@ describe('BitbucketCloudEntityProvider', () => { }); it('single simple provider config with schedule in config', () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); const events = DefaultEventsService.create({ logger }); const scheduler = mockServices.scheduler.mock(); const config = new ConfigReader({ @@ -298,7 +299,7 @@ describe('BitbucketCloudEntityProvider', () => { const providers = BitbucketCloudEntityProvider.fromConfig(config, { auth, - catalogApi, + catalog, events, logger, scheduler, @@ -311,8 +312,8 @@ describe('BitbucketCloudEntityProvider', () => { }); it('multiple provider configs', () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); const config = new ConfigReader({ catalog: { providers: { @@ -330,7 +331,7 @@ describe('BitbucketCloudEntityProvider', () => { const events = DefaultEventsService.create({ logger }); const providers = BitbucketCloudEntityProvider.fromConfig(config, { auth, - catalogApi, + catalog, events, logger, schedule, @@ -346,12 +347,12 @@ describe('BitbucketCloudEntityProvider', () => { }); it('apply full update on scheduled execution', async () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); const events = DefaultEventsService.create({ logger }); const provider = BitbucketCloudEntityProvider.fromConfig(defaultConfig, { auth, - catalogApi, + catalog, events, logger, schedule, @@ -559,17 +560,14 @@ describe('BitbucketCloudEntityProvider', () => { 'added-module/catalog-custom.yaml', ); - const auth = mockServices.auth.mock({ - getPluginRequestToken: async () => ({ token: 'fake-token' }), - }); + const auth = mockServices.auth(); const events = DefaultEventsService.create({ logger }); - const catalogApi = catalogServiceMock.mock({ + const catalog = catalogServiceMock.mock({ getEntities: async ( request: { filter: Record }, - options: { token: string }, + _options: { credentials: BackstageCredentials }, ): Promise<{ items: Entity[] }> => { if ( - options.token !== 'fake-token' || request.filter.kind !== 'Location' || request.filter['metadata.annotations.bitbucket.org/repo-url'] !== 'https://bitbucket.org/test-ws/test-repo' @@ -584,7 +582,7 @@ describe('BitbucketCloudEntityProvider', () => { }); const provider = BitbucketCloudEntityProvider.fromConfig(defaultConfig, { auth, - catalogApi, + catalog, events, logger, schedule, @@ -695,13 +693,13 @@ describe('BitbucketCloudEntityProvider', () => { }); it('no onRepoPush update on non-matching workspace slug', async () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); - jest.spyOn(catalogApi, 'refreshEntity'); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); + jest.spyOn(catalog, 'refreshEntity'); const events = DefaultEventsService.create({ logger }); const provider = BitbucketCloudEntityProvider.fromConfig(defaultConfig, { auth, - catalogApi, + catalog, events, logger, schedule, @@ -722,18 +720,18 @@ describe('BitbucketCloudEntityProvider', () => { }, }); - expect(catalogApi.refreshEntity).toHaveBeenCalledTimes(0); + expect(catalog.refreshEntity).toHaveBeenCalledTimes(0); expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(0); }); it('no onRepoPush update on non-matching repo slug', async () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); - jest.spyOn(catalogApi, 'refreshEntity'); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); + jest.spyOn(catalog, 'refreshEntity'); const events = DefaultEventsService.create({ logger }); const provider = BitbucketCloudEntityProvider.fromConfig(defaultConfig, { auth, - catalogApi, + catalog, events, logger, schedule, @@ -751,7 +749,7 @@ describe('BitbucketCloudEntityProvider', () => { }, }); - expect(catalogApi.refreshEntity).toHaveBeenCalledTimes(0); + expect(catalog.refreshEntity).toHaveBeenCalledTimes(0); expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(0); }); @@ -767,17 +765,14 @@ describe('BitbucketCloudEntityProvider', () => { 'module/catalog-custom.yaml', ); - const auth = mockServices.auth.mock({ - getPluginRequestToken: async () => ({ token: 'fake-token' }), - }); + const auth = mockServices.auth(); const events = DefaultEventsService.create({ logger }); - const catalogApi = catalogServiceMock.mock({ + const catalog = catalogServiceMock.mock({ getEntities: async ( request: { filter: Record }, - options: { token: string }, + _options: { credentials: BackstageCredentials }, ): Promise<{ items: Entity[] }> => { if ( - options.token !== 'fake-token' || request.filter.kind !== 'Location' || request.filter['metadata.annotations.bitbucket.org/repo-url'] !== 'https://bitbucket.org/test-ws/test-repo-old' @@ -792,7 +787,7 @@ describe('BitbucketCloudEntityProvider', () => { }); const provider = BitbucketCloudEntityProvider.fromConfig(defaultConfig, { auth, - catalogApi, + catalog, events, logger, schedule, @@ -870,13 +865,13 @@ describe('BitbucketCloudEntityProvider', () => { }); it('no onRepoUpdated update on non-matching workspace slug', async () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); - jest.spyOn(catalogApi, 'refreshEntity'); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); + jest.spyOn(catalog, 'refreshEntity'); const events = DefaultEventsService.create({ logger }); const provider = BitbucketCloudEntityProvider.fromConfig(defaultConfig, { auth, - catalogApi, + catalog, events, logger, schedule, @@ -897,18 +892,18 @@ describe('BitbucketCloudEntityProvider', () => { }, }); - expect(catalogApi.refreshEntity).toHaveBeenCalledTimes(0); + expect(catalog.refreshEntity).toHaveBeenCalledTimes(0); expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(0); }); it('no onRepoUpdated update on non-matching repo slug', async () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); - jest.spyOn(catalogApi, 'refreshEntity'); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); + jest.spyOn(catalog, 'refreshEntity'); const events = DefaultEventsService.create({ logger }); const provider = BitbucketCloudEntityProvider.fromConfig(defaultConfig, { auth, - catalogApi, + catalog, events, logger, schedule, @@ -926,18 +921,18 @@ describe('BitbucketCloudEntityProvider', () => { }, }); - expect(catalogApi.refreshEntity).toHaveBeenCalledTimes(0); + expect(catalog.refreshEntity).toHaveBeenCalledTimes(0); expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(0); }); it('no onRepoUpdated update on non-relevant repo update', async () => { - const auth = mockServices.auth.mock(); - const catalogApi = catalogServiceMock(); - jest.spyOn(catalogApi, 'refreshEntity'); + const auth = mockServices.auth(); + const catalog = catalogServiceMock(); + jest.spyOn(catalog, 'refreshEntity'); const events = DefaultEventsService.create({ logger }); const provider = BitbucketCloudEntityProvider.fromConfig(defaultConfig, { auth, - catalogApi, + catalog, events, logger, schedule, @@ -957,7 +952,7 @@ describe('BitbucketCloudEntityProvider', () => { }, }); - expect(catalogApi.refreshEntity).toHaveBeenCalledTimes(0); + expect(catalog.refreshEntity).toHaveBeenCalledTimes(0); expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(0); }); }); diff --git a/plugins/catalog-backend-module-bitbucket-cloud/src/providers/BitbucketCloudEntityProvider.ts b/plugins/catalog-backend-module-bitbucket-cloud/src/providers/BitbucketCloudEntityProvider.ts index 88d0cb80ef..64a58c2924 100644 --- a/plugins/catalog-backend-module-bitbucket-cloud/src/providers/BitbucketCloudEntityProvider.ts +++ b/plugins/catalog-backend-module-bitbucket-cloud/src/providers/BitbucketCloudEntityProvider.ts @@ -20,7 +20,6 @@ import { SchedulerService, SchedulerServiceTaskRunner, } from '@backstage/backend-plugin-api'; -import { CatalogApi } from '@backstage/catalog-client'; import { LocationEntity } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import { @@ -33,6 +32,7 @@ import { Models, } from '@backstage/plugin-bitbucket-cloud-common'; import { + CatalogService, DeferredEntity, EntityProvider, EntityProviderConnection, @@ -68,7 +68,7 @@ interface IngestionTarget { */ export class BitbucketCloudEntityProvider implements EntityProvider { private readonly auth: AuthService; - private readonly catalogApi: CatalogApi; + private readonly catalog: CatalogService; private readonly client: BitbucketCloudClient; private readonly config: BitbucketCloudEntityProviderConfig; private readonly events: EventsService; @@ -81,7 +81,7 @@ export class BitbucketCloudEntityProvider implements EntityProvider { config: Config, options: { auth: AuthService; - catalogApi: CatalogApi; + catalog: CatalogService; events: EventsService; logger: LoggerService; schedule?: SchedulerServiceTaskRunner; @@ -113,7 +113,7 @@ export class BitbucketCloudEntityProvider implements EntityProvider { return new BitbucketCloudEntityProvider( options.auth, - options.catalogApi, + options.catalog, providerConfig, options.events, integration, @@ -125,7 +125,7 @@ export class BitbucketCloudEntityProvider implements EntityProvider { private constructor( auth: AuthService, - catalogApi: CatalogApi, + catalog: CatalogService, config: BitbucketCloudEntityProviderConfig, events: EventsService, integration: BitbucketCloudIntegration, @@ -133,7 +133,7 @@ export class BitbucketCloudEntityProvider implements EntityProvider { taskRunner: SchedulerServiceTaskRunner, ) { this.auth = auth; - this.catalogApi = catalogApi; + this.catalog = catalog; this.client = BitbucketCloudClient.fromConfig(integration.config); this.config = config; this.events = events; @@ -350,13 +350,11 @@ export class BitbucketCloudEntityProvider implements EntityProvider { filter[`metadata.annotations.${ANNOTATION_BITBUCKET_CLOUD_REPO_URL}`] = repoUrl; - const { token } = await this.auth.getPluginRequestToken({ - onBehalfOf: await this.auth.getOwnServiceCredentials(), - targetPluginId: 'catalog', - }); - - return this.catalogApi - .getEntities({ filter }, { token }) + return this.catalog + .getEntities( + { filter }, + { credentials: await this.auth.getOwnServiceCredentials() }, + ) .then(result => result.items) as Promise; } diff --git a/plugins/notifications-backend-module-email/src/module.ts b/plugins/notifications-backend-module-email/src/module.ts index c83d27b6a3..0ee7e811b4 100644 --- a/plugins/notifications-backend-module-email/src/module.ts +++ b/plugins/notifications-backend-module-email/src/module.ts @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { coreServices, createBackendModule, } from '@backstage/backend-plugin-api'; -import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha'; +import { catalogServiceRef } from '@backstage/plugin-catalog-node'; import { notificationsProcessingExtensionPoint } from '@backstage/plugin-notifications-node'; import { NotificationsEmailProcessor } from './processor'; import { diff --git a/plugins/notifications-backend-module-email/src/processor/NotificationsEmailProcessor.ts b/plugins/notifications-backend-module-email/src/processor/NotificationsEmailProcessor.ts index d165973424..3496d431e3 100644 --- a/plugins/notifications-backend-module-email/src/processor/NotificationsEmailProcessor.ts +++ b/plugins/notifications-backend-module-email/src/processor/NotificationsEmailProcessor.ts @@ -25,7 +25,7 @@ import { } from '@backstage/backend-plugin-api'; import { Config, readDurationFromConfig } from '@backstage/config'; import { durationToMilliseconds } from '@backstage/types'; -import { CATALOG_FILTER_EXISTS, CatalogApi } from '@backstage/catalog-client'; +import { CATALOG_FILTER_EXISTS } from '@backstage/catalog-client'; import { getProcessorFiltersFromConfig, Notification, @@ -39,6 +39,7 @@ import { createStreamTransport, } from './transports'; import { UserEntity } from '@backstage/catalog-model'; +import { CatalogService } from '@backstage/plugin-catalog-node'; import { compact } from 'lodash'; import { DefaultAwsCredentialsManager } from '@backstage/integration-aws-node'; import { NotificationTemplateRenderer } from '../extensions'; @@ -62,7 +63,7 @@ export class NotificationsEmailProcessor implements NotificationProcessor { constructor( private readonly logger: LoggerService, private readonly config: Config, - private readonly catalog: CatalogApi, + private readonly catalog: CatalogService, private readonly auth: AuthService, private readonly cache?: CacheService, private readonly templateRenderer?: NotificationTemplateRenderer, @@ -152,10 +153,6 @@ export class NotificationsEmailProcessor implements NotificationProcessor { return cached; } - const { token } = await this.auth.getPluginRequestToken({ - onBehalfOf: await this.auth.getOwnServiceCredentials(), - targetPluginId: 'catalog', - }); const entities = await this.catalog.getEntities( { filter: [ @@ -163,7 +160,7 @@ export class NotificationsEmailProcessor implements NotificationProcessor { ], fields: ['spec.profile.email'], }, - { token }, + { credentials: await this.auth.getOwnServiceCredentials() }, ); const ret = compact([ ...new Set( @@ -188,11 +185,9 @@ export class NotificationsEmailProcessor implements NotificationProcessor { return cached; } - const { token } = await this.auth.getPluginRequestToken({ - onBehalfOf: await this.auth.getOwnServiceCredentials(), - targetPluginId: 'catalog', + const entity = await this.catalog.getEntityByRef(entityRef, { + credentials: await this.auth.getOwnServiceCredentials(), }); - const entity = await this.catalog.getEntityByRef(entityRef, { token }); const ret: string[] = []; if (entity) { const userEntity = entity as UserEntity; diff --git a/plugins/notifications-backend/package.json b/plugins/notifications-backend/package.json index afecde5df4..f94548d377 100644 --- a/plugins/notifications-backend/package.json +++ b/plugins/notifications-backend/package.json @@ -40,7 +40,6 @@ }, "dependencies": { "@backstage/backend-plugin-api": "workspace:^", - "@backstage/catalog-client": "workspace:^", "@backstage/catalog-model": "workspace:^", "@backstage/config": "workspace:^", "@backstage/errors": "workspace:^", diff --git a/plugins/notifications-backend/src/plugin.ts b/plugins/notifications-backend/src/plugin.ts index 84a200bae1..a5a31d92ed 100644 --- a/plugins/notifications-backend/src/plugin.ts +++ b/plugins/notifications-backend/src/plugin.ts @@ -25,7 +25,7 @@ import { notificationsProcessingExtensionPoint, NotificationsProcessingExtensionPoint, } from '@backstage/plugin-notifications-node'; -import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha'; +import { catalogServiceRef } from '@backstage/plugin-catalog-node'; class NotificationsProcessingExtensionPointImpl implements NotificationsProcessingExtensionPoint diff --git a/plugins/notifications-backend/src/service/getUsersForEntityRef.test.ts b/plugins/notifications-backend/src/service/getUsersForEntityRef.test.ts index eba03511bb..838ded5c18 100644 --- a/plugins/notifications-backend/src/service/getUsersForEntityRef.test.ts +++ b/plugins/notifications-backend/src/service/getUsersForEntityRef.test.ts @@ -28,25 +28,25 @@ describe('getUsersForEntityRef', () => { await expect( getUsersForEntityRef(null, [], { auth: mockServices.auth(), - catalogClient: catalogServiceMock(), + catalog: catalogServiceMock(), }), ).resolves.toEqual([]); }); it('should resolve users without calling catalog', async () => { - const catalogClient = catalogServiceMock(); - jest.spyOn(catalogClient, 'getEntitiesByRefs'); + const catalog = catalogServiceMock(); + jest.spyOn(catalog, 'getEntitiesByRefs'); await expect( getUsersForEntityRef(['user:foo', 'user:ignored'], ['user:ignored'], { auth: mockServices.auth(), - catalogClient, + catalog, }), ).resolves.toEqual(['user:foo']); - expect(catalogClient.getEntitiesByRefs).not.toHaveBeenCalled(); + expect(catalog.getEntitiesByRefs).not.toHaveBeenCalled(); }); it('should resolve group entities to users', async () => { - const catalogClient = catalogServiceMock({ + const catalog = catalogServiceMock({ entities: [ { apiVersion: 'backstage.io/v1alpha1', @@ -91,14 +91,14 @@ describe('getUsersForEntityRef', () => { ['user:default/ignored'], { auth: mockServices.auth(), - catalogClient, + catalog, }, ), ).resolves.toEqual(['user:default/foo', 'user:default/bar']); }); it('should resolve user owner of entity from entity ref', async () => { - const catalogClient = catalogServiceMock({ + const catalog = catalogServiceMock({ entities: [ { apiVersion: 'backstage.io/v1alpha1', @@ -119,13 +119,13 @@ describe('getUsersForEntityRef', () => { await expect( getUsersForEntityRef('component:default/test_component', [], { auth: mockServices.auth(), - catalogClient, + catalog, }), ).resolves.toEqual(['user:default/foo']); }); it('should resolve group owner of entity from entity ref', async () => { - const catalogClient = catalogServiceMock({ + const catalog = catalogServiceMock({ entities: [ { apiVersion: 'backstage.io/v1alpha1', @@ -159,7 +159,7 @@ describe('getUsersForEntityRef', () => { await expect( getUsersForEntityRef('component:default/test_component', [], { auth: mockServices.auth(), - catalogClient, + catalog, }), ).resolves.toEqual(['user:default/foo']); }); diff --git a/plugins/notifications-backend/src/service/getUsersForEntityRef.ts b/plugins/notifications-backend/src/service/getUsersForEntityRef.ts index 9ced24709b..2fa1412992 100644 --- a/plugins/notifications-backend/src/service/getUsersForEntityRef.ts +++ b/plugins/notifications-backend/src/service/getUsersForEntityRef.ts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { Entity, isGroupEntity, @@ -24,7 +25,7 @@ import { stringifyEntityRef, } from '@backstage/catalog-model'; import { AuthService } from '@backstage/backend-plugin-api'; -import { CatalogApi } from '@backstage/catalog-client'; +import { CatalogService } from '@backstage/plugin-catalog-node'; const isUserEntityRef = (ref: string) => parseEntityRef(ref).kind.toLocaleLowerCase() === 'user'; @@ -45,20 +46,15 @@ export const getUsersForEntityRef = async ( excludeEntityRefs: string | string[], options: { auth: AuthService; - catalogClient: CatalogApi; + catalog: CatalogService; }, ): Promise => { - const { auth, catalogClient } = options; + const { auth, catalog } = options; if (entityRef === null) { return []; } - const { token } = await auth.getPluginRequestToken({ - onBehalfOf: await auth.getOwnServiceCredentials(), - targetPluginId: 'catalog', - }); - const excluded = Array.isArray(excludeEntityRefs) ? excludeEntityRefs : [excludeEntityRefs]; @@ -71,12 +67,12 @@ export const getUsersForEntityRef = async ( const fields = ['kind', 'metadata.name', 'metadata.namespace', 'relations']; let entities: Array = []; if (entityRefs.length > 0) { - const fetchedEntities = await catalogClient.getEntitiesByRefs( + const fetchedEntities = await catalog.getEntitiesByRefs( { entityRefs, fields, }, - { token }, + { credentials: await auth.getOwnServiceCredentials() }, ); entities = fetchedEntities.items; } @@ -114,12 +110,12 @@ export const getUsersForEntityRef = async ( let childGroupUsers: string[][] = []; if (childGroupRefs.length > 0) { - const childGroups = await catalogClient.getEntitiesByRefs( + const childGroups = await catalog.getEntitiesByRefs( { entityRefs: childGroupRefs, fields, }, - { token }, + { credentials: await auth.getOwnServiceCredentials() }, ); childGroupUsers = await Promise.all(childGroups.items.map(mapEntity)); } @@ -145,7 +141,9 @@ export const getUsersForEntityRef = async ( return [ownerRef]; } - const owner = await catalogClient.getEntityByRef(ownerRef, { token }); + const owner = await catalog.getEntityByRef(ownerRef, { + credentials: await auth.getOwnServiceCredentials(), + }); return mapEntity(owner); } diff --git a/plugins/notifications-backend/src/service/router.ts b/plugins/notifications-backend/src/service/router.ts index ebf62c9fa0..f502d49cc4 100644 --- a/plugins/notifications-backend/src/service/router.ts +++ b/plugins/notifications-backend/src/service/router.ts @@ -23,7 +23,7 @@ import { TopicGetOptions, } from '../database'; import { v4 as uuid } from 'uuid'; -import { CatalogApi } from '@backstage/catalog-client'; +import { CatalogService } from '@backstage/plugin-catalog-node'; import { NotificationProcessor, NotificationSendOptions, @@ -63,7 +63,7 @@ export interface RouterOptions { httpAuth: HttpAuthService; userInfo: UserInfoService; signals?: SignalsService; - catalog: CatalogApi; + catalog: CatalogService; processors?: NotificationProcessor[]; } @@ -672,7 +672,7 @@ export async function createRouter( users = await getUsersForEntityRef( entityRef, recipients.excludeEntityRef ?? [], - { auth, catalogClient: catalog }, + { auth, catalog }, ); } catch (e) { throw new InputError('Failed to resolve notification receivers', e); diff --git a/yarn.lock b/yarn.lock index 8803ac52e2..142885e348 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7082,7 +7082,6 @@ __metadata: "@backstage/backend-defaults": "workspace:^" "@backstage/backend-plugin-api": "workspace:^" "@backstage/backend-test-utils": "workspace:^" - "@backstage/catalog-client": "workspace:^" "@backstage/catalog-model": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/config": "workspace:^" From 8a150bf8e1f91f9db941bb6589222b9dd62da91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 5 Jun 2025 12:37:38 +0200 Subject: [PATCH 2/2] review fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/khaki-swans-invite.md | 6 ++++++ .changeset/some-llamas-go.md | 5 +++++ .../catalog-backend-module-bitbucket-cloud/report.api.md | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/khaki-swans-invite.md create mode 100644 .changeset/some-llamas-go.md diff --git a/.changeset/khaki-swans-invite.md b/.changeset/khaki-swans-invite.md new file mode 100644 index 0000000000..4e768a1978 --- /dev/null +++ b/.changeset/khaki-swans-invite.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-notifications-backend-module-email': patch +'@backstage/plugin-notifications-backend': patch +--- + +Internal changes to switch to the non-alpha `catalogServiceRef` diff --git a/.changeset/some-llamas-go.md b/.changeset/some-llamas-go.md new file mode 100644 index 0000000000..d07b6a6c75 --- /dev/null +++ b/.changeset/some-llamas-go.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-bitbucket-cloud': minor +--- + +**BREAKING**: `BitbucketCloudEntityProvider` now accepts a `CatalogService` instead of a `CatalogApi`. diff --git a/plugins/catalog-backend-module-bitbucket-cloud/report.api.md b/plugins/catalog-backend-module-bitbucket-cloud/report.api.md index 77b20e44f1..74fc90680e 100644 --- a/plugins/catalog-backend-module-bitbucket-cloud/report.api.md +++ b/plugins/catalog-backend-module-bitbucket-cloud/report.api.md @@ -5,7 +5,7 @@ ```ts import { AuthService } from '@backstage/backend-plugin-api'; import { BackendFeature } from '@backstage/backend-plugin-api'; -import { CatalogApi } from '@backstage/catalog-client'; +import { CatalogService } from '@backstage/plugin-catalog-node'; import { Config } from '@backstage/config'; import { EntityProvider } from '@backstage/plugin-catalog-node'; import { EntityProviderConnection } from '@backstage/plugin-catalog-node'; @@ -23,7 +23,7 @@ export class BitbucketCloudEntityProvider implements EntityProvider { config: Config, options: { auth: AuthService; - catalogApi: CatalogApi; + catalog: CatalogService; events: EventsService; logger: LoggerService; schedule?: SchedulerServiceTaskRunner;