Make integrations take precedence over providers

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-05-11 18:01:27 +02:00
parent 751bd6d3e8
commit 01a9ebf6a5
4 changed files with 28 additions and 21 deletions
+4 -18
View File
@@ -8,21 +8,7 @@ addition to [`catalog.processors.githubOrg.providers`](https://backstage.io/docs
The `integrations` package supports authentication with both personal access
tokens and GitHub apps.
This deprecates the `catalog.processors.githubOrg.providers` configuration. If
you still have a configuration for providers the processor keeps working, but
consider moving to the [`integrations` configuration](https://backstage.io/docs/integrations/github/locations)
as the providers will be removed in the future. You might need to allow
additional scopes for the credentials.
If you want to stay with providers for now, this introduces a small breaking
change, previously if you had no provider configured, one for GitHub was automatically added. To keep the behavior, add a
default provider for GitHub:
```yaml
catalog:
processors:
githubOrg:
providers:
- target: https://github.com
apiBaseUrl: https://api.github.com
```
This deprecates the `catalog.processors.githubOrg.providers` configuration.
A [`integrations` configuration](https://backstage.io/docs/integrations/github/locations)
for the same host takes precedence over the provider configuration.
You might need to add additional scopes for the credentials.
@@ -113,10 +113,10 @@ export class GithubOrgReaderProcessor implements CatalogProcessor {
}
private async createClient(orgUrl: string): Promise<GraphQL> {
let client = this.createClientFromProvider(orgUrl);
let client = await this.createClientFromIntegrations(orgUrl);
if (!client) {
client = await this.createClientFromIntegrations(orgUrl);
client = await this.createClientFromProvider(orgUrl);
}
if (!client) {
@@ -128,7 +128,9 @@ export class GithubOrgReaderProcessor implements CatalogProcessor {
return client;
}
private createClientFromProvider(orgUrl: string): GraphQL | undefined {
private async createClientFromProvider(
orgUrl: string,
): Promise<GraphQL | undefined> {
const provider = this.providers.find(p =>
orgUrl.startsWith(`${p.target}/`),
);
@@ -27,6 +27,16 @@ describe('config', () => {
});
}
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' }]),
@@ -71,5 +71,14 @@ export function readGithubConfig(config: Config): ProviderConfig[] {
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;
}