remove some usages of the old alpha catalog service

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2025-06-05 11:37:23 +02:00
parent a58e48e983
commit eb1ee0331e
11 changed files with 107 additions and 124 deletions
@@ -40,7 +40,6 @@
},
"dependencies": {
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/catalog-client": "workspace:^",
"@backstage/catalog-model": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/errors": "workspace:^",
+1 -1
View File
@@ -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
@@ -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']);
});
@@ -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<string[]> => {
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<Entity | undefined> = [];
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);
}
@@ -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);