diff --git a/.changeset/heavy-baths-rule.md b/.changeset/heavy-baths-rule.md index 4034035227..09f26e8b57 100644 --- a/.changeset/heavy-baths-rule.md +++ b/.changeset/heavy-baths-rule.md @@ -2,4 +2,4 @@ '@backstage/plugin-catalog-backend-module-github': minor --- -**BREAKING** The `GithubLocationAnalyzer` now requires the `AuthService` when being constructed and the `TokenManger` has been removed. +**BREAKING** The `GithubLocationAnalyzer` now requires the `AuthService` and the `CatalogService` when being constructed and the `TokenManger` has been removed. diff --git a/plugins/catalog-backend-module-github/report.api.md b/plugins/catalog-backend-module-github/report.api.md index f6d69adbd0..691cf271b4 100644 --- a/plugins/catalog-backend-module-github/report.api.md +++ b/plugins/catalog-backend-module-github/report.api.md @@ -6,11 +6,10 @@ import { AnalyzeOptions } from '@backstage/plugin-catalog-node'; import { AuthService } from '@backstage/backend-plugin-api'; import { BackendFeature } from '@backstage/backend-plugin-api'; -import { CatalogApi } from '@backstage/catalog-client'; import { CatalogProcessor } from '@backstage/plugin-catalog-node'; import { CatalogProcessorEmit } from '@backstage/plugin-catalog-node'; +import { CatalogService } 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'; @@ -126,10 +125,9 @@ export class GithubLocationAnalyzer implements ScmLocationAnalyzer { // @public (undocumented) export type GithubLocationAnalyzerOptions = { config: Config; - discovery: DiscoveryService; auth: AuthService; githubCredentialsProvider?: GithubCredentialsProvider; - catalog?: CatalogApi; + catalog: CatalogService; }; // @public 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 25a19ba1ff..c435366931 100644 --- a/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.test.ts +++ b/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.test.ts @@ -39,13 +39,11 @@ import { } from '@backstage/backend-test-utils'; import { setupServer } from 'msw/node'; import { http, HttpResponse } from 'msw'; +import { catalogServiceMock } from '@backstage/plugin-catalog-node/testUtils'; const server = setupServer(); describe('GithubLocationAnalyzer', () => { - const mockDiscovery = mockServices.discovery.mock({ - getBaseUrl: async () => 'http://localhost:7007', - }); const mockAuthService = mockServices.auth.mock({ getPluginRequestToken: async () => ({ token: 'abc123' }), }); @@ -115,7 +113,7 @@ describe('GithubLocationAnalyzer', () => { }); const analyzer = new GithubLocationAnalyzer({ - discovery: mockDiscovery, + catalog: catalogServiceMock(), auth: mockAuthService, config, }); @@ -142,7 +140,7 @@ describe('GithubLocationAnalyzer', () => { }); const analyzer = new GithubLocationAnalyzer({ - discovery: mockDiscovery, + catalog: catalogServiceMock(), auth: mockAuthService, config, }); @@ -168,7 +166,7 @@ describe('GithubLocationAnalyzer', () => { }); const analyzer = new GithubLocationAnalyzer({ - discovery: mockDiscovery, + catalog: catalogServiceMock(), 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 21d8e5b8ea..6719d60cd2 100644 --- a/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.ts +++ b/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { CatalogApi, CatalogClient } from '@backstage/catalog-client'; import { DefaultGithubCredentialsProvider, GithubCredentialsProvider, @@ -26,31 +25,30 @@ import { isEmpty, trimEnd } from 'lodash'; import parseGitUrl from 'git-url-parse'; import { AnalyzeOptions, + CatalogService, ScmLocationAnalyzer, } from '@backstage/plugin-catalog-node'; import { Config } from '@backstage/config'; -import { AuthService, DiscoveryService } from '@backstage/backend-plugin-api'; +import { AuthService } from '@backstage/backend-plugin-api'; import { extname } from 'path'; /** @public */ export type GithubLocationAnalyzerOptions = { config: Config; - discovery: DiscoveryService; auth: AuthService; githubCredentialsProvider?: GithubCredentialsProvider; - catalog?: CatalogApi; + catalog: CatalogService; }; /** @public */ export class GithubLocationAnalyzer implements ScmLocationAnalyzer { - private readonly catalogClient: CatalogApi; + private readonly catalogClient: CatalogService; private readonly githubCredentialsProvider: GithubCredentialsProvider; private readonly integrations: ScmIntegrationRegistry; private readonly auth: AuthService; constructor(options: GithubLocationAnalyzerOptions) { - this.catalogClient = - options.catalog ?? new CatalogClient({ discoveryApi: options.discovery }); + this.catalogClient = options.catalog; this.integrations = ScmIntegrations.fromConfig(options.config); this.githubCredentialsProvider = options.githubCredentialsProvider || @@ -106,10 +104,7 @@ export class GithubLocationAnalyzer implements ScmLocationAnalyzer { }); const defaultBranch = repoInformation.data.default_branch; - const { token: serviceToken } = await this.auth.getPluginRequestToken({ - onBehalfOf: await this.auth.getOwnServiceCredentials(), - targetPluginId: 'catalog', - }); + const credentials = await this.auth.getOwnServiceCredentials(); const result = await Promise.all( searchResult.data.items @@ -121,7 +116,7 @@ export class GithubLocationAnalyzer implements ScmLocationAnalyzer { target, dryRun: true, }, - { token: serviceToken }, + { credentials }, ); return addLocationResult.entities.map(e => ({ location: { type: 'url', target }, diff --git a/plugins/catalog-backend-module-github/src/module/githubCatalogModule.ts b/plugins/catalog-backend-module-github/src/module/githubCatalogModule.ts index bc10b04802..4ae5adbb31 100644 --- a/plugins/catalog-backend-module-github/src/module/githubCatalogModule.ts +++ b/plugins/catalog-backend-module-github/src/module/githubCatalogModule.ts @@ -21,8 +21,8 @@ import { import { catalogAnalysisExtensionPoint, catalogProcessingExtensionPoint, - catalogServiceRef, } from '@backstage/plugin-catalog-node/alpha'; +import { catalogServiceRef } from '@backstage/plugin-catalog-node'; import { eventsServiceRef } from '@backstage/plugin-events-node'; import { GithubEntityProvider } from '../providers/GithubEntityProvider'; import { GithubLocationAnalyzer } from '../analyzers/GithubLocationAnalyzer'; @@ -42,7 +42,6 @@ export const githubCatalogModule = createBackendModule({ auth: coreServices.auth, catalogProcessing: catalogProcessingExtensionPoint, config: coreServices.rootConfig, - discovery: coreServices.discovery, events: eventsServiceRef, logger: coreServices.logger, scheduler: coreServices.scheduler, @@ -55,13 +54,11 @@ export const githubCatalogModule = createBackendModule({ logger, scheduler, catalogAnalyzers, - discovery, auth, catalog, }) { catalogAnalyzers.addScmLocationAnalyzer( new GithubLocationAnalyzer({ - discovery, config, auth, catalog,