inject catalog client where possible in the new backend system

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-09-02 17:13:58 +02:00
parent 61e1632dda
commit 5edd344c98
18 changed files with 66 additions and 47 deletions
+4 -1
View File
@@ -22,7 +22,6 @@ import {
coreServices,
createBackendPlugin,
} from '@backstage/backend-plugin-api';
import {
DocsBuildStrategy,
Generators,
@@ -39,6 +38,7 @@ import {
techdocsPublisherExtensionPoint,
} from '@backstage/plugin-techdocs-node';
import { createRouter } from '@backstage/plugin-techdocs-backend';
import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha';
import * as winston from 'winston';
/**
@@ -108,6 +108,7 @@ export const techdocsPlugin = createBackendPlugin({
cache: coreServices.cache,
httpAuth: coreServices.httpAuth,
auth: coreServices.auth,
catalog: catalogServiceRef,
},
async init({
config,
@@ -118,6 +119,7 @@ export const techdocsPlugin = createBackendPlugin({
cache,
httpAuth,
auth,
catalog,
}) {
const winstonLogger = loggerToWinstonLogger(logger);
// Preparers are responsible for fetching source files for documentation.
@@ -161,6 +163,7 @@ export const techdocsPlugin = createBackendPlugin({
discovery,
httpAuth,
auth,
catalogClient: catalog,
}),
);
@@ -15,11 +15,11 @@
*/
import { CacheService } from '@backstage/backend-plugin-api';
import { CachedEntityLoader } from './CachedEntityLoader';
import { CatalogClient } from '@backstage/catalog-client';
import { CatalogApi } from '@backstage/catalog-client';
import { CompoundEntityRef } from '@backstage/catalog-model';
describe('CachedEntityLoader', () => {
const catalog: jest.Mocked<CatalogClient> = {
const catalog: jest.Mocked<CatalogApi> = {
getEntityByRef: jest.fn(),
} as any;
@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CacheService } from '@backstage/backend-plugin-api';
import { CatalogClient } from '@backstage/catalog-client';
import { CatalogApi } from '@backstage/catalog-client';
import {
Entity,
CompoundEntityRef,
@@ -22,12 +23,12 @@ import {
} from '@backstage/catalog-model';
export type CachedEntityLoaderOptions = {
catalog: CatalogClient;
catalog: CatalogApi;
cache: CacheService;
};
export class CachedEntityLoader {
private readonly catalog: CatalogClient;
private readonly catalog: CatalogApi;
private readonly cache: CacheService;
private readonly readTimeout = 1000;
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
createLegacyAuthAdapters,
PluginCacheManager,
} from '@backstage/backend-common';
import { CatalogClient } from '@backstage/catalog-client';
import { CatalogApi, CatalogClient } from '@backstage/catalog-client';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { Config } from '@backstage/config';
import { NotFoundError } from '@backstage/errors';
@@ -48,7 +49,6 @@ import {
* deployment configuration (prepare/generate/publish all in the Backend).
*
* @public
*
*/
export type OutOfTheBoxDeploymentOptions = {
preparers: PreparerBuilder;
@@ -61,7 +61,7 @@ export type OutOfTheBoxDeploymentOptions = {
cache: PluginCacheManager;
docsBuildStrategy?: DocsBuildStrategy;
buildLogTransport?: winston.transport;
catalogClient?: CatalogClient;
catalogClient?: CatalogApi;
httpAuth?: HttpAuthService;
auth?: AuthService;
};
@@ -81,7 +81,7 @@ export type RecommendedDeploymentOptions = {
cache: PluginCacheManager;
docsBuildStrategy?: DocsBuildStrategy;
buildLogTransport?: winston.transport;
catalogClient?: CatalogClient;
catalogClient?: CatalogApi;
httpAuth?: HttpAuthService;
auth?: AuthService;
};
@@ -112,7 +112,7 @@ function isOutOfTheBoxOption(
* Creates a techdocs router.
*
* @public
*@deprecated This function is only exported for legacy reasons and will be removed in the future.
* @deprecated This function is only exported for legacy reasons and will be removed in the future.
* Please {@link https://backstage.io/docs/backend-system/building-backends/migrating | migrate } to use the new backend system and follow these {@link https://backstage.io/docs/features/techdocs/getting-started#new-backend-system | instructions } to install the user settings backend plugin.
*/
export async function createRouter(