From 420f8d710f88352507d82c2b966bf8b32947a22a Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Wed, 23 Feb 2022 14:49:43 +0100 Subject: [PATCH] catalog-backend: Remove `processors.githubOrg` config section Signed-off-by: Johan Haals --- .changeset/metal-onions-explode.md | 5 ++ app-config.yaml | 8 --- plugins/catalog-backend/config.d.ts | 33 --------- .../processors/github/config.test.ts | 61 +---------------- .../src/ingestion/processors/github/config.ts | 68 ------------------- .../src/ingestion/processors/github/index.ts | 4 +- plugins/config-schema/dev/example-schema.json | 30 -------- 7 files changed, 8 insertions(+), 201 deletions(-) create mode 100644 .changeset/metal-onions-explode.md diff --git a/.changeset/metal-onions-explode.md b/.changeset/metal-onions-explode.md new file mode 100644 index 0000000000..447b21f7bb --- /dev/null +++ b/.changeset/metal-onions-explode.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +Removed the `processors.githubOrg` config section which is unused and has been replaced by the integrations config. diff --git a/app-config.yaml b/app-config.yaml index b025064c74..ab68d4398f 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -211,14 +211,6 @@ catalog: - Location processors: - githubOrg: - providers: - - target: https://github.com - token: ${GITHUB_TOKEN} - #### Example for how to add your GitHub Enterprise instance using the API: - # - target: https://ghe.example.net - # apiBaseUrl: https://ghe.example.net/api - # token: ${GHE_TOKEN} ldapOrg: ### Example for how to add your enterprise LDAP server # providers: diff --git a/plugins/catalog-backend/config.d.ts b/plugins/catalog-backend/config.d.ts index 8964e1ab0e..957f18c15f 100644 --- a/plugins/catalog-backend/config.d.ts +++ b/plugins/catalog-backend/config.d.ts @@ -110,39 +110,6 @@ export interface Config { * List of processor-specific options and attributes */ processors?: { - /** - * GithubOrgReaderProcessor configuration - * - * @deprecated Configure a GitHub integration instead. - */ - githubOrg?: { - /** - * The configuration parameters for each single GitHub org provider. - */ - providers: Array<{ - /** - * The prefix of the target that this matches on, e.g. - * "https://github.com", with no trailing slash. - */ - target: string; - /** - * The base URL of the API of this provider, e.g. - * "https://api.github.com", with no trailing slash. - * - * May be omitted specifically for GitHub; then it will be deduced. - */ - apiBaseUrl?: string; - /** - * The authorization token to use for requests to this provider. - * - * If no token is specified, anonymous access is used. - * - * @visibility secret - */ - token?: string; - }>; - }; - /** * GithubMultiOrgReaderProcessor configuration */ diff --git a/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts b/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts index a67d2378d0..3b722a0e7b 100644 --- a/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts @@ -15,68 +15,9 @@ */ import { ConfigReader } from '@backstage/config'; -import { readGithubConfig, readGithubMultiOrgConfig } from './config'; +import { readGithubMultiOrgConfig } from './config'; describe('config', () => { - describe('readGithubConfig', () => { - function config( - providers: { target: string; apiBaseUrl?: string; token?: string }[], - ) { - return new ConfigReader({ - catalog: { processors: { githubOrg: { providers } } }, - }); - } - - it('adds a default GitHub entry when missing', () => { - const output = readGithubConfig(config([])); - expect(output).toEqual([ - { - target: 'https://github.com', - apiBaseUrl: 'https://api.github.com', - }, - ]); - }); - - it('injects the correct GitHub API base URL when missing', () => { - const output = readGithubConfig( - config([{ target: 'https://github.com' }]), - ); - expect(output).toEqual([ - { - target: 'https://github.com', - apiBaseUrl: 'https://api.github.com', - }, - ]); - }); - - it('rejects custom targets with no base URLs', () => { - expect(() => - readGithubConfig(config([{ target: 'https://ghe.company.com' }])), - ).toThrow( - 'Provider at https://ghe.company.com must configure an explicit apiBaseUrl', - ); - }); - - it('rejects funky configs', () => { - expect(() => readGithubConfig(config([{ target: 7 } as any]))).toThrow( - /target/, - ); - expect(() => - readGithubConfig(config([{ noTarget: '7' } as any])), - ).toThrow(/target/); - expect(() => - readGithubConfig( - config([{ target: 'https://github.com', apiBaseUrl: 7 } as any]), - ), - ).toThrow(/apiBaseUrl/); - expect(() => - readGithubConfig( - config([{ target: 'https://github.com', token: 7 } as any]), - ), - ).toThrow(/token/); - }); - }); - describe('readGithubMultiOrgConfig', () => { function config( orgs: { name: string; groupNamespace?: string; userNamespace?: string }[], diff --git a/plugins/catalog-backend/src/ingestion/processors/github/config.ts b/plugins/catalog-backend/src/ingestion/processors/github/config.ts index cd17d30311..242296b4be 100644 --- a/plugins/catalog-backend/src/ingestion/processors/github/config.ts +++ b/plugins/catalog-backend/src/ingestion/processors/github/config.ts @@ -15,74 +15,6 @@ */ import { Config } from '@backstage/config'; -import { trimEnd } from 'lodash'; - -/** - * The configuration parameters for a single GitHub API provider. - */ -export type ProviderConfig = { - /** - * The prefix of the target that this matches on, e.g. "https://github.com", - * with no trailing slash. - */ - target: string; - - /** - * The base URL of the API of this provider, e.g. "https://api.github.com", - * with no trailing slash. - * - * May be omitted specifically for GitHub; then it will be deduced. - */ - apiBaseUrl?: string; - - /** - * The authorization token to use for requests to this provider. - * - * If no token is specified, anonymous access is used. - */ - token?: string; -}; - -// TODO(freben): Break out common code and config from here and GithubReaderProcessor -export function readGithubConfig(config: Config): ProviderConfig[] { - const providers: ProviderConfig[] = []; - - const providerConfigs = - config.getOptionalConfigArray('catalog.processors.githubOrg.providers') ?? - []; - - // First read all the explicit providers - for (const providerConfig of providerConfigs) { - const target = trimEnd(providerConfig.getString('target'), '/'); - let apiBaseUrl = providerConfig.getOptionalString('apiBaseUrl'); - const token = providerConfig.getOptionalString('token'); - - if (apiBaseUrl) { - apiBaseUrl = trimEnd(apiBaseUrl, '/'); - } else if (target === 'https://github.com') { - apiBaseUrl = 'https://api.github.com'; - } - - if (!apiBaseUrl) { - throw new Error( - `Provider at ${target} must configure an explicit apiBaseUrl`, - ); - } - - providers.push({ target, apiBaseUrl, token }); - } - - // If no explicit github.com provider was added, put one in the list as - // a convenience - if (!providers.some(p => p.target === 'https://github.com')) { - providers.push({ - target: 'https://github.com', - apiBaseUrl: 'https://api.github.com', - }); - } - - return providers; -} /** * The configuration parameters for a multi-org GitHub processor. diff --git a/plugins/catalog-backend/src/ingestion/processors/github/index.ts b/plugins/catalog-backend/src/ingestion/processors/github/index.ts index 3d9e881ddd..3e31d9e00c 100644 --- a/plugins/catalog-backend/src/ingestion/processors/github/index.ts +++ b/plugins/catalog-backend/src/ingestion/processors/github/index.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -export { readGithubConfig, readGithubMultiOrgConfig } from './config'; -export type { GithubMultiOrgConfig, ProviderConfig } from './config'; +export { readGithubMultiOrgConfig } from './config'; +export type { GithubMultiOrgConfig } from './config'; export { getOrganizationRepositories, getOrganizationTeams, diff --git a/plugins/config-schema/dev/example-schema.json b/plugins/config-schema/dev/example-schema.json index ac5c2ad347..be297aaa8d 100644 --- a/plugins/config-schema/dev/example-schema.json +++ b/plugins/config-schema/dev/example-schema.json @@ -746,36 +746,6 @@ "description": "List of processor-specific options and attributes", "type": "object", "properties": { - "githubOrg": { - "description": "GithubOrgReaderProcessor configuration", - "type": "object", - "required": ["providers"], - "properties": { - "providers": { - "description": "The configuration parameters for each single GitHub org provider.", - "type": "array", - "items": { - "type": "object", - "required": ["target"], - "properties": { - "target": { - "description": "The prefix of the target that this matches on, e.g.\n\"https://github.com\", with no trailing slash.", - "type": "string" - }, - "apiBaseUrl": { - "description": "The base URL of the API of this provider, e.g.\n\"https://api.github.com\", with no trailing slash.\n\nMay be omitted specifically for GitHub; then it will be deduced.", - "type": "string" - }, - "token": { - "description": "The authorization token to use for requests to this provider.\n\nIf no token is specified, anonymous access is used.", - "visibility": "secret", - "type": "string" - } - } - } - } - } - }, "ldapOrg": { "description": "LdapOrgReaderProcessor configuration", "type": "object",