Merge pull request #8533 from RoadieHQ/gh-creds-interface
create an interface for gh creds provider
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
import { LocationSpec } from '@backstage/catalog-model';
|
||||
import { Config } from '@backstage/config';
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
SingleInstanceGithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { graphql } from '@octokit/graphql';
|
||||
@@ -84,7 +84,7 @@ export class GithubDiscoveryProcessor implements CatalogProcessor {
|
||||
// about how to handle the wild card which is special for this processor.
|
||||
const orgUrl = `https://${host}/${org}`;
|
||||
|
||||
const { headers } = await GithubCredentialsProvider.create(
|
||||
const { headers } = await SingleInstanceGithubCredentialsProvider.create(
|
||||
gitHubConfig,
|
||||
).getCredentials({ url: orgUrl });
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import { LocationSpec } from '@backstage/catalog-model';
|
||||
import { Config } from '@backstage/config';
|
||||
import {
|
||||
GithubAppCredentialsMux,
|
||||
GithubCredentialsProvider,
|
||||
SingleInstanceGithubCredentialsProvider,
|
||||
GitHubIntegrationConfig,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
@@ -86,7 +86,8 @@ export class GithubMultiOrgReaderProcessor implements CatalogProcessor {
|
||||
|
||||
const allUsersMap = new Map();
|
||||
const baseUrl = new URL(location.target).origin;
|
||||
const credentialsProvider = GithubCredentialsProvider.create(gitHubConfig);
|
||||
const credentialsProvider =
|
||||
SingleInstanceGithubCredentialsProvider.create(gitHubConfig);
|
||||
|
||||
const orgsToProcess = this.orgs.length
|
||||
? this.orgs
|
||||
|
||||
@@ -17,7 +17,7 @@ import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { LocationSpec } from '@backstage/catalog-model';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
SingleInstanceGithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { graphql } from '@octokit/graphql';
|
||||
@@ -87,9 +87,11 @@ describe('GithubOrgReaderProcessor', () => {
|
||||
|
||||
(graphql.defaults as jest.Mock).mockReturnValue(mockClient);
|
||||
|
||||
jest.spyOn(GithubCredentialsProvider, 'create').mockReturnValue({
|
||||
getCredentials: mockGetCredentials,
|
||||
} as any);
|
||||
jest
|
||||
.spyOn(SingleInstanceGithubCredentialsProvider, 'create')
|
||||
.mockReturnValue({
|
||||
getCredentials: mockGetCredentials,
|
||||
} as any);
|
||||
|
||||
const processor = new GithubOrgReaderProcessor({
|
||||
integrations,
|
||||
@@ -135,9 +137,11 @@ describe('GithubOrgReaderProcessor', () => {
|
||||
|
||||
(graphql.defaults as jest.Mock).mockReturnValue(mockClient);
|
||||
|
||||
jest.spyOn(GithubCredentialsProvider, 'create').mockReturnValue({
|
||||
getCredentials: mockGetCredentials,
|
||||
} as any);
|
||||
jest
|
||||
.spyOn(SingleInstanceGithubCredentialsProvider, 'create')
|
||||
.mockReturnValue({
|
||||
getCredentials: mockGetCredentials,
|
||||
} as any);
|
||||
|
||||
const processor = new GithubOrgReaderProcessor({
|
||||
integrations,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import { LocationSpec } from '@backstage/catalog-model';
|
||||
import { Config } from '@backstage/config';
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
SingleInstanceGithubCredentialsProvider,
|
||||
GithubCredentialType,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
@@ -107,7 +107,8 @@ export class GithubOrgReaderProcessor implements CatalogProcessor {
|
||||
);
|
||||
}
|
||||
|
||||
const credentialsProvider = GithubCredentialsProvider.create(gitHubConfig);
|
||||
const credentialsProvider =
|
||||
SingleInstanceGithubCredentialsProvider.create(gitHubConfig);
|
||||
const { headers, type: tokenType } =
|
||||
await credentialsProvider.getCredentials({
|
||||
url: orgUrl,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { GroupEntity, UserEntity } from '@backstage/catalog-model';
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
SingleInstanceGithubCredentialsProvider,
|
||||
GitHubIntegrationConfig,
|
||||
} from '@backstage/integration';
|
||||
import { GitHubOrgEntityProvider } from '.';
|
||||
@@ -93,9 +93,11 @@ describe('GitHubOrgEntityProvider', () => {
|
||||
type: 'app',
|
||||
});
|
||||
|
||||
jest.spyOn(GithubCredentialsProvider, 'create').mockReturnValue({
|
||||
getCredentials: mockGetCredentials,
|
||||
} as any);
|
||||
jest
|
||||
.spyOn(SingleInstanceGithubCredentialsProvider, 'create')
|
||||
.mockReturnValue({
|
||||
getCredentials: mockGetCredentials,
|
||||
} as any);
|
||||
|
||||
const entityProvider = new GitHubOrgEntityProvider({
|
||||
id: 'my-id',
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
} from '@backstage/catalog-model';
|
||||
import { Config } from '@backstage/config';
|
||||
import {
|
||||
SingleInstanceGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
GitHubIntegrationConfig,
|
||||
ScmIntegrations,
|
||||
@@ -77,7 +78,7 @@ export class GitHubOrgEntityProvider implements EntityProvider {
|
||||
logger: Logger;
|
||||
},
|
||||
) {
|
||||
this.credentialsProvider = GithubCredentialsProvider.create(
|
||||
this.credentialsProvider = SingleInstanceGithubCredentialsProvider.create(
|
||||
options.gitHubConfig,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
import { InputError } from '@backstage/errors';
|
||||
import {
|
||||
SingleInstanceGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrationRegistry,
|
||||
} from '@backstage/integration';
|
||||
@@ -40,7 +41,9 @@ export class OctokitProvider {
|
||||
this.integrations = integrations;
|
||||
this.credentialsProviders = new Map(
|
||||
integrations.github.list().map(integration => {
|
||||
const provider = GithubCredentialsProvider.create(integration.config);
|
||||
const provider = SingleInstanceGithubCredentialsProvider.create(
|
||||
integration.config,
|
||||
);
|
||||
return [integration.config.host, provider];
|
||||
}),
|
||||
);
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ import fs from 'fs-extra';
|
||||
import { parseRepoUrl, isExecutable } from './util';
|
||||
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
SingleInstanceGithubCredentialsProvider,
|
||||
ScmIntegrationRegistry,
|
||||
} from '@backstage/integration';
|
||||
import { zipObject } from 'lodash';
|
||||
@@ -76,7 +76,7 @@ export const defaultClientFactory = async ({
|
||||
}
|
||||
|
||||
const credentialsProvider =
|
||||
GithubCredentialsProvider.create(integrationConfig);
|
||||
SingleInstanceGithubCredentialsProvider.create(integrationConfig);
|
||||
|
||||
if (!credentialsProvider) {
|
||||
throw new InputError(
|
||||
|
||||
Reference in New Issue
Block a user