From 3d0dc89b76841cc2ad9d6322285a08ac4a14a405 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 16 Feb 2022 13:01:46 +0100 Subject: [PATCH 1/6] chore: removed the token from actions, it's now backstageToken Signed-off-by: blam --- .../src/scaffolder/tasks/HandlebarsWorkflowRunner.ts | 2 -- .../src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts | 6 ++++-- .../src/scaffolder/tasks/NunjucksWorkflowRunner.ts | 8 -------- .../src/scaffolder/tasks/StorageTaskBroker.test.ts | 2 +- plugins/scaffolder-backend/src/scaffolder/tasks/types.ts | 2 -- plugins/scaffolder-backend/src/service/router.test.ts | 2 +- 6 files changed, 6 insertions(+), 16 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/HandlebarsWorkflowRunner.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/HandlebarsWorkflowRunner.ts index 91c82edebb..86e719c828 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/HandlebarsWorkflowRunner.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/HandlebarsWorkflowRunner.ts @@ -236,8 +236,6 @@ export class HandlebarsWorkflowRunner implements WorkflowRunner { logger: taskLogger, logStream: stream, input, - // this token is deprecated, and will be removed in favour of secrets.backstageToken instead. - token: task.secrets?.token, secrets: task.secrets ?? {}, workspacePath, async createTemporaryDirectory() { diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts index 1597c575ac..d781fdc9cd 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts @@ -203,13 +203,15 @@ describe('DefaultWorkflowRunner', () => { ], }, { - token: fakeToken, + backstageToken: fakeToken, }, ); await runner.execute(task); - expect(fakeActionHandler.mock.calls[0][0].token).toEqual(fakeToken); + expect(fakeActionHandler.mock.calls[0][0].backstageToken).toEqual( + fakeToken, + ); }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts index 889e94d000..5d39d0bc00 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts @@ -258,17 +258,9 @@ export class NunjucksWorkflowRunner implements WorkflowRunner { const tmpDirs = new Array(); const stepOutput: { [outputName: string]: JsonValue } = {}; - if (!task.spec.metadata) { - console.warn( - 'DEPRECATION NOTICE: metadata is undefined. metadata will be required in the future.', - ); - } - await action.handler({ baseUrl: task.spec.baseUrl, input, - // this token is deprecated, and will be removed in favour of secrets.backstageToken instead. - token: task.secrets?.token, secrets: task.secrets ?? {}, logger: taskLogger, logStream: streamLogger, diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/StorageTaskBroker.test.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/StorageTaskBroker.test.ts index 130f6ced13..93285a4ab3 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/StorageTaskBroker.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/StorageTaskBroker.test.ts @@ -38,7 +38,7 @@ async function createStore(): Promise { describe('StorageTaskBroker', () => { let storage: DatabaseTaskStore; - const fakeSecrets = { token: 'secret' } as TaskSecrets; + const fakeSecrets = { backstageToken: 'secret' } as TaskSecrets; beforeAll(async () => { storage = await createStore(); diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/types.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/types.ts index 8caee87f57..8b28fe562c 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/types.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/types.ts @@ -90,8 +90,6 @@ export type SerializedTaskEvent = { * @public */ export type TaskSecrets = Record & { - /** @deprecated Use `backstageToken` instead */ - token?: string; backstageToken?: string; }; diff --git a/plugins/scaffolder-backend/src/service/router.test.ts b/plugins/scaffolder-backend/src/service/router.test.ts index 6e01c3d880..b20dfa5d24 100644 --- a/plugins/scaffolder-backend/src/service/router.test.ts +++ b/plugins/scaffolder-backend/src/service/router.test.ts @@ -182,7 +182,7 @@ describe('createRouter', () => { spec: {} as any, status: 'completed', createdAt: '', - secrets: { token: 'secret' }, + secrets: { backstageToken: 'secret' }, }); const response = await request(app).get(`/v2/tasks/a-random-id`); From 7bed999eb67770339b7daceb7ca53fbe004a105e Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 16 Feb 2022 13:06:04 +0100 Subject: [PATCH 2/6] chore: updating api-report with removed token Signed-off-by: blam --- plugins/scaffolder-backend/api-report.md | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index d2967bf88a..010b235621 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -553,7 +553,6 @@ export class TaskManager implements TaskContext { // @public export type TaskSecrets = Record & { - token?: string; backstageToken?: string; }; From 8db2b671c60f246fb184a9be6bae80eae994ec0c Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 16 Feb 2022 13:08:28 +0100 Subject: [PATCH 3/6] chore: added changeset Signed-off-by: blam --- .changeset/pretty-gorillas-cheat.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/pretty-gorillas-cheat.md diff --git a/.changeset/pretty-gorillas-cheat.md b/.changeset/pretty-gorillas-cheat.md new file mode 100644 index 0000000000..349aee7355 --- /dev/null +++ b/.changeset/pretty-gorillas-cheat.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +**BREAKING**: `ctx.secrets.token` is now `ctx.secrets.backstageToken` in actions. Please update any of your actions that might call out to Backstage API's with this token. From 0df5389f2f03bdbfb7c052673afd2c8fd19d09aa Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 16 Feb 2022 13:16:00 +0100 Subject: [PATCH 4/6] chore: remove from ActionsContext too Signed-off-by: blam --- plugins/scaffolder-backend/api-report.md | 1 - plugins/scaffolder-backend/src/scaffolder/actions/types.ts | 6 ------ 2 files changed, 7 deletions(-) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 010b235621..a28db34c0c 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -41,7 +41,6 @@ export type ActionContext = { baseUrl?: string; logger: Logger_2; logStream: Writable; - token?: string | undefined; secrets?: TaskSecrets; workspacePath: string; input: Input; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/types.ts b/plugins/scaffolder-backend/src/scaffolder/actions/types.ts index f1e5dd7b77..6008e8183f 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/types.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/types.ts @@ -28,12 +28,6 @@ export type ActionContext = { logger: Logger; logStream: Writable; - - /** - * User token forwarded from initial request, for use in subsequent api requests - * @deprecated use `secrets.backstageToken` instead - */ - token?: string | undefined; secrets?: TaskSecrets; workspacePath: string; input: Input; From 79c500e10e0670534b9cc9e7a581b95c8f76326c Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 16 Feb 2022 13:18:24 +0100 Subject: [PATCH 5/6] chore: updating changeset Signed-off-by: blam --- .changeset/pretty-gorillas-cheat.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/pretty-gorillas-cheat.md b/.changeset/pretty-gorillas-cheat.md index 349aee7355..d1500c6575 100644 --- a/.changeset/pretty-gorillas-cheat.md +++ b/.changeset/pretty-gorillas-cheat.md @@ -2,4 +2,4 @@ '@backstage/plugin-scaffolder-backend': minor --- -**BREAKING**: `ctx.secrets.token` is now `ctx.secrets.backstageToken` in actions. Please update any of your actions that might call out to Backstage API's with this token. +**BREAKING**: `ctx.token` is now `ctx.secrets.backstageToken` in Actions. Please update any of your Actions that might call out to Backstage API's with this token. From 91f6be833e7b6b8c21239867e55576eae5fc9f70 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 16 Feb 2022 14:55:30 +0100 Subject: [PATCH 6/6] chore: fixing test Signed-off-by: blam --- .../src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts index d781fdc9cd..f46d969eb8 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts @@ -209,8 +209,8 @@ describe('DefaultWorkflowRunner', () => { await runner.execute(task); - expect(fakeActionHandler.mock.calls[0][0].backstageToken).toEqual( - fakeToken, + expect(fakeActionHandler.mock.calls[0][0].secrets).toEqual( + expect.objectContaining({ backstageToken: fakeToken }), ); }); });