@backstage/plugin-scaffolder-backend 1.22.5 → 1.22.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,11 +1,110 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
- ## 1.22.5
4
-
5
- ### Patch Changes
6
-
7
- - b6b59c5: Fix issue with the log format not being respected when logging from actions
8
- - b6b59c5: Redact `meta` fields too with the logger
3
+ ## 1.22.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 131e5cb: Fix broken links in README.
8
+ - 025641b: Fix issue with the log format not being respected when logging from actions
9
+ - d229dc4: Move path utilities from `backend-common` to the `backend-plugin-api` package.
10
+ - e4b50ab: Scaffolder workspace serialization
11
+ - 025641b: Redact `meta` fields too with the logger
12
+ - Updated dependencies
13
+ - @backstage/plugin-scaffolder-common@1.5.2
14
+ - @backstage/plugin-catalog-node@1.12.0
15
+ - @backstage/plugin-scaffolder-backend-module-github@0.2.8
16
+ - @backstage/plugin-scaffolder-backend-module-gitea@0.1.8
17
+ - @backstage/plugin-scaffolder-backend-module-gitlab@0.4.0
18
+ - @backstage/catalog-model@1.5.0
19
+ - @backstage/backend-common@0.22.0
20
+ - @backstage/backend-plugin-api@0.6.18
21
+ - @backstage/plugin-scaffolder-node@0.4.4
22
+ - @backstage/backend-tasks@0.5.23
23
+ - @backstage/plugin-scaffolder-backend-module-bitbucket-server@0.1.8
24
+ - @backstage/plugin-auth-node@0.4.13
25
+ - @backstage/integration@1.11.0
26
+ - @backstage/catalog-client@1.6.5
27
+ - @backstage/plugin-catalog-backend-module-scaffolder-entity-model@0.1.16
28
+ - @backstage/plugin-permission-node@0.7.29
29
+ - @backstage/plugin-scaffolder-backend-module-azure@0.1.10
30
+ - @backstage/plugin-scaffolder-backend-module-bitbucket@0.2.8
31
+ - @backstage/plugin-scaffolder-backend-module-bitbucket-cloud@0.1.8
32
+ - @backstage/plugin-scaffolder-backend-module-gerrit@0.1.10
33
+
34
+ ## 1.22.6-next.2
35
+
36
+ ### Patch Changes
37
+
38
+ - e4b50ab: Scaffolder workspace serialization
39
+ - Updated dependencies
40
+ - @backstage/plugin-catalog-node@1.12.0-next.2
41
+ - @backstage/plugin-scaffolder-backend-module-gitlab@0.4.0-next.2
42
+ - @backstage/backend-common@0.22.0-next.2
43
+ - @backstage/plugin-scaffolder-node@0.4.4-next.2
44
+ - @backstage/integration@1.11.0-next.0
45
+ - @backstage/plugin-catalog-backend-module-scaffolder-entity-model@0.1.16-next.2
46
+ - @backstage/plugin-scaffolder-backend-module-azure@0.1.10-next.2
47
+ - @backstage/plugin-scaffolder-backend-module-bitbucket@0.2.8-next.2
48
+ - @backstage/plugin-scaffolder-backend-module-bitbucket-cloud@0.1.8-next.2
49
+ - @backstage/plugin-scaffolder-backend-module-bitbucket-server@0.1.8-next.2
50
+ - @backstage/plugin-scaffolder-backend-module-gerrit@0.1.10-next.2
51
+ - @backstage/plugin-scaffolder-backend-module-gitea@0.1.8-next.2
52
+ - @backstage/plugin-scaffolder-backend-module-github@0.2.8-next.2
53
+
54
+ ## 1.22.5-next.1
55
+
56
+ ### Patch Changes
57
+
58
+ - Updated dependencies
59
+ - @backstage/plugin-scaffolder-common@1.5.2-next.1
60
+ - @backstage/backend-common@0.22.0-next.1
61
+ - @backstage/plugin-catalog-backend-module-scaffolder-entity-model@0.1.16-next.1
62
+ - @backstage/plugin-scaffolder-node@0.4.4-next.1
63
+ - @backstage/backend-tasks@0.5.23-next.1
64
+ - @backstage/plugin-auth-node@0.4.13-next.1
65
+ - @backstage/plugin-permission-node@0.7.29-next.1
66
+ - @backstage/plugin-scaffolder-backend-module-github@0.2.8-next.1
67
+ - @backstage/plugin-scaffolder-backend-module-gitlab@0.3.4-next.1
68
+ - @backstage/plugin-scaffolder-backend-module-azure@0.1.10-next.1
69
+ - @backstage/plugin-scaffolder-backend-module-bitbucket@0.2.8-next.1
70
+ - @backstage/plugin-scaffolder-backend-module-bitbucket-cloud@0.1.8-next.1
71
+ - @backstage/plugin-scaffolder-backend-module-bitbucket-server@0.1.8-next.1
72
+ - @backstage/plugin-scaffolder-backend-module-gerrit@0.1.10-next.1
73
+ - @backstage/plugin-scaffolder-backend-module-gitea@0.1.8-next.1
74
+ - @backstage/plugin-catalog-node@1.11.2-next.1
75
+ - @backstage/backend-plugin-api@0.6.18-next.1
76
+
77
+ ## 1.22.5-next.0
78
+
79
+ ### Patch Changes
80
+
81
+ - 025641b: Fix issue with the log format not being respected when logging from actions
82
+ - 025641b: Redact `meta` fields too with the logger
83
+ - Updated dependencies
84
+ - @backstage/plugin-scaffolder-backend-module-github@0.2.8-next.0
85
+ - @backstage/plugin-scaffolder-backend-module-gitea@0.1.8-next.0
86
+ - @backstage/catalog-model@1.5.0-next.0
87
+ - @backstage/plugin-scaffolder-backend-module-gitlab@0.3.4-next.0
88
+ - @backstage/plugin-scaffolder-backend-module-bitbucket-server@0.1.8-next.0
89
+ - @backstage/plugin-auth-node@0.4.13-next.0
90
+ - @backstage/backend-common@0.21.8-next.0
91
+ - @backstage/backend-plugin-api@0.6.18-next.0
92
+ - @backstage/catalog-client@1.6.5-next.0
93
+ - @backstage/plugin-catalog-backend-module-scaffolder-entity-model@0.1.16-next.0
94
+ - @backstage/plugin-catalog-node@1.11.2-next.0
95
+ - @backstage/plugin-scaffolder-common@1.5.2-next.0
96
+ - @backstage/plugin-scaffolder-node@0.4.4-next.0
97
+ - @backstage/backend-tasks@0.5.23-next.0
98
+ - @backstage/config@1.2.0
99
+ - @backstage/errors@1.2.4
100
+ - @backstage/integration@1.10.0
101
+ - @backstage/types@1.1.1
102
+ - @backstage/plugin-permission-common@0.7.13
103
+ - @backstage/plugin-permission-node@0.7.29-next.0
104
+ - @backstage/plugin-scaffolder-backend-module-azure@0.1.10-next.0
105
+ - @backstage/plugin-scaffolder-backend-module-bitbucket@0.2.8-next.0
106
+ - @backstage/plugin-scaffolder-backend-module-bitbucket-cloud@0.1.8-next.0
107
+ - @backstage/plugin-scaffolder-backend-module-gerrit@0.1.10-next.0
9
108
 
10
109
  ## 1.22.4
11
110
 
package/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  # Scaffolder Backend
2
2
 
3
- This is the backend for the default Backstage [software
4
- templates](https://backstage.io/docs/features/software-templates/).
5
- This provides the API for the frontend [scaffolder
6
- plugin](https://github.com/backstage/backstage/tree/master/plugins/scaffolder),
3
+ This is the backend for the default Backstage [software templates](https://backstage.io/docs/features/software-templates/).
4
+ This provides the API for the frontend [scaffolder plugin](https://github.com/backstage/backstage/tree/master/plugins/scaffolder),
7
5
  as well as the built-in template actions, tasks and stages.
8
6
 
9
7
  ## Installation
@@ -24,12 +22,19 @@ restoring the plugin, if you previously removed it.
24
22
  yarn --cwd packages/backend add @backstage/plugin-scaffolder-backend
25
23
  ```
26
24
 
27
- ### Adding the plugin to your `packages/backend`
25
+ Then add the plugin to your backend, typically in `packages/backend/src/index.ts`:
28
26
 
29
- You'll need to add the plugin to the router in your `backend` package. You can
30
- do this by creating a file called `packages/backend/src/plugins/scaffolder.ts`
31
- with contents matching [scaffolder.ts in the create-app
32
- template](https://github.com/backstage/backstage/blob/master/packages/create-app/templates/default-app/packages/backend/src/plugins/scaffolder.ts).
27
+ ```ts
28
+ const backend = createBackend();
29
+ // ...
30
+ backend.add(import('@backstage/plugin-scaffolder-backend/alpha'));
31
+ ```
32
+
33
+ #### Old backend system
34
+
35
+ In the old backend system there's a bit more wiring required. You'll need to
36
+ create a file called `packages/backend/src/plugins/scaffolder.ts`
37
+ with contents matching [scaffolder.ts in the create-app template](https://github.com/backstage/backstage/blob/ad9314d3a7e0405719ba93badf96e97adde8ef83/packages/create-app/templates/default-app/packages/backend/src/plugins/scaffolder.ts).
33
38
 
34
39
  With the `scaffolder.ts` router setup in place, add the router to
35
40
  `packages/backend/src/index.ts`:
@@ -54,10 +59,7 @@ async function main() {
54
59
  ### Adding templates
55
60
 
56
61
  At this point the scaffolder backend is installed in your backend package, but
57
- you will not have any templates available to use. These need to be [added to the
58
- software
59
- catalog](https://backstage.io/docs/features/software-templates/adding-templates).
62
+ you will not have any templates available to use. These need to be [added to the software catalog](https://backstage.io/docs/features/software-templates/adding-templates).
60
63
 
61
64
  To get up and running and try out some templates quickly, you can or copy the
62
- catalog locations from the [create-app
63
- template](https://github.com/backstage/backstage/blob/master/packages/create-app/templates/default-app/app-config.yaml.hbs).
65
+ catalog locations from the [create-app template](https://github.com/backstage/backstage/blob/master/packages/create-app/templates/default-app/app-config.yaml.hbs).
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend",
3
- "version": "1.22.5",
3
+ "version": "1.22.6",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/config.d.ts CHANGED
@@ -47,6 +47,11 @@ export interface Config {
47
47
  */
48
48
  EXPERIMENTAL_recoverTasks?: boolean;
49
49
 
50
+ /**
51
+ * Sets the serialization of the workspace to have an ability to rerun the failed task.
52
+ */
53
+ EXPERIMENTAL_workspaceSerialization?: boolean;
54
+
50
55
  /**
51
56
  * Every task which is in progress state and having a last heartbeat longer than a specified timeout is going to
52
57
  * be attempted to recover.
package/dist/alpha.cjs.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var alpha = require('@backstage/plugin-scaffolder-common/alpha');
6
6
  var pluginPermissionNode = require('@backstage/plugin-permission-node');
7
- var router = require('./cjs/router-CDFi_apW.cjs.js');
7
+ var router = require('./cjs/router-BKGs_U4O.cjs.js');
8
8
  var backendPluginApi = require('@backstage/backend-plugin-api');
9
9
  var backendCommon = require('@backstage/backend-common');
10
10
  var integration = require('@backstage/integration');
@@ -39,9 +39,12 @@ require('isbinaryfile');
39
39
  require('isolated-vm');
40
40
  require('lodash/get');
41
41
  require('uuid');
42
+ require('tar');
43
+ require('concat-stream');
44
+ require('util');
45
+ require('stream');
42
46
  require('winston');
43
47
  require('nunjucks');
44
- require('stream');
45
48
  require('prom-client');
46
49
  require('@backstage/plugin-permission-common');
47
50
  require('winston-transport');
@@ -1 +1 @@
1
- {"version":3,"file":"alpha.cjs.js","sources":["../src/service/conditionExports.ts","../src/ScaffolderPlugin.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,\n RESOURCE_TYPE_SCAFFOLDER_ACTION,\n} from '@backstage/plugin-scaffolder-common/alpha';\nimport { createConditionExports } from '@backstage/plugin-permission-node';\nimport { scaffolderTemplateRules, scaffolderActionRules } from './rules';\n\nconst templateConditionExports = createConditionExports({\n pluginId: 'scaffolder',\n resourceType: RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,\n rules: scaffolderTemplateRules,\n});\n\nconst actionsConditionExports = createConditionExports({\n pluginId: 'scaffolder',\n resourceType: RESOURCE_TYPE_SCAFFOLDER_ACTION,\n rules: scaffolderActionRules,\n});\n\n/**\n * `createScaffolderTemplateConditionalDecision` can be used when authoring policies to\n * create conditional decisions. It requires a permission of type\n * `ResourcePermission<'scaffolder-template'>` to be passed as the first parameter.\n * It's recommended that you use the provided `isResourcePermission` and\n * `isPermission` helper methods to narrow the type of the permission passed to\n * the handle method as shown below.\n *\n * ```\n * // MyAuthorizationPolicy.ts\n * ...\n * import { createScaffolderPolicyDecision } from '@backstage/plugin-scaffolder-backend';\n * import { RESOURCE_TYPE_SCAFFOLDER_TEMPLATE } from '@backstage/plugin-scaffolder-common';\n *\n * class MyAuthorizationPolicy implements PermissionPolicy {\n * async handle(request, user) {\n * ...\n *\n * if (isResourcePermission(request.permission, RESOURCE_TYPE_SCAFFOLDER_TEMPLATE)) {\n * return createScaffolderConditionalDecision(\n * request.permission,\n * { anyOf: [...insert conditions here...] }\n * );\n * }\n *\n * ...\n * }\n *\n * ```\n *\n * @alpha\n */\nexport const createScaffolderTemplateConditionalDecision =\n templateConditionExports.createConditionalDecision;\n\n/**\n * These conditions are used when creating conditional decisions for scaffolder\n * templates that are returned by authorization policies.\n *\n * @alpha\n */\nexport const scaffolderTemplateConditions = templateConditionExports.conditions;\n\n/**\n * @alpha\n */\nexport const createScaffolderActionConditionalDecision =\n actionsConditionExports.createConditionalDecision;\n\n/**\n *\n * These conditions are used when creating conditional decisions for scaffolder\n * actions that are returned by authorization policies.\n *\n * @alpha\n */\nexport const scaffolderActionConditions = actionsConditionExports.conditions;\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createBackendPlugin,\n coreServices,\n} from '@backstage/backend-plugin-api';\nimport { loggerToWinstonLogger } from '@backstage/backend-common';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha';\nimport {\n TaskBroker,\n TemplateAction,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport {\n scaffolderActionsExtensionPoint,\n scaffolderTaskBrokerExtensionPoint,\n scaffolderTemplatingExtensionPoint,\n} from '@backstage/plugin-scaffolder-node/alpha';\nimport {\n createCatalogRegisterAction,\n createCatalogWriteAction,\n createDebugLogAction,\n createFetchCatalogEntityAction,\n createFetchPlainAction,\n createFetchPlainFileAction,\n createFetchTemplateAction,\n createFilesystemDeleteAction,\n createFilesystemRenameAction,\n createWaitAction,\n} from './scaffolder';\nimport { createRouter } from './service/router';\n\n/**\n * Scaffolder plugin\n *\n * @alpha\n */\nexport const scaffolderPlugin = createBackendPlugin({\n pluginId: 'scaffolder',\n register(env) {\n const addedActions = new Array<TemplateAction<any, any>>();\n env.registerExtensionPoint(scaffolderActionsExtensionPoint, {\n addActions(...newActions: TemplateAction<any>[]) {\n addedActions.push(...newActions);\n },\n });\n\n let taskBroker: TaskBroker | undefined;\n env.registerExtensionPoint(scaffolderTaskBrokerExtensionPoint, {\n setTaskBroker(newTaskBroker) {\n if (taskBroker) {\n throw new Error('Task broker may only be set once');\n }\n taskBroker = newTaskBroker;\n },\n });\n\n const additionalTemplateFilters: Record<string, TemplateFilter> = {};\n const additionalTemplateGlobals: Record<string, TemplateGlobal> = {};\n env.registerExtensionPoint(scaffolderTemplatingExtensionPoint, {\n addTemplateFilters(newFilters) {\n Object.assign(additionalTemplateFilters, newFilters);\n },\n addTemplateGlobals(newGlobals) {\n Object.assign(additionalTemplateGlobals, newGlobals);\n },\n });\n\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n lifecycle: coreServices.rootLifecycle,\n reader: coreServices.urlReader,\n permissions: coreServices.permissions,\n database: coreServices.database,\n auth: coreServices.auth,\n discovery: coreServices.discovery,\n httpRouter: coreServices.httpRouter,\n httpAuth: coreServices.httpAuth,\n catalogClient: catalogServiceRef,\n },\n async init({\n logger,\n config,\n lifecycle,\n reader,\n database,\n auth,\n discovery,\n httpRouter,\n httpAuth,\n catalogClient,\n permissions,\n }) {\n const log = loggerToWinstonLogger(logger);\n const integrations = ScmIntegrations.fromConfig(config);\n\n const actions = [\n // actions provided from other modules\n ...addedActions,\n\n // built-in actions for the scaffolder\n createFetchPlainAction({\n reader,\n integrations,\n }),\n createFetchPlainFileAction({\n reader,\n integrations,\n }),\n createFetchTemplateAction({\n integrations,\n reader,\n additionalTemplateFilters,\n additionalTemplateGlobals,\n }),\n createDebugLogAction(),\n createWaitAction(),\n // todo(blam): maybe these should be a -catalog module?\n createCatalogRegisterAction({ catalogClient, integrations, auth }),\n createFetchCatalogEntityAction({ catalogClient, auth }),\n createCatalogWriteAction(),\n createFilesystemDeleteAction(),\n createFilesystemRenameAction(),\n ];\n\n const actionIds = actions.map(action => action.id).join(', ');\n\n log.info(\n `Starting scaffolder with the following actions enabled ${actionIds}`,\n );\n\n const router = await createRouter({\n logger: log,\n config,\n database,\n catalogClient,\n reader,\n lifecycle,\n actions,\n taskBroker,\n additionalTemplateFilters,\n additionalTemplateGlobals,\n auth,\n httpAuth,\n discovery,\n permissions,\n });\n httpRouter.use(router);\n },\n });\n },\n});\n"],"names":["createConditionExports","RESOURCE_TYPE_SCAFFOLDER_TEMPLATE","scaffolderTemplateRules","RESOURCE_TYPE_SCAFFOLDER_ACTION","scaffolderActionRules","createBackendPlugin","scaffolderActionsExtensionPoint","scaffolderTaskBrokerExtensionPoint","scaffolderTemplatingExtensionPoint","coreServices","catalogServiceRef","loggerToWinstonLogger","ScmIntegrations","createFetchPlainAction","createFetchPlainFileAction","createFetchTemplateAction","createDebugLogAction","createWaitAction","createCatalogRegisterAction","createFetchCatalogEntityAction","createCatalogWriteAction","createFilesystemDeleteAction","createFilesystemRenameAction","router","createRouter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,2BAA2BA,2CAAuB,CAAA;AAAA,EACtD,QAAU,EAAA,YAAA;AAAA,EACV,YAAc,EAAAC,uCAAA;AAAA,EACd,KAAO,EAAAC,8BAAA;AACT,CAAC,CAAA,CAAA;AAED,MAAM,0BAA0BF,2CAAuB,CAAA;AAAA,EACrD,QAAU,EAAA,YAAA;AAAA,EACV,YAAc,EAAAG,qCAAA;AAAA,EACd,KAAO,EAAAC,4BAAA;AACT,CAAC,CAAA,CAAA;AAkCM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A,EAAE,aAAe,EAAA,IAAA,EAAM,CAAA;AAAA,UACtDC,+BAAyB,EAAA;AAAA,UACzBC,mCAA6B,EAAA;AAAA,UAC7BC,mCAA6B,EAAA;AAAA,SAC/B,CAAA;AAEA,QAAM,MAAA,SAAA,GAAY,QAAQ,GAAI,CAAA,CAAA,MAAA,KAAU,OAAO,EAAE,CAAA,CAAE,KAAK,IAAI,CAAA,CAAA;AAE5D,QAAI,GAAA,CAAA,IAAA;AAAA,UACF,0DAA0D,SAAS,CAAA,CAAA;AAAA,SACrE,CAAA;AAEA,QAAM,MAAAC,QAAA,GAAS,MAAMC,mBAAa,CAAA;AAAA,UAChC,MAAQ,EAAA,GAAA;AAAA,UACR,MAAA;AAAA,UACA,QAAA;AAAA,UACA,aAAA;AAAA,UACA,MAAA;AAAA,UACA,SAAA;AAAA,UACA,OAAA;AAAA,UACA,UAAA;AAAA,UACA,yBAAA;AAAA,UACA,yBAAA;AAAA,UACA,IAAA;AAAA,UACA,QAAA;AAAA,UACA,SAAA;AAAA,UACA,WAAA;AAAA,SACD,CAAA,CAAA;AACD,QAAA,UAAA,CAAW,IAAID,QAAM,CAAA,CAAA;AAAA,OACvB;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;;;;"}
1
+ {"version":3,"file":"alpha.cjs.js","sources":["../src/service/conditionExports.ts","../src/ScaffolderPlugin.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,\n RESOURCE_TYPE_SCAFFOLDER_ACTION,\n} from '@backstage/plugin-scaffolder-common/alpha';\nimport { createConditionExports } from '@backstage/plugin-permission-node';\nimport { scaffolderTemplateRules, scaffolderActionRules } from './rules';\n\nconst templateConditionExports = createConditionExports({\n pluginId: 'scaffolder',\n resourceType: RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,\n rules: scaffolderTemplateRules,\n});\n\nconst actionsConditionExports = createConditionExports({\n pluginId: 'scaffolder',\n resourceType: RESOURCE_TYPE_SCAFFOLDER_ACTION,\n rules: scaffolderActionRules,\n});\n\n/**\n * `createScaffolderTemplateConditionalDecision` can be used when authoring policies to\n * create conditional decisions. It requires a permission of type\n * `ResourcePermission<'scaffolder-template'>` to be passed as the first parameter.\n * It's recommended that you use the provided `isResourcePermission` and\n * `isPermission` helper methods to narrow the type of the permission passed to\n * the handle method as shown below.\n *\n * ```\n * // MyAuthorizationPolicy.ts\n * ...\n * import { createScaffolderPolicyDecision } from '@backstage/plugin-scaffolder-backend';\n * import { RESOURCE_TYPE_SCAFFOLDER_TEMPLATE } from '@backstage/plugin-scaffolder-common';\n *\n * class MyAuthorizationPolicy implements PermissionPolicy {\n * async handle(request, user) {\n * ...\n *\n * if (isResourcePermission(request.permission, RESOURCE_TYPE_SCAFFOLDER_TEMPLATE)) {\n * return createScaffolderConditionalDecision(\n * request.permission,\n * { anyOf: [...insert conditions here...] }\n * );\n * }\n *\n * ...\n * }\n *\n * ```\n *\n * @alpha\n */\nexport const createScaffolderTemplateConditionalDecision =\n templateConditionExports.createConditionalDecision;\n\n/**\n * These conditions are used when creating conditional decisions for scaffolder\n * templates that are returned by authorization policies.\n *\n * @alpha\n */\nexport const scaffolderTemplateConditions = templateConditionExports.conditions;\n\n/**\n * @alpha\n */\nexport const createScaffolderActionConditionalDecision =\n actionsConditionExports.createConditionalDecision;\n\n/**\n *\n * These conditions are used when creating conditional decisions for scaffolder\n * actions that are returned by authorization policies.\n *\n * @alpha\n */\nexport const scaffolderActionConditions = actionsConditionExports.conditions;\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createBackendPlugin,\n coreServices,\n} from '@backstage/backend-plugin-api';\nimport { loggerToWinstonLogger } from '@backstage/backend-common';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha';\nimport {\n TaskBroker,\n TemplateAction,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport {\n scaffolderActionsExtensionPoint,\n scaffolderTaskBrokerExtensionPoint,\n scaffolderTemplatingExtensionPoint,\n} from '@backstage/plugin-scaffolder-node/alpha';\nimport {\n createCatalogRegisterAction,\n createCatalogWriteAction,\n createDebugLogAction,\n createFetchCatalogEntityAction,\n createFetchPlainAction,\n createFetchPlainFileAction,\n createFetchTemplateAction,\n createFilesystemDeleteAction,\n createFilesystemRenameAction,\n createWaitAction,\n} from './scaffolder';\nimport { createRouter } from './service/router';\n\n/**\n * Scaffolder plugin\n *\n * @alpha\n */\nexport const scaffolderPlugin = createBackendPlugin({\n pluginId: 'scaffolder',\n register(env) {\n const addedActions = new Array<TemplateAction<any, any>>();\n env.registerExtensionPoint(scaffolderActionsExtensionPoint, {\n addActions(...newActions: TemplateAction<any>[]) {\n addedActions.push(...newActions);\n },\n });\n\n let taskBroker: TaskBroker | undefined;\n env.registerExtensionPoint(scaffolderTaskBrokerExtensionPoint, {\n setTaskBroker(newTaskBroker) {\n if (taskBroker) {\n throw new Error('Task broker may only be set once');\n }\n taskBroker = newTaskBroker;\n },\n });\n\n const additionalTemplateFilters: Record<string, TemplateFilter> = {};\n const additionalTemplateGlobals: Record<string, TemplateGlobal> = {};\n env.registerExtensionPoint(scaffolderTemplatingExtensionPoint, {\n addTemplateFilters(newFilters) {\n Object.assign(additionalTemplateFilters, newFilters);\n },\n addTemplateGlobals(newGlobals) {\n Object.assign(additionalTemplateGlobals, newGlobals);\n },\n });\n\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n lifecycle: coreServices.rootLifecycle,\n reader: coreServices.urlReader,\n permissions: coreServices.permissions,\n database: coreServices.database,\n auth: coreServices.auth,\n discovery: coreServices.discovery,\n httpRouter: coreServices.httpRouter,\n httpAuth: coreServices.httpAuth,\n catalogClient: catalogServiceRef,\n },\n async init({\n logger,\n config,\n lifecycle,\n reader,\n database,\n auth,\n discovery,\n httpRouter,\n httpAuth,\n catalogClient,\n permissions,\n }) {\n const log = loggerToWinstonLogger(logger);\n const integrations = ScmIntegrations.fromConfig(config);\n\n const actions = [\n // actions provided from other modules\n ...addedActions,\n\n // built-in actions for the scaffolder\n createFetchPlainAction({\n reader,\n integrations,\n }),\n createFetchPlainFileAction({\n reader,\n integrations,\n }),\n createFetchTemplateAction({\n integrations,\n reader,\n additionalTemplateFilters,\n additionalTemplateGlobals,\n }),\n createDebugLogAction(),\n createWaitAction(),\n // todo(blam): maybe these should be a -catalog module?\n createCatalogRegisterAction({ catalogClient, integrations, auth }),\n createFetchCatalogEntityAction({ catalogClient, auth }),\n createCatalogWriteAction(),\n createFilesystemDeleteAction(),\n createFilesystemRenameAction(),\n ];\n\n const actionIds = actions.map(action => action.id).join(', ');\n\n log.info(\n `Starting scaffolder with the following actions enabled ${actionIds}`,\n );\n\n const router = await createRouter({\n logger: log,\n config,\n database,\n catalogClient,\n reader,\n lifecycle,\n actions,\n taskBroker,\n additionalTemplateFilters,\n additionalTemplateGlobals,\n auth,\n httpAuth,\n discovery,\n permissions,\n });\n httpRouter.use(router);\n },\n });\n },\n});\n"],"names":["createConditionExports","RESOURCE_TYPE_SCAFFOLDER_TEMPLATE","scaffolderTemplateRules","RESOURCE_TYPE_SCAFFOLDER_ACTION","scaffolderActionRules","createBackendPlugin","scaffolderActionsExtensionPoint","scaffolderTaskBrokerExtensionPoint","scaffolderTemplatingExtensionPoint","coreServices","catalogServiceRef","loggerToWinstonLogger","ScmIntegrations","createFetchPlainAction","createFetchPlainFileAction","createFetchTemplateAction","createDebugLogAction","createWaitAction","createCatalogRegisterAction","createFetchCatalogEntityAction","createCatalogWriteAction","createFilesystemDeleteAction","createFilesystemRenameAction","router","createRouter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,2BAA2BA,2CAAuB,CAAA;AAAA,EACtD,QAAU,EAAA,YAAA;AAAA,EACV,YAAc,EAAAC,uCAAA;AAAA,EACd,KAAO,EAAAC,8BAAA;AACT,CAAC,CAAA,CAAA;AAED,MAAM,0BAA0BF,2CAAuB,CAAA;AAAA,EACrD,QAAU,EAAA,YAAA;AAAA,EACV,YAAc,EAAAG,qCAAA;AAAA,EACd,KAAO,EAAAC,4BAAA;AACT,CAAC,CAAA,CAAA;AAkCM,MAAM,8CACX,wBAAyB,CAAA,0BAAA;AAQpB,MAAM,+BAA+B,wBAAyB,CAAA,WAAA;AAK9D,MAAM,4CACX,uBAAwB,CAAA,0BAAA;AASnB,MAAM,6BAA6B,uBAAwB,CAAA;;ACtC3D,MAAM,mBAAmBC,oCAAoB,CAAA;AAAA,EAClD,QAAU,EAAA,YAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAM,MAAA,YAAA,GAAe,IAAI,KAAgC,EAAA,CAAA;AACzD,IAAA,GAAA,CAAI,uBAAuBC,uCAAiC,EAAA;AAAA,MAC1D,cAAc,UAAmC,EAAA;AAC/C,QAAa,YAAA,CAAA,IAAA,CAAK,GAAG,UAAU,CAAA,CAAA;AAAA,OACjC;AAAA,KACD,CAAA,CAAA;AAED,IAAI,IAAA,UAAA,CAAA;AACJ,IAAA,GAA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AAAA,UACA,UAAA;AAAA,UACA,yBAAA;AAAA,UACA,yBAAA;AAAA,UACA,IAAA;AAAA,UACA,QAAA;AAAA,UACA,SAAA;AAAA,UACA,WAAA;AAAA,SACD,CAAA,CAAA;AACD,QAAA,UAAA,CAAW,IAAID,QAAM,CAAA,CAAA;AAAA,OACvB;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;;;;"}
@@ -14,6 +14,7 @@ var zod = require('zod');
14
14
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
15
15
  var yaml = require('yaml');
16
16
  var fs = require('fs-extra');
17
+ var backendPluginApi = require('@backstage/backend-plugin-api');
17
18
  var path = require('path');
18
19
  var luxon = require('luxon');
19
20
  var globby = require('globby');
@@ -29,12 +30,15 @@ var gerrit = require('@backstage/plugin-scaffolder-backend-module-gerrit');
29
30
  var gitlab = require('@backstage/plugin-scaffolder-backend-module-gitlab');
30
31
  var pluginScaffolderBackendModuleGitea = require('@backstage/plugin-scaffolder-backend-module-gitea');
31
32
  var uuid = require('uuid');
33
+ var tar = require('tar');
34
+ var concatStream = require('concat-stream');
35
+ var util = require('util');
36
+ var stream = require('stream');
32
37
  var ObservableImpl = require('zen-observable');
33
38
  var lodash = require('lodash');
34
39
  var PQueue = require('p-queue');
35
40
  var winston = require('winston');
36
41
  var nunjucks = require('nunjucks');
37
- var stream = require('stream');
38
42
  var pluginPermissionNode = require('@backstage/plugin-permission-node');
39
43
  var promClient = require('prom-client');
40
44
  var pluginPermissionCommon = require('@backstage/plugin-permission-common');
@@ -69,6 +73,8 @@ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
69
73
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
70
74
  var globby__default = /*#__PURE__*/_interopDefaultCompat(globby);
71
75
  var get__default = /*#__PURE__*/_interopDefaultCompat(get);
76
+ var tar__default = /*#__PURE__*/_interopDefaultCompat(tar);
77
+ var concatStream__default = /*#__PURE__*/_interopDefaultCompat(concatStream);
72
78
  var ObservableImpl__default = /*#__PURE__*/_interopDefaultCompat(ObservableImpl);
73
79
  var PQueue__default = /*#__PURE__*/_interopDefaultCompat(PQueue);
74
80
  var winston__namespace = /*#__PURE__*/_interopNamespaceCompat(winston);
@@ -281,7 +287,7 @@ function createCatalogWriteAction() {
281
287
  const entityRef = (_a = ctx.templateInfo) == null ? void 0 : _a.entityRef;
282
288
  const path = filePath != null ? filePath : "catalog-info.yaml";
283
289
  await fs__default.default.writeFile(
284
- backendCommon.resolveSafeChildPath(ctx.workspacePath, path),
290
+ backendPluginApi.resolveSafeChildPath(ctx.workspacePath, path),
285
291
  yaml__namespace.stringify({
286
292
  ...entity,
287
293
  metadata: {
@@ -679,7 +685,7 @@ function createFetchPlainAction(options) {
679
685
  var _a, _b;
680
686
  ctx.logger.info("Fetching plain content from remote URL");
681
687
  const targetPath = (_a = ctx.input.targetPath) != null ? _a : "./";
682
- const outputPath = backendCommon.resolveSafeChildPath(ctx.workspacePath, targetPath);
688
+ const outputPath = backendPluginApi.resolveSafeChildPath(ctx.workspacePath, targetPath);
683
689
  await pluginScaffolderNode.fetchContents({
684
690
  reader,
685
691
  integrations,
@@ -744,7 +750,7 @@ function createFetchPlainFileAction(options) {
744
750
  async handler(ctx) {
745
751
  var _a;
746
752
  ctx.logger.info("Fetching plain content from remote URL");
747
- const outputPath = backendCommon.resolveSafeChildPath(
753
+ const outputPath = backendPluginApi.resolveSafeChildPath(
748
754
  ctx.workspacePath,
749
755
  ctx.input.targetPath
750
756
  );
@@ -855,7 +861,7 @@ class SecureTemplater {
855
861
  const context = await isolate.createContext();
856
862
  const contextGlobal = context.global;
857
863
  const nunjucksSource = await fs__default.default.readFile(
858
- backendCommon.resolvePackagePath(
864
+ backendPluginApi.resolvePackagePath(
859
865
  "@backstage/plugin-scaffolder-backend",
860
866
  "assets/nunjucks.js.txt"
861
867
  ),
@@ -1040,9 +1046,9 @@ function createFetchTemplateAction(options) {
1040
1046
  var _a, _b;
1041
1047
  ctx.logger.info("Fetching template content from remote URL");
1042
1048
  const workDir = await ctx.createTemporaryDirectory();
1043
- const templateDir = backendCommon.resolveSafeChildPath(workDir, "template");
1049
+ const templateDir = backendPluginApi.resolveSafeChildPath(workDir, "template");
1044
1050
  const targetPath = (_a = ctx.input.targetPath) != null ? _a : "./";
1045
- const outputDir = backendCommon.resolveSafeChildPath(ctx.workspacePath, targetPath);
1051
+ const outputDir = backendPluginApi.resolveSafeChildPath(ctx.workspacePath, targetPath);
1046
1052
  if (ctx.input.copyWithoutRender && ctx.input.copyWithoutTemplating) {
1047
1053
  throw new errors.InputError(
1048
1054
  "Fetch action input copyWithoutRender and copyWithoutTemplating can not be used at the same time"
@@ -1142,7 +1148,7 @@ function createFetchTemplateAction(options) {
1142
1148
  if (containsSkippedContent(localOutputPath)) {
1143
1149
  continue;
1144
1150
  }
1145
- const outputPath = backendCommon.resolveSafeChildPath(outputDir, localOutputPath);
1151
+ const outputPath = backendPluginApi.resolveSafeChildPath(outputDir, localOutputPath);
1146
1152
  if (fs__default.default.existsSync(outputPath) && !ctx.input.replace) {
1147
1153
  continue;
1148
1154
  }
@@ -1157,7 +1163,7 @@ function createFetchTemplateAction(options) {
1157
1163
  );
1158
1164
  await fs__default.default.ensureDir(outputPath);
1159
1165
  } else {
1160
- const inputFilePath = backendCommon.resolveSafeChildPath(templateDir, location);
1166
+ const inputFilePath = backendPluginApi.resolveSafeChildPath(templateDir, location);
1161
1167
  const stats = await fs__default.default.promises.lstat(inputFilePath);
1162
1168
  if (stats.isSymbolicLink() || await isbinaryfile.isBinaryFile(inputFilePath)) {
1163
1169
  ctx.logger.info(
@@ -1232,7 +1238,7 @@ const createFilesystemDeleteAction = () => {
1232
1238
  throw new errors.InputError("files must be an Array");
1233
1239
  }
1234
1240
  for (const file of ctx.input.files) {
1235
- const filepath = backendCommon.resolveSafeChildPath(ctx.workspacePath, file);
1241
+ const filepath = backendPluginApi.resolveSafeChildPath(ctx.workspacePath, file);
1236
1242
  try {
1237
1243
  await fs__default.default.remove(filepath);
1238
1244
  ctx.logger.info(`File ${filepath} deleted successfully`);
@@ -1313,11 +1319,11 @@ const createFilesystemRenameAction = () => {
1313
1319
  if (!file.from || !file.to) {
1314
1320
  throw new errors.InputError("each file must have a from and to property");
1315
1321
  }
1316
- const sourceFilepath = backendCommon.resolveSafeChildPath(
1322
+ const sourceFilepath = backendPluginApi.resolveSafeChildPath(
1317
1323
  ctx.workspacePath,
1318
1324
  file.from
1319
1325
  );
1320
- const destFilepath = backendCommon.resolveSafeChildPath(ctx.workspacePath, file.to);
1326
+ const destFilepath = backendPluginApi.resolveSafeChildPath(ctx.workspacePath, file.to);
1321
1327
  try {
1322
1328
  await fs__default.default.move(sourceFilepath, destFilepath, {
1323
1329
  overwrite: (_b = file.overwrite) != null ? _b : false
@@ -1382,7 +1388,8 @@ const createBuiltinActions = (options) => {
1382
1388
  }),
1383
1389
  github.createPublishGithubPullRequestAction({
1384
1390
  integrations,
1385
- githubCredentialsProvider
1391
+ githubCredentialsProvider,
1392
+ config
1386
1393
  }),
1387
1394
  gitlab.createPublishGitlabAction({
1388
1395
  integrations,
@@ -1462,7 +1469,7 @@ const createBuiltinActions = (options) => {
1462
1469
  var __defProp$4 = Object.defineProperty;
1463
1470
  var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1464
1471
  var __publicField$4 = (obj, key, value) => {
1465
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1472
+ __defNormalProp$4(obj, key + "" , value);
1466
1473
  return value;
1467
1474
  };
1468
1475
  class TemplateActionRegistry {
@@ -1521,13 +1528,30 @@ const intervalFromNowTill = (timeoutS, knex) => {
1521
1528
  return heartbeatInterval;
1522
1529
  };
1523
1530
 
1531
+ const pipeline = util.promisify(stream.pipeline);
1532
+ const serializeWorkspace = async (path) => {
1533
+ return await new Promise(async (resolve) => {
1534
+ await pipeline(tar__default.default.create({ cwd: path }, [""]), concatStream__default.default(resolve));
1535
+ });
1536
+ };
1537
+ const restoreWorkspace = async (path, buffer) => {
1538
+ if (buffer) {
1539
+ await pipeline(
1540
+ stream.Readable.from(buffer),
1541
+ tar__default.default.extract({
1542
+ C: path
1543
+ })
1544
+ );
1545
+ }
1546
+ };
1547
+
1524
1548
  var __defProp$3 = Object.defineProperty;
1525
1549
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1526
1550
  var __publicField$3 = (obj, key, value) => {
1527
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
1551
+ __defNormalProp$3(obj, key + "" , value);
1528
1552
  return value;
1529
1553
  };
1530
- const migrationsDir = backendCommon.resolvePackagePath(
1554
+ const migrationsDir = backendPluginApi.resolvePackagePath(
1531
1555
  "@backstage/plugin-scaffolder-backend",
1532
1556
  "migrations"
1533
1557
  );
@@ -1844,6 +1868,22 @@ class DatabaseTaskStore {
1844
1868
  }
1845
1869
  });
1846
1870
  }
1871
+ async rehydrateWorkspace(options) {
1872
+ const [result] = await this.db("tasks").where({ id: options.taskId }).select("workspace");
1873
+ await restoreWorkspace(options.targetPath, result.workspace);
1874
+ }
1875
+ async cleanWorkspace({ taskId }) {
1876
+ await this.db("tasks").where({ id: taskId }).update({
1877
+ workspace: void 0
1878
+ });
1879
+ }
1880
+ async serializeWorkspace(options) {
1881
+ if (options.path) {
1882
+ await this.db("tasks").where({ id: options.taskId }).update({
1883
+ workspace: await serializeWorkspace(options.path)
1884
+ });
1885
+ }
1886
+ }
1847
1887
  async cancelTask(options) {
1848
1888
  const { taskId, body } = options;
1849
1889
  const serializedBody = JSON.stringify(body);
@@ -1928,17 +1968,25 @@ var __publicField$2 = (obj, key, value) => {
1928
1968
  };
1929
1969
  class TaskManager {
1930
1970
  // Runs heartbeat internally
1931
- constructor(task, storage, signal, logger, auth) {
1971
+ constructor(task, storage, signal, logger, auth, config) {
1932
1972
  this.task = task;
1933
1973
  this.storage = storage;
1934
1974
  this.signal = signal;
1935
1975
  this.logger = logger;
1936
1976
  this.auth = auth;
1977
+ this.config = config;
1937
1978
  __publicField$2(this, "isDone", false);
1938
1979
  __publicField$2(this, "heartbeatTimeoutId");
1939
1980
  }
1940
- static create(task, storage, abortSignal, logger, auth) {
1941
- const agent = new TaskManager(task, storage, abortSignal, logger, auth);
1981
+ static create(task, storage, abortSignal, logger, auth, config) {
1982
+ const agent = new TaskManager(
1983
+ task,
1984
+ storage,
1985
+ abortSignal,
1986
+ logger,
1987
+ auth,
1988
+ config
1989
+ );
1942
1990
  agent.startTimeout();
1943
1991
  return agent;
1944
1992
  }
@@ -1957,6 +2005,12 @@ class TaskManager {
1957
2005
  async getWorkspaceName() {
1958
2006
  return this.task.taskId;
1959
2007
  }
2008
+ async rehydrateWorkspace(options) {
2009
+ var _a, _b;
2010
+ if (this.isWorkspaceSerializationEnabled()) {
2011
+ (_b = (_a = this.storage).rehydrateWorkspace) == null ? void 0 : _b.call(_a, options);
2012
+ }
2013
+ }
1960
2014
  get done() {
1961
2015
  return this.isDone;
1962
2016
  }
@@ -1983,6 +2037,21 @@ class TaskManager {
1983
2037
  state: this.task.state
1984
2038
  }));
1985
2039
  }
2040
+ async serializeWorkspace(options) {
2041
+ var _a, _b;
2042
+ if (this.isWorkspaceSerializationEnabled()) {
2043
+ await ((_b = (_a = this.storage).serializeWorkspace) == null ? void 0 : _b.call(_a, {
2044
+ path: options.path,
2045
+ taskId: this.task.taskId
2046
+ }));
2047
+ }
2048
+ }
2049
+ async cleanWorkspace() {
2050
+ var _a, _b;
2051
+ if (this.isWorkspaceSerializationEnabled()) {
2052
+ await ((_b = (_a = this.storage).cleanWorkspace) == null ? void 0 : _b.call(_a, { taskId: this.task.taskId }));
2053
+ }
2054
+ }
1986
2055
  async complete(result, metadata) {
1987
2056
  await this.storage.completeTask({
1988
2057
  taskId: this.task.taskId,
@@ -2011,6 +2080,12 @@ class TaskManager {
2011
2080
  }
2012
2081
  }, 1e3);
2013
2082
  }
2083
+ isWorkspaceSerializationEnabled() {
2084
+ var _a, _b;
2085
+ return (_b = (_a = this.config) == null ? void 0 : _a.getOptionalBoolean(
2086
+ "scaffolder.EXPERIMENTAL_workspaceSerialization"
2087
+ )) != null ? _b : false;
2088
+ }
2014
2089
  async getInitiatorCredentials() {
2015
2090
  const secrets = this.task.secrets;
2016
2091
  if (secrets && secrets.__initiatorCredentials) {
@@ -2110,7 +2185,8 @@ class StorageTaskBroker {
2110
2185
  this.storage,
2111
2186
  abortController.signal,
2112
2187
  this.logger,
2113
- this.auth
2188
+ this.auth,
2189
+ this.config
2114
2190
  );
2115
2191
  }
2116
2192
  await this.waitForDispatch();
@@ -2303,7 +2379,7 @@ var __accessCheck = (obj, member, msg) => {
2303
2379
  };
2304
2380
  var __privateGet = (obj, member, getter) => {
2305
2381
  __accessCheck(obj, member, "read from private field");
2306
- return getter ? getter.call(obj) : member.get(obj);
2382
+ return member.get(obj);
2307
2383
  };
2308
2384
  var __privateAdd = (obj, member, value) => {
2309
2385
  if (member.has(obj))
@@ -2312,7 +2388,7 @@ var __privateAdd = (obj, member, value) => {
2312
2388
  };
2313
2389
  var __privateSet = (obj, member, value, setter) => {
2314
2390
  __accessCheck(obj, member, "write to private field");
2315
- setter ? setter.call(obj, value) : member.set(obj, value);
2391
+ member.set(obj, value);
2316
2392
  return value;
2317
2393
  };
2318
2394
  var _winston, _addRedactions;
@@ -2568,7 +2644,7 @@ class NunjucksWorkflowRunner {
2568
2644
  });
2569
2645
  }
2570
2646
  async executeStep(task, step, context, renderTemplate, taskTrack, workspacePath, decision) {
2571
- var _a, _b, _c, _d, _e, _f;
2647
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2572
2648
  const stepTrack = await this.tracker.stepStart(task, step);
2573
2649
  if (task.cancelSignal.aborted) {
2574
2650
  throw new Error(`Step ${step.name} has been cancelled.`);
@@ -2686,7 +2762,7 @@ class NunjucksWorkflowRunner {
2686
2762
  logStream: streamLogger,
2687
2763
  workspacePath,
2688
2764
  async checkpoint(keySuffix, fn) {
2689
- var _a2, _b2, _c2, _d2;
2765
+ var _a2, _b2, _c2, _d2, _e2;
2690
2766
  const key = `v1.task.checkpoint.${keySuffix}`;
2691
2767
  try {
2692
2768
  let prevValue;
@@ -2712,6 +2788,8 @@ class NunjucksWorkflowRunner {
2712
2788
  reason: errors.stringifyError(err)
2713
2789
  });
2714
2790
  throw err;
2791
+ } finally {
2792
+ await ((_e2 = task.serializeWorkspace) == null ? void 0 : _e2.call(task, { path: workspacePath }));
2715
2793
  }
2716
2794
  },
2717
2795
  createTemporaryDirectory: async () => {
@@ -2743,23 +2821,25 @@ class NunjucksWorkflowRunner {
2743
2821
  if (task.cancelSignal.aborted) {
2744
2822
  throw new Error(`Step ${step.name} has been cancelled.`);
2745
2823
  }
2824
+ await ((_g = task.cleanWorkspace) == null ? void 0 : _g.call(task));
2746
2825
  await stepTrack.markSuccessful();
2747
2826
  } catch (err) {
2748
2827
  await taskTrack.markFailed(step, err);
2749
2828
  await stepTrack.markFailed();
2750
2829
  throw err;
2830
+ } finally {
2831
+ await ((_h = task.serializeWorkspace) == null ? void 0 : _h.call(task, { path: workspacePath }));
2751
2832
  }
2752
2833
  }
2753
2834
  async execute(task) {
2835
+ var _a;
2754
2836
  if (!isValidTaskSpec(task.spec)) {
2755
2837
  throw new errors.InputError(
2756
2838
  "Wrong template version executed with the workflow engine"
2757
2839
  );
2758
2840
  }
2759
- const workspacePath = path__default.default.join(
2760
- this.options.workingDirectory,
2761
- await task.getWorkspaceName()
2762
- );
2841
+ const taskId = await task.getWorkspaceName();
2842
+ const workspacePath = path__default.default.join(this.options.workingDirectory, taskId);
2763
2843
  const { additionalTemplateFilters, additionalTemplateGlobals } = this.options;
2764
2844
  const renderTemplate = await SecureTemplater.loadRenderer({
2765
2845
  templateFilters: {
@@ -2769,6 +2849,7 @@ class NunjucksWorkflowRunner {
2769
2849
  templateGlobals: additionalTemplateGlobals
2770
2850
  });
2771
2851
  try {
2852
+ await ((_a = task.rehydrateWorkspace) == null ? void 0 : _a.call(task, { taskId, targetPath: workspacePath }));
2772
2853
  const taskTrack = await this.tracker.taskStart(task);
2773
2854
  await fs__default.default.ensureDir(workspacePath);
2774
2855
  const context = {
@@ -3075,7 +3156,7 @@ function createDryRunner(options) {
3075
3156
  });
3076
3157
  const dryRunId = uuid.v4();
3077
3158
  const log = new Array();
3078
- const contentsPath = backendCommon.resolveSafeChildPath(
3159
+ const contentsPath = backendPluginApi.resolveSafeChildPath(
3079
3160
  options.workingDirectory,
3080
3161
  `dry-run-content-${dryRunId}`
3081
3162
  );
@@ -3096,7 +3177,7 @@ function createDryRunner(options) {
3096
3177
  templateInfo: {
3097
3178
  entityRef: "template:default/dry-run",
3098
3179
  baseUrl: url.pathToFileURL(
3099
- backendCommon.resolveSafeChildPath(contentsPath, "template.yaml")
3180
+ backendPluginApi.resolveSafeChildPath(contentsPath, "template.yaml")
3100
3181
  ).toString()
3101
3182
  }
3102
3183
  },
@@ -3701,4 +3782,4 @@ exports.createRouter = createRouter;
3701
3782
  exports.createWaitAction = createWaitAction;
3702
3783
  exports.scaffolderActionRules = scaffolderActionRules;
3703
3784
  exports.scaffolderTemplateRules = scaffolderTemplateRules;
3704
- //# sourceMappingURL=router-CDFi_apW.cjs.js.map
3785
+ //# sourceMappingURL=router-BKGs_U4O.cjs.js.map