@backstage/plugin-scaffolder-backend 1.15.0-next.3 → 1.15.0

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,5 +1,48 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
+ ## 1.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 84b0e47373db: Add `TargetBranchName` variable and output for the `publish:gitlab:merge-request` and `publish:github:pull-request` s'cascaffolder actions.
8
+ - 6a694ce98e32: Add a scaffolder action that pull-requests for bitbucket server
9
+ - 1948845861b0: Added `github:deployKey:create` and `github:environment:create` scaffolder actions. You will need to add `read/write` permissions to your GITHUB_TOKEN and/or Github Backstage App for Repository `Administration` (for deploy key functionality) and `Environments` (for Environment functionality)
10
+ - df8411779da1: Add support for Repository Variables and Secrets to the `publish:github` and `github:repo:create` scaffolder actions. You will need to add `read/write` permissions to your GITHUB_TOKEN and/or Github Backstage App for Repository `Secrets` and `Variables`
11
+
12
+ Upgrade octokit introduces some breaking changes.
13
+
14
+ ### Patch Changes
15
+
16
+ - cc936b529676: Fix handling of `optional` property in `catalog:register` scaffolder action
17
+ - b269da39ac2d: Clearer error messages for action `publish:gitlab:merge-request`
18
+ - 11e0f625583f: Fix wrong gitlabUrl format in repoUrl input description
19
+ - a2c70cdda202: Switch out the sandbox, from `vm2` to `isolated-vm`.
20
+
21
+ This is a native dependency, which means that it will need to be compiled with the same version of node on the same OS. This could cause some issues when running in Docker for instance, as you will need to make sure that the dependency is installed and compiled inside the docker container that it will run on.
22
+
23
+ This could mean adding in some dependencies to the container like `build-essential` to make sure that this compiles correctly.
24
+
25
+ If you're having issues installing this dependency, there's some [install instructions](https://github.com/laverdet/isolated-vm#requirements) over on `isolated-vm`'s repo.
26
+
27
+ - Updated dependencies
28
+ - @backstage/backend-common@0.19.0
29
+ - @backstage/catalog-client@1.4.2
30
+ - @backstage/types@1.1.0
31
+ - @backstage/plugin-catalog-backend@1.10.0
32
+ - @backstage/integration@1.5.0
33
+ - @backstage/catalog-model@1.4.0
34
+ - @backstage/errors@1.2.0
35
+ - @backstage/backend-plugin-api@0.5.3
36
+ - @backstage/backend-tasks@0.5.3
37
+ - @backstage/plugin-auth-node@0.2.15
38
+ - @backstage/plugin-catalog-node@1.3.7
39
+ - @backstage/plugin-permission-node@0.7.9
40
+ - @backstage/config@1.0.8
41
+ - @backstage/plugin-catalog-common@1.0.14
42
+ - @backstage/plugin-permission-common@0.7.6
43
+ - @backstage/plugin-scaffolder-common@1.3.1
44
+ - @backstage/plugin-scaffolder-node@0.1.4
45
+
3
46
  ## 1.15.0-next.3
4
47
 
5
48
  ### Minor Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend",
3
- "version": "1.15.0-next.3",
3
+ "version": "1.15.0",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/dist/alpha.cjs.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var backendPluginApi = require('@backstage/backend-plugin-api');
6
6
  var alpha = require('@backstage/plugin-catalog-node/alpha');
7
- var ScaffolderEntitiesProcessor = require('./cjs/ScaffolderEntitiesProcessor-8d851e94.cjs.js');
7
+ var ScaffolderEntitiesProcessor = require('./cjs/ScaffolderEntitiesProcessor-d9bc7a90.cjs.js');
8
8
  var alpha$1 = require('@backstage/plugin-scaffolder-common/alpha');
9
9
  var pluginPermissionNode = require('@backstage/plugin-permission-node');
10
10
  var backendCommon = require('@backstage/backend-common');
@@ -15,7 +15,7 @@ require('fs-extra');
15
15
  require('path');
16
16
  require('globby');
17
17
  require('isbinaryfile');
18
- require('vm2');
18
+ require('isolated-vm');
19
19
  require('@backstage/catalog-model');
20
20
  require('lodash/get');
21
21
  require('child_process');
@@ -17,7 +17,7 @@ var path = require('path');
17
17
  var luxon = require('luxon');
18
18
  var globby = require('globby');
19
19
  var isbinaryfile = require('isbinaryfile');
20
- var vm2 = require('vm2');
20
+ var isolatedVm = require('isolated-vm');
21
21
  var get = require('lodash/get');
22
22
  var octokit = require('octokit');
23
23
  var child_process = require('child_process');
@@ -738,20 +738,14 @@ const { render, renderCompat } = (() => {
738
738
  });
739
739
  compatEnv.addFilter('jsonify', compatEnv.getFilter('dump'));
740
740
 
741
- if (typeof templateFilters !== 'undefined') {
742
- for (const [filterName, filterFn] of Object.entries(templateFilters)) {
743
- env.addFilter(filterName, (...args) => JSON.parse(filterFn(...args)));
744
- }
741
+ for (const name of JSON.parse(availableTemplateFilters)) {
742
+ env.addFilter(name, (...args) => JSON.parse(callFilter(name, args)));
745
743
  }
746
-
747
- if (typeof templateGlobals !== 'undefined') {
748
- for (const [globalName, global] of Object.entries(templateGlobals)) {
749
- if (typeof global === 'function') {
750
- env.addGlobal(globalName, (...args) => JSON.parse(global(...args)));
751
- } else {
752
- env.addGlobal(globalName, JSON.parse(global));
753
- }
754
- }
744
+ for (const [name, value] of Object.entries(JSON.parse(availableTemplateGlobals))) {
745
+ env.addGlobal(name, value);
746
+ }
747
+ for (const name of JSON.parse(availableTemplateCallbacks)) {
748
+ env.addGlobal(name, (...args) => JSON.parse(callGlobal(name, args)));
755
749
  }
756
750
 
757
751
  let uninstallCompat = undefined;
@@ -786,30 +780,14 @@ const { render, renderCompat } = (() => {
786
780
  `;
787
781
  class SecureTemplater {
788
782
  static async loadRenderer(options = {}) {
789
- const { cookiecutterCompat, templateFilters, templateGlobals } = options;
790
- const sandbox = {};
791
- if (templateFilters) {
792
- sandbox.templateFilters = Object.fromEntries(
793
- Object.entries(templateFilters).filter(([_, filterFunction]) => !!filterFunction).map(([filterName, filterFunction]) => [
794
- filterName,
795
- (...args) => JSON.stringify(filterFunction(...args))
796
- ])
797
- );
798
- }
799
- if (templateGlobals) {
800
- sandbox.templateGlobals = Object.fromEntries(
801
- Object.entries(templateGlobals).filter(([_, global]) => !!global).map(([globalName, global]) => {
802
- if (typeof global === "function") {
803
- return [
804
- globalName,
805
- (...args) => JSON.stringify(global(...args))
806
- ];
807
- }
808
- return [globalName, JSON.stringify(global)];
809
- })
810
- );
811
- }
812
- const vm = new vm2.VM({ sandbox });
783
+ const {
784
+ cookiecutterCompat,
785
+ templateFilters = {},
786
+ templateGlobals = {}
787
+ } = options;
788
+ const isolate = new isolatedVm.Isolate({ memoryLimit: 128 });
789
+ const context = await isolate.createContext();
790
+ const contextGlobal = context.global;
813
791
  const nunjucksSource = await fs__default["default"].readFile(
814
792
  backendCommon.resolvePackagePath(
815
793
  "@backstage/plugin-scaffolder-backend",
@@ -817,17 +795,64 @@ class SecureTemplater {
817
795
  ),
818
796
  "utf-8"
819
797
  );
820
- vm.run(mkScript(nunjucksSource));
798
+ const nunjucksScript = await isolate.compileScript(
799
+ mkScript(nunjucksSource)
800
+ );
801
+ const availableFilters = Object.keys(templateFilters);
802
+ await contextGlobal.set(
803
+ "availableTemplateFilters",
804
+ JSON.stringify(availableFilters)
805
+ );
806
+ const globalCallbacks = [];
807
+ const globalValues = {};
808
+ for (const [name, value] of Object.entries(templateGlobals)) {
809
+ if (typeof value === "function") {
810
+ globalCallbacks.push(name);
811
+ } else {
812
+ globalValues[name] = value;
813
+ }
814
+ }
815
+ await contextGlobal.set(
816
+ "availableTemplateGlobals",
817
+ JSON.stringify(globalValues)
818
+ );
819
+ await contextGlobal.set(
820
+ "availableTemplateCallbacks",
821
+ JSON.stringify(globalCallbacks)
822
+ );
823
+ await contextGlobal.set(
824
+ "callFilter",
825
+ (filterName, args) => {
826
+ if (!Object.hasOwn(templateFilters, filterName)) {
827
+ return "";
828
+ }
829
+ return JSON.stringify(templateFilters[filterName](...args));
830
+ }
831
+ );
832
+ await contextGlobal.set(
833
+ "callGlobal",
834
+ (globalName, args) => {
835
+ if (!Object.hasOwn(templateGlobals, globalName)) {
836
+ return "";
837
+ }
838
+ const global = templateGlobals[globalName];
839
+ if (typeof global !== "function") {
840
+ return "";
841
+ }
842
+ return JSON.stringify(global(...args));
843
+ }
844
+ );
845
+ await nunjucksScript.run(context);
821
846
  const render = (template, values) => {
822
- if (!vm) {
847
+ if (!context) {
823
848
  throw new Error("SecureTemplater has not been initialized");
824
849
  }
825
- vm.setGlobal("templateStr", template);
826
- vm.setGlobal("templateValues", JSON.stringify(values));
850
+ contextGlobal.setSync("templateStr", String(template));
851
+ contextGlobal.setSync("templateValues", JSON.stringify(values));
827
852
  if (cookiecutterCompat) {
828
- return vm.run(`renderCompat(templateStr, templateValues)`);
853
+ return context.evalSync(`renderCompat(templateStr, templateValues)`);
829
854
  }
830
- return vm.run(`render(templateStr, templateValues)`);
855
+ return context.evalSync(`render(templateStr, templateValues)`);
831
856
  };
832
857
  return render;
833
858
  }
@@ -6740,4 +6765,4 @@ exports.executeShellCommand = executeShellCommand;
6740
6765
  exports.fetchContents = fetchContents;
6741
6766
  exports.scaffolderActionRules = scaffolderActionRules;
6742
6767
  exports.scaffolderTemplateRules = scaffolderTemplateRules;
6743
- //# sourceMappingURL=ScaffolderEntitiesProcessor-8d851e94.cjs.js.map
6768
+ //# sourceMappingURL=ScaffolderEntitiesProcessor-d9bc7a90.cjs.js.map