fix: use a different id for the legacy catalog client ref

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2025-04-02 13:56:17 +02:00
parent 7885e01b62
commit 98b7131e54
5 changed files with 19 additions and 16 deletions
@@ -3,7 +3,7 @@ import {
createBackendPlugin,
} from '@backstage/backend-plugin-api';
import { createRouter } from './router';
import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha';
import { catalogServiceRef } from '@backstage/plugin-catalog-node';
import { createTodoListService } from './services/TodoListService';
/**
@@ -17,15 +17,13 @@ export const {{pluginVar}} = createBackendPlugin({
env.registerInit({
deps: {
logger: coreServices.logger,
auth: coreServices.auth,
httpAuth: coreServices.httpAuth,
httpRouter: coreServices.httpRouter,
catalog: catalogServiceRef,
},
async init({ logger, auth, httpAuth, httpRouter, catalog }) {
async init({ logger, httpAuth, httpRouter, catalog }) {
const todoListService = await createTodoListService({
logger,
auth,
catalog,
});
@@ -1,6 +1,6 @@
import { AuthService, LoggerService } from '@backstage/backend-plugin-api';
import { LoggerService } from '@backstage/backend-plugin-api';
import { NotFoundError } from '@backstage/errors';
import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha';
import { catalogServiceRef } from '@backstage/plugin-catalog-node';
import crypto from 'node:crypto';
import { TodoItem, TodoListService } from './types';
@@ -10,11 +10,9 @@ import { TodoItem, TodoListService } from './types';
// documentation for more information on how to do this:
// https://backstage.io/docs/backend-system/core-services/database
export async function createTodoListService({
auth,
logger,
catalog,
}: {
auth: AuthService;
logger: LoggerService;
catalog: typeof catalogServiceRef.T;
}): Promise<TodoListService> {
@@ -40,13 +38,7 @@ export async function createTodoListService({
// If you want to make a request using the plugin backend's own identity,
// you can access it via the `auth.getOwnServiceCredentials()` method.
// Beware that this bypasses any user permission checks.
const { token } = await auth.getPluginRequestToken({
onBehalfOf: options.credentials,
targetPluginId: 'catalog',
});
const entity = await catalog.getEntityByRef(input.entityRef, {
token,
});
const entity = await catalog.getEntityByRef(input.entityRef, options);
if (!entity) {
throw new NotFoundError(
`No entity found for ref '${input.entityRef}'`,