From a6e2851902d061448115232ff2b41dd0a7ac659b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 10 Mar 2022 11:25:58 +0100 Subject: [PATCH] add check for externalized processors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../src/service/CatalogBuilder.ts | 86 +++++++++++++++++++ scripts/api-extractor.ts | 2 + 2 files changed, 88 insertions(+) diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index 317eef1cea..79edf3b221 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -549,6 +549,8 @@ export class CatalogBuilder { // Add the ones (if any) that the user added processors.push(...this.processors); + this.checkMissingExternalProcessors(processors); + return processors; } @@ -577,4 +579,88 @@ export class CatalogBuilder { ); } } + + // TODO(freben): This can be removed no sooner than June 2022, after adopters have had some time to adapt to the new package structure + private checkMissingExternalProcessors(processors: CatalogProcessor[]) { + const skipCheckVarName = 'BACKSTAGE_CATALOG_SKIP_MISSING_PROCESSORS_CHECK'; + if (process.env[skipCheckVarName]) { + return; + } + + const locationTypes = new Set( + this.env.config + .getOptionalConfigArray('catalog.locations') + ?.map(l => l.getString('type')) ?? [], + ); + const processorNames = new Set(processors.map(p => p.getProcessorName())); + + function check( + locationType: string, + processorName: string, + installationUrl: string, + ) { + if ( + locationTypes.has(locationType) && + !processorNames.has(processorName) + ) { + throw new Error( + [ + `Your config contains a "catalog.locations" entry of type ${locationType},`, + `but does not have the corresponding catalog processor ${processorName} installed.`, + `This processor used to be built into the catalog itself, but is now moved to an`, + `external module that has to be installed manually. Please follow the installation`, + `instructions at ${installationUrl} if you are using this ability, or remove the`, + `location from your app config if you do not. You can also silence this check entirely`, + `by setting the environment variable ${skipCheckVarName} to 'true'.`, + ].join(' '), + ); + } + } + + check( + 'aws-cloud-accounts', + 'AwsOrganizationCloudAccountProcessor', + 'https://backstage.io/docs/integrations', + ); + check( + 's3-discovery', + 'AwsS3DiscoveryProcessor', + 'https://backstage.io/docs/integrations/aws-s3/discovery', + ); + check( + 'azure-discovery', + 'AzureDevOpsDiscoveryProcessor', + 'https://backstage.io/docs/integrations/azure/discovery', + ); + check( + 'bitbucket-discovery', + 'BitbucketDiscoveryProcessor', + 'https://backstage.io/docs/integrations/bitbucket/discovery', + ); + check( + 'github-discovery', + 'GithubDiscoveryProcessor', + 'https://backstage.io/docs/integrations/github/discovery', + ); + check( + 'github-org', + 'GithubOrgReaderProcessor', + 'https://backstage.io/docs/integrations/github/org', + ); + check( + 'gitlab-discovery', + 'GitLabDiscoveryProcessor', + 'https://backstage.io/docs/integrations/gitlab/discovery', + ); + check( + 'ldap-org', + 'LdapOrgReaderProcessor', + 'https://backstage.io/docs/integrations/ldap/org', + ); + check( + 'microsoft-graph-org', + 'MicrosoftGraphOrgReaderProcessor', + 'https://backstage.io/docs/integrations/azure/org', + ); + } } diff --git a/scripts/api-extractor.ts b/scripts/api-extractor.ts index a39cf700f5..2e85cc4cff 100644 --- a/scripts/api-extractor.ts +++ b/scripts/api-extractor.ts @@ -224,6 +224,8 @@ const NO_WARNING_PACKAGES = [ 'plugins/catalog-backend', 'plugins/catalog-backend-module-aws', 'plugins/catalog-backend-module-azure', + 'plugins/catalog-backend-module-bitbucket', + 'plugins/catalog-backend-module-github', 'plugins/catalog-backend-module-gitlab', 'plugins/catalog-backend-module-ldap', 'plugins/catalog-backend-module-msgraph',