From 808153c0f78828ead4a09622f89b15407510155e Mon Sep 17 00:00:00 2001 From: ebarrios Date: Fri, 12 Feb 2021 16:18:30 +0100 Subject: [PATCH 01/12] Added GithubApp authentication to the scaffolder plugin --- packages/integration/src/github/config.ts | 7 ++++ .../src/scaffolder/stages/publish/github.ts | 38 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/packages/integration/src/github/config.ts b/packages/integration/src/github/config.ts index 94ed00731e..4b80a9aa60 100644 --- a/packages/integration/src/github/config.ts +++ b/packages/integration/src/github/config.ts @@ -59,6 +59,13 @@ export type GitHubIntegrationConfig = { */ token?: string; + /** + * The accessType (oAuth|githubApp) to use for requests to this provider. + * + * If no user is specified, oAuth access is used. + */ + accessType?: string; + /** * The GitHub Apps configuration to use for requests to this provider. * diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 13aab7ff34..667764dc1e 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -17,6 +17,7 @@ import { PublisherBase, PublisherOptions, PublisherResult } from './types'; import { initRepoAndPush } from './helpers'; import { GitHubIntegrationConfig } from '@backstage/integration'; +import { createAppAuth } from '@octokit/auth-app'; import parseGitUrl from 'git-url-parse'; import { Octokit } from '@octokit/rest'; import path from 'path'; @@ -28,8 +29,23 @@ export class GithubPublisher implements PublisherBase { config: GitHubIntegrationConfig, { repoVisibility }: { repoVisibility: RepoVisibilityOptions }, ) { + config.accessType = 'oAuth'; + if (!config.token) { - return undefined; + if (!config.apps) { + return undefined + } + const auth = createAppAuth({ + appId: config.apps[0].appId, + privateKey: config.apps[0].privateKey, + installationId: process.env.GITHUB_INSTALLATION_ID, + clientId: config.apps[0].clientId, + clientSecret: config.apps[0].clientSecret, + }); + const appAuthentication = await auth({ type: 'installation' }); + + config.token = appAuthentication.token; + config.accessType = 'githubApp' } const githubClient = new Octokit({ @@ -39,6 +55,7 @@ export class GithubPublisher implements PublisherBase { return new GithubPublisher({ token: config.token, + accessType: config.accessType, client: githubClient, repoVisibility, }); @@ -47,6 +64,7 @@ export class GithubPublisher implements PublisherBase { constructor( private readonly config: { token: string; + accessType: string; client: Octokit; repoVisibility: RepoVisibilityOptions; }, @@ -68,15 +86,27 @@ export class GithubPublisher implements PublisherBase { owner, }); - await initRepoAndPush({ + if (this.config.accessType === 'githubApp') { + await initRepoAndPush({ dir: path.join(workspacePath, 'result'), remoteUrl, auth: { - username: this.config.token, - password: 'x-oauth-basic', + username: 'x-access-token', + password: this.config.token, }, logger, }); + } else if (this.config.accessType === 'oAuth'){ + await initRepoAndPush({ + dir: path.join(workspacePath, 'result'), + remoteUrl, + auth: { + username: this.config.token, + password: 'x-oauth-basic', + }, + logger, + }); + } const catalogInfoUrl = remoteUrl.replace( /\.git$/, From 7a4d468d974e023e19588bdccb7317a92c842a44 Mon Sep 17 00:00:00 2001 From: ebarrios Date: Mon, 15 Feb 2021 11:53:38 +0100 Subject: [PATCH 02/12] Used GithubCredentialsProvider as requested by benjdlambert in the pr comments --- .../src/scaffolder/stages/publish/github.ts | 69 ++++++++++--------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 667764dc1e..4dd872ad8f 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -16,8 +16,10 @@ import { PublisherBase, PublisherOptions, PublisherResult } from './types'; import { initRepoAndPush } from './helpers'; -import { GitHubIntegrationConfig } from '@backstage/integration'; -import { createAppAuth } from '@octokit/auth-app'; +import { + GitHubIntegrationConfig, + GithubCredentialsProvider, +} from '@backstage/integration'; import parseGitUrl from 'git-url-parse'; import { Octokit } from '@octokit/rest'; import path from 'path'; @@ -31,21 +33,13 @@ export class GithubPublisher implements PublisherBase { ) { config.accessType = 'oAuth'; + const credentialsProvider = GithubCredentialsProvider.create(config); + if (!config.token) { if (!config.apps) { - return undefined + return undefined; } - const auth = createAppAuth({ - appId: config.apps[0].appId, - privateKey: config.apps[0].privateKey, - installationId: process.env.GITHUB_INSTALLATION_ID, - clientId: config.apps[0].clientId, - clientSecret: config.apps[0].clientSecret, - }); - const appAuthentication = await auth({ type: 'installation' }); - - config.token = appAuthentication.token; - config.accessType = 'githubApp' + config.accessType = 'githubApp'; } const githubClient = new Octokit({ @@ -54,10 +48,12 @@ export class GithubPublisher implements PublisherBase { }); return new GithubPublisher({ - token: config.token, + token: config.token || '', accessType: config.accessType, + credentialsProvider, client: githubClient, repoVisibility, + apiBaseUrl: config.apiBaseUrl, }); } @@ -65,8 +61,10 @@ export class GithubPublisher implements PublisherBase { private readonly config: { token: string; accessType: string; + credentialsProvider: GithubCredentialsProvider; client: Octokit; repoVisibility: RepoVisibilityOptions; + apiBaseUrl: string | undefined; }, ) {} @@ -77,6 +75,28 @@ export class GithubPublisher implements PublisherBase { }: PublisherOptions): Promise { const { owner, name } = parseGitUrl(values.storePath); + let auth = { + username: this.config.token, + password: 'x-oauth-basic', + }; + + if (this.config.accessType === 'githubApp') { + this.config.token = + ( + await this.config.credentialsProvider.getCredentials({ + url: values.storePath, + }) + ).token || ''; + this.config.client = new Octokit({ + auth: this.config.token, + baseUrl: this.config.apiBaseUrl, + }); + auth = { + username: 'x-access-token', + password: this.config.token, + }; + } + const description = values.description as string; const access = values.access as string; const remoteUrl = await this.createRemote({ @@ -86,27 +106,12 @@ export class GithubPublisher implements PublisherBase { owner, }); - if (this.config.accessType === 'githubApp') { - await initRepoAndPush({ + await initRepoAndPush({ dir: path.join(workspacePath, 'result'), remoteUrl, - auth: { - username: 'x-access-token', - password: this.config.token, - }, + auth, logger, }); - } else if (this.config.accessType === 'oAuth'){ - await initRepoAndPush({ - dir: path.join(workspacePath, 'result'), - remoteUrl, - auth: { - username: this.config.token, - password: 'x-oauth-basic', - }, - logger, - }); - } const catalogInfoUrl = remoteUrl.replace( /\.git$/, From 18ed99c0e5f6d376f780d8098ead15ec98837242 Mon Sep 17 00:00:00 2001 From: ebarrios Date: Mon, 15 Feb 2021 14:45:40 +0100 Subject: [PATCH 03/12] Used credentialsProvider as to determine which kind of authentication is going to be used instead of adding an accessType top the GitHubIntegrationConfig --- packages/integration/package.json | 1 + packages/integration/src/github/config.ts | 7 ++++--- .../src/scaffolder/stages/publish/github.ts | 12 ++++-------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/integration/package.json b/packages/integration/package.json index b4134ab00e..254b4d3fe5 100644 --- a/packages/integration/package.json +++ b/packages/integration/package.json @@ -30,6 +30,7 @@ }, "dependencies": { "@backstage/config": "^0.1.2", + "@backstage/integration": "^0.4.0", "cross-fetch": "^3.0.6", "git-url-parse": "^11.4.4", "@octokit/rest": "^18.0.12", diff --git a/packages/integration/src/github/config.ts b/packages/integration/src/github/config.ts index 4b80a9aa60..2a998ef18b 100644 --- a/packages/integration/src/github/config.ts +++ b/packages/integration/src/github/config.ts @@ -16,6 +16,7 @@ import { Config } from '@backstage/config'; import { isValidHost } from '../helpers'; +import { GithubCredentialsProvider } from '@backstage/integration'; const GITHUB_HOST = 'github.com'; const GITHUB_API_BASE_URL = 'https://api.github.com'; @@ -60,11 +61,11 @@ export type GitHubIntegrationConfig = { token?: string; /** - * The accessType (oAuth|githubApp) to use for requests to this provider. + * The credentialsProvider to use for requests to this provider. * - * If no user is specified, oAuth access is used. + * If no credentialsProvider is created, undefined is used. */ - accessType?: string; + credentialsProvider?: GithubCredentialsProvider | undefined; /** * The GitHub Apps configuration to use for requests to this provider. diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 4dd872ad8f..4d038ed5b9 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -31,15 +31,13 @@ export class GithubPublisher implements PublisherBase { config: GitHubIntegrationConfig, { repoVisibility }: { repoVisibility: RepoVisibilityOptions }, ) { - config.accessType = 'oAuth'; - - const credentialsProvider = GithubCredentialsProvider.create(config); + let credentialsProvider: GithubCredentialsProvider | undefined = undefined; if (!config.token) { if (!config.apps) { return undefined; } - config.accessType = 'githubApp'; + credentialsProvider = GithubCredentialsProvider.create(config); } const githubClient = new Octokit({ @@ -49,7 +47,6 @@ export class GithubPublisher implements PublisherBase { return new GithubPublisher({ token: config.token || '', - accessType: config.accessType, credentialsProvider, client: githubClient, repoVisibility, @@ -60,8 +57,7 @@ export class GithubPublisher implements PublisherBase { constructor( private readonly config: { token: string; - accessType: string; - credentialsProvider: GithubCredentialsProvider; + credentialsProvider: GithubCredentialsProvider | undefined; client: Octokit; repoVisibility: RepoVisibilityOptions; apiBaseUrl: string | undefined; @@ -80,7 +76,7 @@ export class GithubPublisher implements PublisherBase { password: 'x-oauth-basic', }; - if (this.config.accessType === 'githubApp') { + if (this.config.credentialsProvider) { this.config.token = ( await this.config.credentialsProvider.getCredentials({ From 09e8baf31b617c20ee1d85ff5e1887762fa96334 Mon Sep 17 00:00:00 2001 From: ebarrios Date: Mon, 15 Feb 2021 14:57:58 +0100 Subject: [PATCH 04/12] Removed the githubCredentials from the github config because it is not needed there --- packages/integration/src/github/config.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/integration/src/github/config.ts b/packages/integration/src/github/config.ts index 2a998ef18b..94ed00731e 100644 --- a/packages/integration/src/github/config.ts +++ b/packages/integration/src/github/config.ts @@ -16,7 +16,6 @@ import { Config } from '@backstage/config'; import { isValidHost } from '../helpers'; -import { GithubCredentialsProvider } from '@backstage/integration'; const GITHUB_HOST = 'github.com'; const GITHUB_API_BASE_URL = 'https://api.github.com'; @@ -60,13 +59,6 @@ export type GitHubIntegrationConfig = { */ token?: string; - /** - * The credentialsProvider to use for requests to this provider. - * - * If no credentialsProvider is created, undefined is used. - */ - credentialsProvider?: GithubCredentialsProvider | undefined; - /** * The GitHub Apps configuration to use for requests to this provider. * From c7e8e7cf058a5b0bed942c6b0eaddaab48aed08c Mon Sep 17 00:00:00 2001 From: Esteban Barrios Date: Mon, 15 Feb 2021 23:28:00 +0100 Subject: [PATCH 05/12] Removed unused import Removed unused import --- packages/integration/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/integration/package.json b/packages/integration/package.json index 254b4d3fe5..b4134ab00e 100644 --- a/packages/integration/package.json +++ b/packages/integration/package.json @@ -30,7 +30,6 @@ }, "dependencies": { "@backstage/config": "^0.1.2", - "@backstage/integration": "^0.4.0", "cross-fetch": "^3.0.6", "git-url-parse": "^11.4.4", "@octokit/rest": "^18.0.12", From 3a15d2941ebae2a23a8bead606a55971efc21990 Mon Sep 17 00:00:00 2001 From: ebarrios Date: Tue, 16 Feb 2021 10:18:14 +0100 Subject: [PATCH 06/12] Addresed all coments from Rugvip to remove all mutable objects from the fromConfig function --- .../src/scaffolder/stages/publish/github.ts | 55 ++++++++----------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 98d16e6bb7..1846cb90d1 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -31,24 +31,16 @@ export class GithubPublisher implements PublisherBase { config: GitHubIntegrationConfig, { repoVisibility }: { repoVisibility: RepoVisibilityOptions }, ) { - let credentialsProvider: GithubCredentialsProvider | undefined = undefined; - if (!config.token) { if (!config.apps) { return undefined; } - credentialsProvider = GithubCredentialsProvider.create(config); } - const githubClient = new Octokit({ - auth: config.token, - baseUrl: config.apiBaseUrl, - }); + const credentialsProvider = GithubCredentialsProvider.create(config); return new GithubPublisher({ - token: config.token || '', credentialsProvider, - client: githubClient, repoVisibility, apiBaseUrl: config.apiBaseUrl, }); @@ -56,9 +48,7 @@ export class GithubPublisher implements PublisherBase { constructor( private readonly config: { - token: string; - credentialsProvider: GithubCredentialsProvider | undefined; - client: Octokit; + credentialsProvider: GithubCredentialsProvider; repoVisibility: RepoVisibilityOptions; apiBaseUrl: string | undefined; }, @@ -70,23 +60,23 @@ export class GithubPublisher implements PublisherBase { logger, }: PublisherOptions): Promise { const { owner, name } = parseGitUrl(values.storePath); - - if (this.config.credentialsProvider) { - this.config.token = - ( - await this.config.credentialsProvider.getCredentials({ - url: values.storePath, - }) - ).token || ''; - this.config.client = new Octokit({ - auth: this.config.token, - baseUrl: this.config.apiBaseUrl, - }); - } + + const token = + ( + await this.config.credentialsProvider.getCredentials({ + url: values.storePath, + }) + ).token || ''; + + const client = new Octokit({ + auth: token, + baseUrl: this.config.apiBaseUrl, + }); const description = values.description as string; const access = values.access as string; const remoteUrl = await this.createRemote({ + client, description, access, name, @@ -98,7 +88,7 @@ export class GithubPublisher implements PublisherBase { remoteUrl, auth: { username: 'x-access-token', - password: this.config.token, + password: token, }, logger, }); @@ -111,27 +101,28 @@ export class GithubPublisher implements PublisherBase { } private async createRemote(opts: { + client: Octokit; access: string; name: string; owner: string; description: string; }) { - const { access, description, owner, name } = opts; + const { client, access, description, owner, name } = opts; - const user = await this.config.client.users.getByUsername({ + const user = await client.users.getByUsername({ username: owner, }); const repoCreationPromise = user.data.type === 'Organization' - ? this.config.client.repos.createInOrg({ + ? client.repos.createInOrg({ name, org: owner, private: this.config.repoVisibility !== 'public', visibility: this.config.repoVisibility, description, }) - : this.config.client.repos.createForAuthenticatedUser({ + : client.repos.createForAuthenticatedUser({ name, private: this.config.repoVisibility === 'private', description, @@ -141,7 +132,7 @@ export class GithubPublisher implements PublisherBase { if (access?.startsWith(`${owner}/`)) { const [, team] = access.split('/'); - await this.config.client.teams.addOrUpdateRepoPermissionsInOrg({ + await client.teams.addOrUpdateRepoPermissionsInOrg({ org: owner, team_slug: team, owner, @@ -150,7 +141,7 @@ export class GithubPublisher implements PublisherBase { }); // no need to add access if it's the person who own's the personal account } else if (access && access !== owner) { - await this.config.client.repos.addCollaborator({ + await client.repos.addCollaborator({ owner, repo: name, username: access, From edbc27bfdc1c0ba4b3f93cf3f109f49804170853 Mon Sep 17 00:00:00 2001 From: ebarrios Date: Tue, 16 Feb 2021 10:59:04 +0100 Subject: [PATCH 07/12] Added changeset --- .changeset/loud-owls-beam.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/loud-owls-beam.md diff --git a/.changeset/loud-owls-beam.md b/.changeset/loud-owls-beam.md new file mode 100644 index 0000000000..f17b23223b --- /dev/null +++ b/.changeset/loud-owls-beam.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +Added githubApp authentication to the scaffolder-backend plugin From 3fc738a55c494da8c577da1e9b021ad8c517c041 Mon Sep 17 00:00:00 2001 From: ebarrios Date: Tue, 16 Feb 2021 12:58:15 +0100 Subject: [PATCH 08/12] modify change set to path, simplify to one expresion the check for config.token and config.apps and deconstructed the response fron the credentialProvider.getCredentials function --- .changeset/loud-owls-beam.md | 2 +- .../src/scaffolder/stages/publish/github.ts | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.changeset/loud-owls-beam.md b/.changeset/loud-owls-beam.md index f17b23223b..764bfdf72a 100644 --- a/.changeset/loud-owls-beam.md +++ b/.changeset/loud-owls-beam.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-scaffolder-backend': minor +'@backstage/plugin-scaffolder-backend': patch --- Added githubApp authentication to the scaffolder-backend plugin diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 1846cb90d1..365b3f14cd 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -31,10 +31,8 @@ export class GithubPublisher implements PublisherBase { config: GitHubIntegrationConfig, { repoVisibility }: { repoVisibility: RepoVisibilityOptions }, ) { - if (!config.token) { - if (!config.apps) { - return undefined; - } + if (!config.token && !config.apps) { + return undefined; } const credentialsProvider = GithubCredentialsProvider.create(config); @@ -61,12 +59,13 @@ export class GithubPublisher implements PublisherBase { }: PublisherOptions): Promise { const { owner, name } = parseGitUrl(values.storePath); - const token = - ( - await this.config.credentialsProvider.getCredentials({ - url: values.storePath, - }) - ).token || ''; + const { token } = await this.config.credentialsProvider.getCredentials({ + url: values.storePath, + }); + + if (!token) { + return { remoteUrl: '', catalogInfoUrl: undefined }; + } const client = new Octokit({ auth: token, From fdd33af1cf79e71d35f550f353a7d5cac126eddb Mon Sep 17 00:00:00 2001 From: ebarrios Date: Tue, 16 Feb 2021 15:10:00 +0100 Subject: [PATCH 09/12] Added githubApp authentication for the scaffolder prepare stage --- .../src/scaffolder/stages/prepare/github.ts | 28 ++++++++++++------- .../src/scaffolder/stages/publish/github.ts | 1 + 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts index 5b74ee81ca..d2b29b5d0b 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts @@ -18,14 +18,20 @@ import path from 'path'; import { Git } from '@backstage/backend-common'; import { PreparerBase, PreparerOptions } from './types'; import parseGitUrl from 'git-url-parse'; -import { GitHubIntegrationConfig } from '@backstage/integration'; +import { + GitHubIntegrationConfig, + GithubCredentialsProvider, +} from '@backstage/integration'; export class GithubPreparer implements PreparerBase { static fromConfig(config: GitHubIntegrationConfig) { - return new GithubPreparer({ token: config.token }); + const credentialsProvider = GithubCredentialsProvider.create(config); + return new GithubPreparer({ credentialsProvider }); } - constructor(private readonly config: { token?: string }) {} + constructor( + private readonly config: { credentialsProvider: GithubCredentialsProvider }, + ) {} async prepare({ url, workspacePath, logger }: PreparerOptions) { const parsedGitUrl = parseGitUrl(url); @@ -36,13 +42,15 @@ export class GithubPreparer implements PreparerBase { parsedGitUrl.filepath ?? '', ); - const git = this.config.token - ? Git.fromAuth({ - username: 'x-access-token', - password: this.config.token, - logger, - }) - : Git.fromAuth({ logger }); + const { token } = await this.config.credentialsProvider.getCredentials({ + url, + }); + + const git = Git.fromAuth({ + username: 'x-access-token', + password: token, + logger, + }); await git.clone({ url: parsedGitUrl.toString('https'), diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 365b3f14cd..e71da7fb84 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -64,6 +64,7 @@ export class GithubPublisher implements PublisherBase { }); if (!token) { + logger.error(`Unable to adquire credentials for ${owner}/${name}`); return { remoteUrl: '', catalogInfoUrl: undefined }; } From cc2c047f15791f90c5635acd81a190a5d7c62f5f Mon Sep 17 00:00:00 2001 From: ebarrios Date: Tue, 16 Feb 2021 19:50:56 +0100 Subject: [PATCH 10/12] Reverted change to preparer function to use Git.fromAuth({ logger }) when the credentials provider can not get a token --- .../src/scaffolder/stages/prepare/github.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts index d2b29b5d0b..81ccdeb026 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts @@ -46,11 +46,13 @@ export class GithubPreparer implements PreparerBase { url, }); - const git = Git.fromAuth({ - username: 'x-access-token', - password: token, - logger, - }); + const git = token + ? Git.fromAuth({ + username: 'x-access-token', + password: token, + logger, + }) + : Git.fromAuth({ logger }); await git.clone({ url: parsedGitUrl.toString('https'), From 36a4ede27516becd0683ef59393bcd82dd3ea39c Mon Sep 17 00:00:00 2001 From: ebarrios Date: Tue, 16 Feb 2021 19:56:18 +0100 Subject: [PATCH 11/12] Change error message in the publish func for when the credentials provider can not get a token --- .../scaffolder-backend/src/scaffolder/stages/publish/github.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index e71da7fb84..4de928c32b 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -64,7 +64,7 @@ export class GithubPublisher implements PublisherBase { }); if (!token) { - logger.error(`Unable to adquire credentials for ${owner}/${name}`); + logger.error(`No token could be acquired for URL: ${values.storePath}`); return { remoteUrl: '', catalogInfoUrl: undefined }; } From 233b78a42ef566aa10df6b6a08397ec7dbe54682 Mon Sep 17 00:00:00 2001 From: ebarrios Date: Wed, 17 Feb 2021 12:23:16 +0100 Subject: [PATCH 12/12] Replace logging erro and return undefined for a throw new Error --- .../src/scaffolder/stages/publish/github.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 4de928c32b..a449eddd5d 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -64,8 +64,9 @@ export class GithubPublisher implements PublisherBase { }); if (!token) { - logger.error(`No token could be acquired for URL: ${values.storePath}`); - return { remoteUrl: '', catalogInfoUrl: undefined }; + throw new Error( + `No token could be acquired for URL: ${values.storePath}`, + ); } const client = new Octokit({