diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plain.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plain.test.ts index 249941096d..ad179d8269 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plain.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plain.test.ts @@ -85,4 +85,23 @@ describe('fetch:plain', () => { }), ); }); + + it('should fetch plain with token', async () => { + await action.handler({ + ...mockContext, + input: { + url: 'https://github.com/backstage/community/tree/main/backstage-community-sessions/assets', + targetPath: 'lol', + token: 'mockToken', + }, + }); + + expect(fetchContents).toHaveBeenCalledWith( + expect.objectContaining({ + outputPath: resolvePath(mockContext.workspacePath, 'lol'), + fetchUrl: + 'https://github.com/backstage/community/tree/main/backstage-community-sessions/assets', + }), + ); + }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plain.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plain.ts index 57f3d1121b..8bca630af9 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plain.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plain.ts @@ -36,7 +36,11 @@ export function createFetchPlainAction(options: { }) { const { reader, integrations } = options; - return createTemplateAction<{ url: string; targetPath?: string }>({ + return createTemplateAction<{ + url: string; + targetPath?: string; + token?: string; + }>({ id: ACTION_ID, examples, description: @@ -58,6 +62,12 @@ export function createFetchPlainAction(options: { 'Target path within the working directory to download the contents to.', type: 'string', }, + token: { + title: 'Token', + description: + 'An optional token to use for authentication when reading the resources.', + type: 'string', + }, }, }, }, @@ -75,6 +85,7 @@ export function createFetchPlainAction(options: { baseUrl: ctx.templateInfo?.baseUrl, fetchUrl: ctx.input.url, outputPath, + token: ctx.input.token, }); }, }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plainFile.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plainFile.test.ts index 084b08d640..7ea74a809b 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plainFile.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plainFile.test.ts @@ -69,6 +69,21 @@ describe('fetch:plain:file', () => { ); }); + it('passed through the token to fetchFile', async () => { + await action.handler({ + ...mockContext, + input: { + url: 'https://github.com/backstage/community/tree/main/backstage-community-sessions/assets/Backstage%20Community%20Sessions.png', + token: 'mockToken', + targetPath: 'lol', + }, + }); + + expect(fetchFile).toHaveBeenCalledWith( + expect.objectContaining({ token: 'mockToken' }), + ); + }); + it('should fetch plain', async () => { await action.handler({ ...mockContext, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plainFile.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plainFile.ts index 0a791a31a4..da0255ff5a 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plainFile.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/plainFile.ts @@ -33,7 +33,11 @@ export function createFetchPlainFileAction(options: { }) { const { reader, integrations } = options; - return createTemplateAction<{ url: string; targetPath: string }>({ + return createTemplateAction<{ + url: string; + targetPath: string; + token?: string; + }>({ id: 'fetch:plain:file', description: 'Downloads single file and places it in the workspace.', examples, @@ -54,6 +58,12 @@ export function createFetchPlainFileAction(options: { 'Target path within the working directory to download the file as.', type: 'string', }, + token: { + title: 'Token', + description: + 'An optional token to use for authentication when reading the resources.', + type: 'string', + }, }, }, }, @@ -73,6 +83,7 @@ export function createFetchPlainFileAction(options: { baseUrl: ctx.templateInfo?.baseUrl, fetchUrl: ctx.input.url, outputPath, + token: ctx.input.token, }); }, }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts index 119cd78eb7..25b65462e6 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts @@ -371,6 +371,18 @@ describe('fetch:template', () => { fs.readlink(`${workspacePath}/target/brokenSymlink`), ).resolves.toEqual(`.${pathSep}not-a-real-file.txt`); }); + + it('passed through the token to the fetchContents call', async () => { + await action.handler( + mockContext({ + token: 'mockToken', + }), + ); + + expect(mockFetchContents).toHaveBeenCalledWith( + expect.objectContaining({ token: 'mockToken' }), + ); + }); }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts index 2a2c138708..63a595ef80 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts @@ -71,6 +71,7 @@ export function createFetchTemplateAction(options: { replace?: boolean; trimBlocks?: boolean; lstripBlocks?: boolean; + token?: string; }>({ id: 'fetch:template', description: @@ -134,6 +135,12 @@ export function createFetchTemplateAction(options: { 'If set, replace files in targetPath instead of skipping existing ones.', type: 'boolean', }, + token: { + title: 'Token', + description: + 'An optional token to use for authentication when reading the resources.', + type: 'string', + }, }, }, }, @@ -197,6 +204,7 @@ export function createFetchTemplateAction(options: { baseUrl: ctx.templateInfo?.baseUrl, fetchUrl: ctx.input.url, outputPath: templateDir, + token: ctx.input.token, }); ctx.logger.info('Listing files and directories in template');