@backstage/plugin-scaffolder-backend 0.0.0-nightly-20220217022146 → 0.0.0-nightly-20220221022454

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,6 +1,64 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
- ## 0.0.0-nightly-20220217022146
3
+ ## 0.0.0-nightly-20220221022454
4
+
5
+ ### Minor Changes
6
+
7
+ - 7f193ff019: - **BREAKING** - `DatabaseTaskStore()` constructor is now removed. Please use the `DatabaseTaskStore.create()` method instead.
8
+
9
+ - **BREAKING** - `TaskStore.createTask()` method now only takes one argument of type `TaskStoreCreateTaskOptions` which encapsulates the `spec` and `secrets`
10
+
11
+ ```diff
12
+ - TaskStore.createTask(spec, secrets)
13
+ + TaskStore.createTask({ spec, secrets})
14
+ ```
15
+
16
+ - **BREAKING** - `TaskBroker.dispatch()` method now only takes one argument of type `TaskBrokerDispatchOptions` which encapsulates the `spec` and `secrets`
17
+
18
+ ```diff
19
+ - TaskBroker.dispatch(spec, secrets)
20
+ + TaskBroker.dispatch({ spec, secrets})
21
+ ```
22
+
23
+ ### Patch Changes
24
+
25
+ - 6981ac4ad2: - **DEPRECATED** - The `containerRunner` option passed to `createBuiltinActions` has now been deprecated.
26
+
27
+ - **DEPRECATED** - The `createFetchCookiecutterAction` export has also been deprecated and will soon disappear from this plugin.
28
+
29
+ The `fetch:cookiecutter` action will soon be removed from the default list of actions that are provided out of the box from the scaffolder plugin. It will still be supported, and maintained by the community, so you can install the package (`@backstage/plugin-scaffolder-backend-module-cookiecutter`) and pass it in as a custom action. Or you can migrate your templates to use [`fetch:template`](https://backstage.io/docs/features/software-templates/builtin-actions#migrating-from-fetchcookiecutter-to-fetchtemplate) with the `cookiecutterCompat` option.
30
+
31
+ - 0f37cdef19: Migrated over from the deprecated `spec.metadata` to `spec.templateInfo` for the `name` and the `baseUrl` of the template.
32
+ - 7f193ff019: - **DEPRECATED** - `Status` has been deprecated in favour of `TaskStatus`
33
+ - **DEPRECATED** - `CompletedTaskState` has been deprecated in favour of `TaskCompletionState`
34
+ - **DEPRECATED** - `DispatchResult` has been deprecated in favour of `TaskBrokerDispatchResult`
35
+ - df61ca71dd: Implemented required `getProcessorName` method for catalog processor.
36
+ - Updated dependencies
37
+ - @backstage/plugin-catalog-backend@0.0.0-nightly-20220221022454
38
+ - @backstage/plugin-scaffolder-common@0.0.0-nightly-20220221022454
39
+ - @backstage/catalog-model@0.0.0-nightly-20220221022454
40
+ - @backstage/plugin-scaffolder-backend-module-cookiecutter@0.0.0-nightly-20220221022454
41
+ - @backstage/integration@0.0.0-nightly-20220221022454
42
+ - @backstage/catalog-client@0.0.0-nightly-20220221022454
43
+
44
+ ## 0.16.1
45
+
46
+ ### Patch Changes
47
+
48
+ - Fix for the previous release with missing type declarations.
49
+ - Updated dependencies
50
+ - @backstage/backend-common@0.10.9
51
+ - @backstage/catalog-client@0.7.1
52
+ - @backstage/catalog-model@0.10.1
53
+ - @backstage/config@0.1.15
54
+ - @backstage/errors@0.2.2
55
+ - @backstage/integration@0.7.4
56
+ - @backstage/types@0.1.3
57
+ - @backstage/plugin-catalog-backend@0.21.5
58
+ - @backstage/plugin-scaffolder-backend-module-cookiecutter@0.2.1
59
+ - @backstage/plugin-scaffolder-common@0.2.1
60
+
61
+ ## 0.16.0
4
62
 
5
63
  ### Minor Changes
6
64
 
@@ -23,16 +81,16 @@
23
81
  - 1433045c08: Removed unused `helmet` dependency.
24
82
  - 27eccab216: Replaces use of deprecated catalog-model constants.
25
83
  - Updated dependencies
26
- - @backstage/plugin-scaffolder-common@0.0.0-nightly-20220217022146
27
- - @backstage/plugin-catalog-backend@0.0.0-nightly-20220217022146
28
- - @backstage/backend-common@0.0.0-nightly-20220217022146
29
- - @backstage/catalog-client@0.0.0-nightly-20220217022146
30
- - @backstage/errors@0.0.0-nightly-20220217022146
31
- - @backstage/integration@0.0.0-nightly-20220217022146
32
- - @backstage/catalog-model@0.0.0-nightly-20220217022146
33
- - @backstage/config@0.0.0-nightly-20220217022146
34
- - @backstage/types@0.0.0-nightly-20220217022146
35
- - @backstage/plugin-scaffolder-backend-module-cookiecutter@0.0.0-nightly-20220217022146
84
+ - @backstage/plugin-scaffolder-common@0.2.0
85
+ - @backstage/plugin-catalog-backend@0.21.4
86
+ - @backstage/backend-common@0.10.8
87
+ - @backstage/catalog-client@0.7.0
88
+ - @backstage/errors@0.2.1
89
+ - @backstage/integration@0.7.3
90
+ - @backstage/catalog-model@0.10.0
91
+ - @backstage/config@0.1.14
92
+ - @backstage/types@0.1.2
93
+ - @backstage/plugin-scaffolder-backend-module-cookiecutter@0.2.0
36
94
 
37
95
  ## 0.15.24
38
96
 
package/dist/index.cjs.js CHANGED
@@ -250,9 +250,6 @@ async function fetchContents({
250
250
  fetchUrl = ".",
251
251
  outputPath
252
252
  }) {
253
- if (typeof fetchUrl !== "string") {
254
- throw new errors.InputError(`Invalid url parameter, expected string, got ${typeof fetchUrl}`);
255
- }
256
253
  let fetchUrlIsAbsolute = false;
257
254
  try {
258
255
  new URL(fetchUrl);
@@ -309,14 +306,14 @@ function createFetchPlainAction(options) {
309
306
  }
310
307
  },
311
308
  async handler(ctx) {
312
- var _a;
309
+ var _a, _b;
313
310
  ctx.logger.info("Fetching plain content from remote URL");
314
311
  const targetPath = (_a = ctx.input.targetPath) != null ? _a : "./";
315
312
  const outputPath = backendCommon.resolveSafeChildPath(ctx.workspacePath, targetPath);
316
313
  await fetchContents({
317
314
  reader,
318
315
  integrations,
319
- baseUrl: ctx.baseUrl,
316
+ baseUrl: (_b = ctx.templateInfo) == null ? void 0 : _b.baseUrl,
320
317
  fetchUrl: ctx.input.url,
321
318
  outputPath
322
319
  });
@@ -475,7 +472,7 @@ function createFetchTemplateAction(options) {
475
472
  }
476
473
  },
477
474
  async handler(ctx) {
478
- var _a;
475
+ var _a, _b;
479
476
  ctx.logger.info("Fetching template content from remote URL");
480
477
  const workDir = await ctx.createTemporaryDirectory();
481
478
  const templateDir = backendCommon.resolveSafeChildPath(workDir, "template");
@@ -497,7 +494,7 @@ function createFetchTemplateAction(options) {
497
494
  await fetchContents({
498
495
  reader,
499
496
  integrations,
500
- baseUrl: ctx.baseUrl,
497
+ baseUrl: (_b = ctx.templateInfo) == null ? void 0 : _b.baseUrl,
501
498
  fetchUrl: ctx.input.url,
502
499
  outputPath: templateDir
503
500
  });
@@ -2054,6 +2051,9 @@ const createBuiltinActions = (options) => {
2054
2051
  })
2055
2052
  ];
2056
2053
  if (containerRunner) {
2054
+ backendCommon.getRootLogger().warn(`[DEPRECATED] The fetch:cookiecutter action will be removed part of the default scaffolder actions in later versions.
2055
+ You can install the package seperately and remove the containerRunner from the createBuiltInActions to remove this warning,
2056
+ or you can migrate to using fetch:template https://backstage.io/docs/features/software-templates/builtin-actions#migrating-from-fetchcookiecutter-to-fetchtemplate`);
2057
2057
  actions.push(pluginScaffolderBackendModuleCookiecutter.createFetchCookiecutterAction({
2058
2058
  reader,
2059
2059
  integrations,
@@ -2116,12 +2116,12 @@ class DatabaseTaskStore {
2116
2116
  throw new Error(`Failed to parse spec of task '${taskId}', ${error}`);
2117
2117
  }
2118
2118
  }
2119
- async createTask(spec, secrets) {
2119
+ async createTask(options) {
2120
2120
  const taskId = uuid.v4();
2121
2121
  await this.db("tasks").insert({
2122
2122
  id: taskId,
2123
- spec: JSON.stringify(spec),
2124
- secrets: secrets ? JSON.stringify(secrets) : void 0,
2123
+ spec: JSON.stringify(options.spec),
2124
+ secrets: options.secrets ? JSON.stringify(options.secrets) : void 0,
2125
2125
  status: "open"
2126
2126
  });
2127
2127
  return { taskId };
@@ -2333,8 +2333,8 @@ class StorageTaskBroker {
2333
2333
  await this.waitForDispatch();
2334
2334
  }
2335
2335
  }
2336
- async dispatch(spec, secrets) {
2337
- const taskRow = await this.storage.createTask(spec, secrets);
2336
+ async dispatch(options) {
2337
+ const taskRow = await this.storage.createTask(options);
2338
2338
  this.signalDispatch();
2339
2339
  return {
2340
2340
  taskId: taskRow.taskId
@@ -2368,8 +2368,8 @@ class StorageTaskBroker {
2368
2368
  })();
2369
2369
  return { unsubscribe };
2370
2370
  }
2371
- async vacuumTasks(timeoutS) {
2372
- const { tasks } = await this.storage.listStaleTasks(timeoutS);
2371
+ async vacuumTasks(options) {
2372
+ const { tasks } = await this.storage.listStaleTasks(options);
2373
2373
  await Promise.all(tasks.map(async (task) => {
2374
2374
  try {
2375
2375
  await this.storage.completeTask({
@@ -2509,9 +2509,6 @@ class HandlebarsWorkflowRunner {
2509
2509
  this.options.logger.debug(`Running ${action.id} with input`, {
2510
2510
  input: JSON.stringify(input, null, 2)
2511
2511
  });
2512
- if (!task.spec.metadata) {
2513
- console.warn("DEPRECATION NOTICE: metadata is undefined. metadata will be required in the future.");
2514
- }
2515
2512
  await action.handler({
2516
2513
  baseUrl: task.spec.baseUrl,
2517
2514
  logger: taskLogger,
@@ -2527,7 +2524,8 @@ class HandlebarsWorkflowRunner {
2527
2524
  output(name, value) {
2528
2525
  stepOutputs[name] = value;
2529
2526
  },
2530
- metadata: task.spec.metadata
2527
+ metadata: task.spec.metadata,
2528
+ templateInfo: task.spec.templateInfo
2531
2529
  });
2532
2530
  for (const tmpDir of tmpDirs) {
2533
2531
  await fs__default["default"].remove(tmpDir);
@@ -2702,7 +2700,8 @@ class NunjucksWorkflowRunner {
2702
2700
  output(name, value) {
2703
2701
  stepOutput[name] = value;
2704
2702
  },
2705
- metadata: task.spec.metadata
2703
+ metadata: task.spec.metadata,
2704
+ templateInfo: task.spec.templateInfo
2706
2705
  });
2707
2706
  for (const tmpDir of tmpDirs) {
2708
2707
  await fs__default["default"].remove(tmpDir);
@@ -2934,14 +2933,17 @@ async function createRouter(options) {
2934
2933
  });
2935
2934
  res.json(actionsList);
2936
2935
  }).post("/v2/tasks", async (req, res) => {
2937
- var _a, _b, _c, _d, _e;
2936
+ var _a, _b, _c, _d;
2938
2937
  const templateName = req.body.templateName;
2938
+ const { kind, namespace } = { kind: "template", namespace: "default" };
2939
2939
  const values = req.body.values;
2940
2940
  const token = getBearerToken(req.headers.authorization);
2941
2941
  const template = await findTemplate({
2942
2942
  catalogApi: catalogClient,
2943
2943
  entityRef: {
2944
- name: templateName
2944
+ name: templateName,
2945
+ kind,
2946
+ namespace
2945
2947
  },
2946
2948
  token: getBearerToken(req.headers.authorization)
2947
2949
  });
@@ -2958,10 +2960,8 @@ async function createRouter(options) {
2958
2960
  }
2959
2961
  }
2960
2962
  const baseUrl = getEntityBaseUrl(template);
2961
- taskSpec = template.apiVersion === "backstage.io/v1beta2" ? {
2962
- apiVersion: template.apiVersion,
2963
+ const baseTaskSpec = {
2963
2964
  baseUrl,
2964
- values,
2965
2965
  steps: template.spec.steps.map((step, index) => {
2966
2966
  var _a2, _b2;
2967
2967
  return {
@@ -2971,29 +2971,34 @@ async function createRouter(options) {
2971
2971
  };
2972
2972
  }),
2973
2973
  output: (_b = template.spec.output) != null ? _b : {},
2974
- metadata: { name: (_c = template.metadata) == null ? void 0 : _c.name }
2974
+ metadata: { name: (_c = template.metadata) == null ? void 0 : _c.name },
2975
+ templateInfo: {
2976
+ entityRef: catalogModel.stringifyEntityRef({
2977
+ kind,
2978
+ namespace,
2979
+ name: (_d = template.metadata) == null ? void 0 : _d.name
2980
+ }),
2981
+ baseUrl
2982
+ }
2983
+ };
2984
+ taskSpec = template.apiVersion === "backstage.io/v1beta2" ? {
2985
+ ...baseTaskSpec,
2986
+ apiVersion: template.apiVersion,
2987
+ values
2975
2988
  } : {
2989
+ ...baseTaskSpec,
2976
2990
  apiVersion: template.apiVersion,
2977
- baseUrl,
2978
- parameters: values,
2979
- steps: template.spec.steps.map((step, index) => {
2980
- var _a2, _b2;
2981
- return {
2982
- ...step,
2983
- id: (_a2 = step.id) != null ? _a2 : `step-${index + 1}`,
2984
- name: (_b2 = step.name) != null ? _b2 : step.action
2985
- };
2986
- }),
2987
- output: (_d = template.spec.output) != null ? _d : {},
2988
- metadata: { name: (_e = template.metadata) == null ? void 0 : _e.name }
2991
+ parameters: values
2989
2992
  };
2990
2993
  } else {
2991
2994
  throw new errors.InputError(`Unsupported apiVersion field in schema entity, ${template.apiVersion}`);
2992
2995
  }
2993
- const result = await taskBroker.dispatch(taskSpec, {
2994
- ...req.body.secrets,
2995
- backstageToken: token,
2996
- token
2996
+ const result = await taskBroker.dispatch({
2997
+ spec: taskSpec,
2998
+ secrets: {
2999
+ ...req.body.secrets,
3000
+ backstageToken: token
3001
+ }
2997
3002
  });
2998
3003
  res.status(201).json({ id: result.taskId });
2999
3004
  }).get("/v2/tasks/:taskId", async (req, res) => {
@@ -3072,6 +3077,9 @@ class ScaffolderEntitiesProcessor {
3072
3077
  constructor() {
3073
3078
  this.validators = [pluginScaffolderCommon.templateEntityV1beta3Validator];
3074
3079
  }
3080
+ getProcessorName() {
3081
+ return "ScaffolderEntitiesProcessor";
3082
+ }
3075
3083
  async validateEntityKind(entity) {
3076
3084
  for (const validator of this.validators) {
3077
3085
  if (await validator.check(entity)) {