feat: pass through the the token in scaffolder

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2024-01-25 19:21:58 +01:00
parent 75dd39d084
commit ed0f7336d8
6 changed files with 78 additions and 2 deletions
@@ -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',
}),
);
});
});
@@ -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,
});
},
});
@@ -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,
@@ -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,
});
},
});
@@ -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' }),
);
});
});
});
@@ -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');