From 6b1ed2292d4d01fcb13a99faccc522de1be370bc Mon Sep 17 00:00:00 2001 From: ivgo Date: Thu, 9 Jun 2022 14:50:01 +0200 Subject: [PATCH] Remove rules & update some tsc errors Signed-off-by: ivgo --- .changeset/lazy-zoos-move.md | 3 -- .changeset/perfect-mangos-allow.md | 5 --- docs/integrations/gitlab/discovery.md | 3 -- .../src/lib/types.ts | 2 +- .../GitlabDiscoveryEntityProvider.ts | 2 +- .../src/ingestion/CatalogRules.ts | 45 ------------------- 6 files changed, 2 insertions(+), 58 deletions(-) delete mode 100644 .changeset/perfect-mangos-allow.md diff --git a/.changeset/lazy-zoos-move.md b/.changeset/lazy-zoos-move.md index 4bd78cee1d..69bd517438 100644 --- a/.changeset/lazy-zoos-move.md +++ b/.changeset/lazy-zoos-move.md @@ -43,9 +43,6 @@ catalog: branch: main # Optional. Uses `master` as default group: example-group # Group and subgroup (if needed) to look for repositories entityFilename: catalog-info.yaml # Optional. Defaults to `catalog-info.yaml` - rules: # Optional. Uses the default rules if not present - - repository: example-repo - allow: [Component, System, Location, Template] ``` ```ts diff --git a/.changeset/perfect-mangos-allow.md b/.changeset/perfect-mangos-allow.md deleted file mode 100644 index 0fe75e009c..0000000000 --- a/.changeset/perfect-mangos-allow.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@backstage/plugin-catalog-backend': patch ---- - -Add support to custom rules for `GitlabDiscoveryEntityProvider` diff --git a/docs/integrations/gitlab/discovery.md b/docs/integrations/gitlab/discovery.md index 6383e70e64..ea151e9415 100644 --- a/docs/integrations/gitlab/discovery.md +++ b/docs/integrations/gitlab/discovery.md @@ -24,9 +24,6 @@ catalog: branch: main # Optional. Uses `master` as default group: example-group # Group and subgroup (if needed) to look for repositories entityFilename: catalog-info.yaml # Optional. Defaults to `catalog-info.yaml` - rules: # Optional. Uses the default rules if not present - - repository: example-repo - allow: [Component, System, Location, Template] ``` As this provider is not one of the default providers, you will first need to install diff --git a/plugins/catalog-backend-module-gitlab/src/lib/types.ts b/plugins/catalog-backend-module-gitlab/src/lib/types.ts index fa2350487f..69de9d28c7 100644 --- a/plugins/catalog-backend-module-gitlab/src/lib/types.ts +++ b/plugins/catalog-backend-module-gitlab/src/lib/types.ts @@ -26,7 +26,7 @@ export type GitLabProject = { archived: boolean; last_activity_at: string; web_url: string; - path_with_namespace: string; + path_with_namespace?: string; }; export type GitlabProviderConfig = { diff --git a/plugins/catalog-backend-module-gitlab/src/providers/GitlabDiscoveryEntityProvider.ts b/plugins/catalog-backend-module-gitlab/src/providers/GitlabDiscoveryEntityProvider.ts index 1ecf274c3b..36c3ee90be 100644 --- a/plugins/catalog-backend-module-gitlab/src/providers/GitlabDiscoveryEntityProvider.ts +++ b/plugins/catalog-backend-module-gitlab/src/providers/GitlabDiscoveryEntityProvider.ts @@ -160,7 +160,7 @@ export class GitlabDiscoveryEntityProvider implements EntityProvider { const project_branch = project.default_branch ?? this.config.branch; const projectHasFile: boolean = await client.hasFile( - project.path_with_namespace, + project.path_with_namespace ?? '', project_branch, this.config.catalogFile, ); diff --git a/plugins/catalog-backend/src/ingestion/CatalogRules.ts b/plugins/catalog-backend/src/ingestion/CatalogRules.ts index 72eae22b11..587a0bd7d5 100644 --- a/plugins/catalog-backend/src/ingestion/CatalogRules.ts +++ b/plugins/catalog-backend/src/ingestion/CatalogRules.ts @@ -18,7 +18,6 @@ import { Config } from '@backstage/config'; import { Entity } from '@backstage/catalog-model'; import path from 'path'; import { LocationSpec } from '../api'; -import { ScmIntegrations } from '@backstage/integration'; /** * Rules to apply to catalog entities. @@ -120,18 +119,6 @@ export class DefaultCatalogRulesEnforcer implements CatalogRulesEnforcer { rules.push(...locationRules); } - if (config.has('catalog.providers')) { - const providersConf = config.getConfig('catalog.providers'); - const providerList = providersConf.keys(); - providerList.forEach(provider => { - if (provider === 'gitlab') { - rules.push( - ...getGitlabRules(config, providersConf.getConfig(provider)), - ); - } - }); - } - return new DefaultCatalogRulesEnforcer(rules); } @@ -200,35 +187,3 @@ function resolveTarget(type: string, target: string): string { return path.resolve(target); } - -function getGitlabRules(initialConfig: Config, config: Config): CatalogRule[] { - return config.keys().flatMap(id => { - const gitlabConf = config.getConfig(id); - if (!gitlabConf.has('rules')) { - return []; - } - - const integrations = ScmIntegrations.fromConfig(initialConfig).gitlab; - const gitlabHost = gitlabConf.getString('host'); - const integration = integrations.byHost(gitlabHost); - if (!integration) { - throw new Error( - `No gitlab integration found that matches host ${gitlabHost}`, - ); - } - - const type = `url`; - const branch = gitlabConf.getOptionalString('branch') ?? 'master'; - const entityFilename = - gitlabConf.getOptionalString('entityFilename') ?? 'catalog-info.yaml'; - - return gitlabConf.getConfigArray('rules').map(ruleConf => { - const repoName = ruleConf.getString('repository'); - const target = `${integration.config.baseUrl}/${id}/${repoName}/-/blob/${branch}/${entityFilename}`; - return { - allow: ruleConf.getStringArray('allow').map(kind => ({ kind })), - locations: [{ type, target }], - }; - }); - }); -}