scaffolder-backend: pass token to tasks

Signed-off-by: Diego Drumond <diego.ribeiro@hotmart.com>
This commit is contained in:
Diego Drumond
2022-01-12 08:55:16 -03:00
parent 332b47fcdf
commit fced56a416
2 changed files with 33 additions and 2 deletions
@@ -22,7 +22,7 @@ import { NunjucksWorkflowRunner } from './NunjucksWorkflowRunner';
import { TemplateActionRegistry } from '../actions';
import { ScmIntegrations } from '@backstage/integration';
import { ConfigReader } from '@backstage/config';
import { TaskContext, TaskSpec } from './types';
import { TaskContext, TaskSpec, TaskSecrets } from './types';
const realFiles = Object.fromEntries(
[
@@ -49,8 +49,12 @@ describe('DefaultWorkflowRunner', () => {
}),
);
const createMockTaskWithSpec = (spec: TaskSpec): TaskContext => ({
const createMockTaskWithSpec = (
spec: TaskSpec,
secrets?: TaskSecrets,
): TaskContext => ({
spec,
secrets,
complete: async () => {},
done: false,
emitLog: async () => {},
@@ -182,6 +186,32 @@ describe('DefaultWorkflowRunner', () => {
name: templateName,
});
});
it('should pass token through', async () => {
const fakeToken = 'secret';
const task = createMockTaskWithSpec(
{
apiVersion: 'scaffolder.backstage.io/v1beta3',
parameters: {},
output: {},
steps: [
{
id: 'test',
name: 'name',
action: 'jest-validated-action',
input: { foo: 1 },
},
],
},
{
token: fakeToken,
},
);
await runner.execute(task);
expect(fakeActionHandler.mock.calls[0][0].token).toEqual(fakeToken);
});
});
describe('conditionals', () => {
@@ -257,6 +257,7 @@ export class NunjucksWorkflowRunner implements WorkflowRunner {
await action.handler({
baseUrl: task.spec.baseUrl,
input,
token: task.secrets?.token,
logger: taskLogger,
logStream: streamLogger,
workspacePath,