@backstage/plugin-scaffolder-backend 1.13.0-next.3 → 1.13.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 +57 -0
- package/alpha/package.json +1 -1
- package/dist/alpha.cjs.js +24 -14
- package/dist/alpha.cjs.js.map +1 -1
- package/dist/alpha.d.ts +57 -16
- package/dist/cjs/{ScaffolderEntitiesProcessor-b5a2b352.cjs.js → ScaffolderEntitiesProcessor-2f24bb9e.cjs.js} +175 -48
- package/dist/cjs/ScaffolderEntitiesProcessor-2f24bb9e.cjs.js.map +1 -0
- package/dist/index.cjs.js +3 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/package.json +18 -18
- package/dist/cjs/ScaffolderEntitiesProcessor-b5a2b352.cjs.js.map +0 -1
|
@@ -36,10 +36,11 @@ var PQueue = require('p-queue');
|
|
|
36
36
|
var winston = require('winston');
|
|
37
37
|
var nunjucks = require('nunjucks');
|
|
38
38
|
var lodash = require('lodash');
|
|
39
|
+
var pluginPermissionNode = require('@backstage/plugin-permission-node');
|
|
39
40
|
var promClient = require('prom-client');
|
|
41
|
+
var pluginPermissionCommon = require('@backstage/plugin-permission-common');
|
|
40
42
|
var url = require('url');
|
|
41
43
|
var os = require('os');
|
|
42
|
-
var pluginPermissionNode = require('@backstage/plugin-permission-node');
|
|
43
44
|
var pluginCatalogNode = require('@backstage/plugin-catalog-node');
|
|
44
45
|
|
|
45
46
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -1270,7 +1271,7 @@ async function initRepoAndPush({
|
|
|
1270
1271
|
name: (_a = gitAuthorInfo == null ? void 0 : gitAuthorInfo.name) != null ? _a : "Scaffolder",
|
|
1271
1272
|
email: (_b = gitAuthorInfo == null ? void 0 : gitAuthorInfo.email) != null ? _b : "scaffolder@backstage.io"
|
|
1272
1273
|
};
|
|
1273
|
-
await git.commit({
|
|
1274
|
+
const commitHash = await git.commit({
|
|
1274
1275
|
dir,
|
|
1275
1276
|
message: commitMessage,
|
|
1276
1277
|
author: authorInfo,
|
|
@@ -1285,6 +1286,7 @@ async function initRepoAndPush({
|
|
|
1285
1286
|
dir,
|
|
1286
1287
|
remote: "origin"
|
|
1287
1288
|
});
|
|
1289
|
+
return { commitHash };
|
|
1288
1290
|
}
|
|
1289
1291
|
async function commitAndPushRepo({
|
|
1290
1292
|
dir,
|
|
@@ -1307,7 +1309,7 @@ async function commitAndPushRepo({
|
|
|
1307
1309
|
name: (_a = gitAuthorInfo == null ? void 0 : gitAuthorInfo.name) != null ? _a : "Scaffolder",
|
|
1308
1310
|
email: (_b = gitAuthorInfo == null ? void 0 : gitAuthorInfo.email) != null ? _b : "scaffolder@backstage.io"
|
|
1309
1311
|
};
|
|
1310
|
-
await git.commit({
|
|
1312
|
+
const commitHash = await git.commit({
|
|
1311
1313
|
dir,
|
|
1312
1314
|
message: commitMessage,
|
|
1313
1315
|
author: authorInfo,
|
|
@@ -1318,6 +1320,7 @@ async function commitAndPushRepo({
|
|
|
1318
1320
|
remote: "origin",
|
|
1319
1321
|
remoteRef: remoteRef != null ? remoteRef : `refs/heads/${branch}`
|
|
1320
1322
|
});
|
|
1323
|
+
return { commitHash };
|
|
1321
1324
|
}
|
|
1322
1325
|
const enableBranchProtectionOnDefaultRepoBranch = async ({
|
|
1323
1326
|
repoName,
|
|
@@ -1560,7 +1563,7 @@ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, source
|
|
|
1560
1563
|
email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
|
|
1561
1564
|
};
|
|
1562
1565
|
const commitMessage = gitCommitMessage ? gitCommitMessage : config.getOptionalString("scaffolder.defaultCommitMessage");
|
|
1563
|
-
await initRepoAndPush({
|
|
1566
|
+
const commitResult = await initRepoAndPush({
|
|
1564
1567
|
dir: getRepoSourceDirectory(workspacePath, sourcePath),
|
|
1565
1568
|
remoteUrl,
|
|
1566
1569
|
defaultBranch,
|
|
@@ -1598,6 +1601,7 @@ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, source
|
|
|
1598
1601
|
);
|
|
1599
1602
|
}
|
|
1600
1603
|
}
|
|
1604
|
+
return { commitHash: commitResult.commitHash };
|
|
1601
1605
|
}
|
|
1602
1606
|
function extractCollaboratorName(collaborator) {
|
|
1603
1607
|
if ("username" in collaborator)
|
|
@@ -2007,6 +2011,10 @@ const repoContentsUrl = {
|
|
|
2007
2011
|
title: "A URL to the root of the repository",
|
|
2008
2012
|
type: "string"
|
|
2009
2013
|
};
|
|
2014
|
+
const commitHash = {
|
|
2015
|
+
title: "The git commit hash of the initial commit",
|
|
2016
|
+
type: "string"
|
|
2017
|
+
};
|
|
2010
2018
|
|
|
2011
2019
|
function createGithubRepoCreateAction(options) {
|
|
2012
2020
|
const { integrations, githubCredentialsProvider } = options;
|
|
@@ -2147,7 +2155,8 @@ function createGithubRepoPushAction(options) {
|
|
|
2147
2155
|
type: "object",
|
|
2148
2156
|
properties: {
|
|
2149
2157
|
remoteUrl: remoteUrl,
|
|
2150
|
-
repoContentsUrl: repoContentsUrl
|
|
2158
|
+
repoContentsUrl: repoContentsUrl,
|
|
2159
|
+
commitHash: commitHash
|
|
2151
2160
|
}
|
|
2152
2161
|
}
|
|
2153
2162
|
},
|
|
@@ -2185,7 +2194,7 @@ function createGithubRepoPushAction(options) {
|
|
|
2185
2194
|
const targetRepo = await client.rest.repos.get({ owner, repo });
|
|
2186
2195
|
const remoteUrl = targetRepo.data.clone_url;
|
|
2187
2196
|
const repoContentsUrl = `${targetRepo.data.html_url}/blob/${defaultBranch}`;
|
|
2188
|
-
await initRepoPushAndProtect(
|
|
2197
|
+
const { commitHash } = await initRepoPushAndProtect(
|
|
2189
2198
|
remoteUrl,
|
|
2190
2199
|
octokitOptions.auth,
|
|
2191
2200
|
ctx.workspacePath,
|
|
@@ -2213,6 +2222,7 @@ function createGithubRepoPushAction(options) {
|
|
|
2213
2222
|
);
|
|
2214
2223
|
ctx.output("remoteUrl", remoteUrl);
|
|
2215
2224
|
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
2225
|
+
ctx.output("commitHash", commitHash);
|
|
2216
2226
|
}
|
|
2217
2227
|
});
|
|
2218
2228
|
}
|
|
@@ -2399,6 +2409,10 @@ function createPublishAzureAction(options) {
|
|
|
2399
2409
|
repositoryId: {
|
|
2400
2410
|
title: "The Id of the created repository",
|
|
2401
2411
|
type: "string"
|
|
2412
|
+
},
|
|
2413
|
+
commitHash: {
|
|
2414
|
+
title: "The git commit hash of the initial commit",
|
|
2415
|
+
type: "string"
|
|
2402
2416
|
}
|
|
2403
2417
|
}
|
|
2404
2418
|
}
|
|
@@ -2457,7 +2471,7 @@ function createPublishAzureAction(options) {
|
|
|
2457
2471
|
name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
|
|
2458
2472
|
email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
|
|
2459
2473
|
};
|
|
2460
|
-
await initRepoAndPush({
|
|
2474
|
+
const commitResult = await initRepoAndPush({
|
|
2461
2475
|
dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
|
|
2462
2476
|
remoteUrl,
|
|
2463
2477
|
defaultBranch,
|
|
@@ -2469,6 +2483,7 @@ function createPublishAzureAction(options) {
|
|
|
2469
2483
|
commitMessage: gitCommitMessage ? gitCommitMessage : config.getOptionalString("scaffolder.defaultCommitMessage"),
|
|
2470
2484
|
gitAuthorInfo
|
|
2471
2485
|
});
|
|
2486
|
+
ctx.output("commitHash", commitResult == null ? void 0 : commitResult.commitHash);
|
|
2472
2487
|
ctx.output("remoteUrl", remoteUrl);
|
|
2473
2488
|
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
2474
2489
|
ctx.output("repositoryId", repositoryId);
|
|
@@ -2668,6 +2683,10 @@ function createPublishBitbucketAction(options) {
|
|
|
2668
2683
|
repoContentsUrl: {
|
|
2669
2684
|
title: "A URL to the root of the repository",
|
|
2670
2685
|
type: "string"
|
|
2686
|
+
},
|
|
2687
|
+
commitHash: {
|
|
2688
|
+
title: "The git commit hash of the initial commit",
|
|
2689
|
+
type: "string"
|
|
2671
2690
|
}
|
|
2672
2691
|
}
|
|
2673
2692
|
}
|
|
@@ -2744,7 +2763,7 @@ function createPublishBitbucketAction(options) {
|
|
|
2744
2763
|
password: integrationConfig.config.appPassword ? integrationConfig.config.appPassword : (_a = integrationConfig.config.token) != null ? _a : ""
|
|
2745
2764
|
};
|
|
2746
2765
|
}
|
|
2747
|
-
await initRepoAndPush({
|
|
2766
|
+
const commitResult = await initRepoAndPush({
|
|
2748
2767
|
dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
|
|
2749
2768
|
remoteUrl,
|
|
2750
2769
|
auth,
|
|
@@ -2756,6 +2775,7 @@ function createPublishBitbucketAction(options) {
|
|
|
2756
2775
|
if (enableLFS && host !== "bitbucket.org") {
|
|
2757
2776
|
await performEnableLFS$1({ authorization, host, project, repo });
|
|
2758
2777
|
}
|
|
2778
|
+
ctx.output("commitHash", commitResult == null ? void 0 : commitResult.commitHash);
|
|
2759
2779
|
ctx.output("remoteUrl", remoteUrl);
|
|
2760
2780
|
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
2761
2781
|
}
|
|
@@ -2875,6 +2895,10 @@ function createPublishBitbucketCloudAction(options) {
|
|
|
2875
2895
|
repoContentsUrl: {
|
|
2876
2896
|
title: "A URL to the root of the repository",
|
|
2877
2897
|
type: "string"
|
|
2898
|
+
},
|
|
2899
|
+
commitHash: {
|
|
2900
|
+
title: "The git commit hash of the initial commit",
|
|
2901
|
+
type: "string"
|
|
2878
2902
|
}
|
|
2879
2903
|
}
|
|
2880
2904
|
}
|
|
@@ -2941,7 +2965,7 @@ function createPublishBitbucketCloudAction(options) {
|
|
|
2941
2965
|
password: integrationConfig.config.appPassword
|
|
2942
2966
|
};
|
|
2943
2967
|
}
|
|
2944
|
-
await initRepoAndPush({
|
|
2968
|
+
const commitResult = await initRepoAndPush({
|
|
2945
2969
|
dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
|
|
2946
2970
|
remoteUrl,
|
|
2947
2971
|
auth,
|
|
@@ -2952,6 +2976,7 @@ function createPublishBitbucketCloudAction(options) {
|
|
|
2952
2976
|
),
|
|
2953
2977
|
gitAuthorInfo
|
|
2954
2978
|
});
|
|
2979
|
+
ctx.output("commitHash", commitResult == null ? void 0 : commitResult.commitHash);
|
|
2955
2980
|
ctx.output("remoteUrl", remoteUrl);
|
|
2956
2981
|
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
2957
2982
|
}
|
|
@@ -3089,6 +3114,10 @@ function createPublishBitbucketServerAction(options) {
|
|
|
3089
3114
|
repoContentsUrl: {
|
|
3090
3115
|
title: "A URL to the root of the repository",
|
|
3091
3116
|
type: "string"
|
|
3117
|
+
},
|
|
3118
|
+
commitHash: {
|
|
3119
|
+
title: "The git commit hash of the initial commit",
|
|
3120
|
+
type: "string"
|
|
3092
3121
|
}
|
|
3093
3122
|
}
|
|
3094
3123
|
}
|
|
@@ -3149,7 +3178,7 @@ function createPublishBitbucketServerAction(options) {
|
|
|
3149
3178
|
username: authConfig.username,
|
|
3150
3179
|
password: authConfig.password
|
|
3151
3180
|
};
|
|
3152
|
-
await initRepoAndPush({
|
|
3181
|
+
const commitResult = await initRepoAndPush({
|
|
3153
3182
|
dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
|
|
3154
3183
|
remoteUrl,
|
|
3155
3184
|
auth,
|
|
@@ -3161,6 +3190,7 @@ function createPublishBitbucketServerAction(options) {
|
|
|
3161
3190
|
if (enableLFS) {
|
|
3162
3191
|
await performEnableLFS({ authorization, host, project, repo });
|
|
3163
3192
|
}
|
|
3193
|
+
ctx.output("commitHash", commitResult == null ? void 0 : commitResult.commitHash);
|
|
3164
3194
|
ctx.output("remoteUrl", remoteUrl);
|
|
3165
3195
|
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
3166
3196
|
}
|
|
@@ -3254,6 +3284,10 @@ function createPublishGerritAction(options) {
|
|
|
3254
3284
|
repoContentsUrl: {
|
|
3255
3285
|
title: "A URL to the root of the repository",
|
|
3256
3286
|
type: "string"
|
|
3287
|
+
},
|
|
3288
|
+
commitHash: {
|
|
3289
|
+
title: "The git commit hash of the initial commit",
|
|
3290
|
+
type: "string"
|
|
3257
3291
|
}
|
|
3258
3292
|
}
|
|
3259
3293
|
}
|
|
@@ -3298,7 +3332,7 @@ function createPublishGerritAction(options) {
|
|
|
3298
3332
|
email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
|
|
3299
3333
|
};
|
|
3300
3334
|
const remoteUrl = `${integrationConfig.config.cloneUrl}/a/${repo}`;
|
|
3301
|
-
await initRepoAndPush({
|
|
3335
|
+
const commitResult = await initRepoAndPush({
|
|
3302
3336
|
dir: getRepoSourceDirectory(ctx.workspacePath, sourcePath),
|
|
3303
3337
|
remoteUrl,
|
|
3304
3338
|
auth,
|
|
@@ -3309,6 +3343,7 @@ function createPublishGerritAction(options) {
|
|
|
3309
3343
|
});
|
|
3310
3344
|
const repoContentsUrl = `${integrationConfig.config.gitilesBaseUrl}/${repo}/+/refs/heads/${defaultBranch}`;
|
|
3311
3345
|
ctx.output("remoteUrl", remoteUrl);
|
|
3346
|
+
ctx.output("commitHash", commitResult == null ? void 0 : commitResult.commitHash);
|
|
3312
3347
|
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
3313
3348
|
}
|
|
3314
3349
|
});
|
|
@@ -3473,7 +3508,8 @@ function createPublishGithubAction(options) {
|
|
|
3473
3508
|
type: "object",
|
|
3474
3509
|
properties: {
|
|
3475
3510
|
remoteUrl: remoteUrl,
|
|
3476
|
-
repoContentsUrl: repoContentsUrl
|
|
3511
|
+
repoContentsUrl: repoContentsUrl,
|
|
3512
|
+
commitHash: commitHash
|
|
3477
3513
|
}
|
|
3478
3514
|
}
|
|
3479
3515
|
},
|
|
@@ -3548,7 +3584,7 @@ function createPublishGithubAction(options) {
|
|
|
3548
3584
|
);
|
|
3549
3585
|
const remoteUrl = newRepo.clone_url;
|
|
3550
3586
|
const repoContentsUrl = `${newRepo.html_url}/blob/${defaultBranch}`;
|
|
3551
|
-
await initRepoPushAndProtect(
|
|
3587
|
+
const commitResult = await initRepoPushAndProtect(
|
|
3552
3588
|
remoteUrl,
|
|
3553
3589
|
octokitOptions.auth,
|
|
3554
3590
|
ctx.workspacePath,
|
|
@@ -3574,6 +3610,7 @@ function createPublishGithubAction(options) {
|
|
|
3574
3610
|
dismissStaleReviews,
|
|
3575
3611
|
requiredCommitSigning
|
|
3576
3612
|
);
|
|
3613
|
+
ctx.output("commitHash", commitResult == null ? void 0 : commitResult.commitHash);
|
|
3577
3614
|
ctx.output("remoteUrl", remoteUrl);
|
|
3578
3615
|
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
3579
3616
|
}
|
|
@@ -3959,6 +3996,10 @@ function createPublishGitlabAction(options) {
|
|
|
3959
3996
|
projectId: {
|
|
3960
3997
|
title: "The ID of the project",
|
|
3961
3998
|
type: "string"
|
|
3999
|
+
},
|
|
4000
|
+
commitHash: {
|
|
4001
|
+
title: "The git commit hash of the initial commit",
|
|
4002
|
+
type: "string"
|
|
3962
4003
|
}
|
|
3963
4004
|
}
|
|
3964
4005
|
}
|
|
@@ -4019,7 +4060,7 @@ function createPublishGitlabAction(options) {
|
|
|
4019
4060
|
name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
|
|
4020
4061
|
email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
|
|
4021
4062
|
};
|
|
4022
|
-
await initRepoAndPush({
|
|
4063
|
+
const commitResult = await initRepoAndPush({
|
|
4023
4064
|
dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
|
|
4024
4065
|
remoteUrl: http_url_to_repo,
|
|
4025
4066
|
defaultBranch,
|
|
@@ -4031,6 +4072,7 @@ function createPublishGitlabAction(options) {
|
|
|
4031
4072
|
commitMessage: gitCommitMessage ? gitCommitMessage : config.getOptionalString("scaffolder.defaultCommitMessage"),
|
|
4032
4073
|
gitAuthorInfo
|
|
4033
4074
|
});
|
|
4075
|
+
ctx.output("commitHash", commitResult == null ? void 0 : commitResult.commitHash);
|
|
4034
4076
|
ctx.output("remoteUrl", remoteUrl);
|
|
4035
4077
|
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
4036
4078
|
ctx.output("projectId", projectId);
|
|
@@ -4899,6 +4941,87 @@ function createHistogramMetric(config) {
|
|
|
4899
4941
|
return metric;
|
|
4900
4942
|
}
|
|
4901
4943
|
|
|
4944
|
+
const createTemplatePermissionRule = pluginPermissionNode.makeCreatePermissionRule();
|
|
4945
|
+
const hasTag = createTemplatePermissionRule({
|
|
4946
|
+
name: "HAS_TAG",
|
|
4947
|
+
resourceType: alpha.RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,
|
|
4948
|
+
description: `Match parameters or steps with the given tag`,
|
|
4949
|
+
paramsSchema: zod.z.object({
|
|
4950
|
+
tag: zod.z.string().describe("Name of the tag to match on")
|
|
4951
|
+
}),
|
|
4952
|
+
apply: (resource, { tag }) => {
|
|
4953
|
+
var _a, _b, _c;
|
|
4954
|
+
return (_c = (_b = (_a = resource["backstage:permissions"]) == null ? void 0 : _a.tags) == null ? void 0 : _b.includes(tag)) != null ? _c : false;
|
|
4955
|
+
},
|
|
4956
|
+
toQuery: () => ({})
|
|
4957
|
+
});
|
|
4958
|
+
const createActionPermissionRule = pluginPermissionNode.makeCreatePermissionRule();
|
|
4959
|
+
const hasActionId = createActionPermissionRule({
|
|
4960
|
+
name: "HAS_ACTION_ID",
|
|
4961
|
+
resourceType: alpha.RESOURCE_TYPE_SCAFFOLDER_ACTION,
|
|
4962
|
+
description: `Match actions with the given actionId`,
|
|
4963
|
+
paramsSchema: zod.z.object({
|
|
4964
|
+
actionId: zod.z.string().describe("Name of the actionId to match on")
|
|
4965
|
+
}),
|
|
4966
|
+
apply: (resource, { actionId }) => {
|
|
4967
|
+
return resource.action === actionId;
|
|
4968
|
+
},
|
|
4969
|
+
toQuery: () => ({})
|
|
4970
|
+
});
|
|
4971
|
+
buildHasProperty({
|
|
4972
|
+
name: "HAS_PROPERTY",
|
|
4973
|
+
valueSchema: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()]),
|
|
4974
|
+
validateProperty: false
|
|
4975
|
+
});
|
|
4976
|
+
const hasBooleanProperty = buildHasProperty({
|
|
4977
|
+
name: "HAS_BOOLEAN_PROPERTY",
|
|
4978
|
+
valueSchema: zod.z.boolean()
|
|
4979
|
+
});
|
|
4980
|
+
const hasNumberProperty = buildHasProperty({
|
|
4981
|
+
name: "HAS_NUMBER_PROPERTY",
|
|
4982
|
+
valueSchema: zod.z.number()
|
|
4983
|
+
});
|
|
4984
|
+
const hasStringProperty = buildHasProperty({
|
|
4985
|
+
name: "HAS_STRING_PROPERTY",
|
|
4986
|
+
valueSchema: zod.z.string()
|
|
4987
|
+
});
|
|
4988
|
+
function buildHasProperty({
|
|
4989
|
+
name,
|
|
4990
|
+
valueSchema,
|
|
4991
|
+
validateProperty = true
|
|
4992
|
+
}) {
|
|
4993
|
+
return createActionPermissionRule({
|
|
4994
|
+
name,
|
|
4995
|
+
description: `Allow actions with the specified property`,
|
|
4996
|
+
resourceType: alpha.RESOURCE_TYPE_SCAFFOLDER_ACTION,
|
|
4997
|
+
paramsSchema: zod.z.object({
|
|
4998
|
+
key: zod.z.string().describe(`Property within the action parameters to match on`),
|
|
4999
|
+
value: valueSchema.describe(`Value of the given property to match on`)
|
|
5000
|
+
}),
|
|
5001
|
+
apply: (resource, { key, value }) => {
|
|
5002
|
+
const foundValue = lodash.get(resource.input, key);
|
|
5003
|
+
if (validateProperty && !valueSchema.safeParse(foundValue).success) {
|
|
5004
|
+
return false;
|
|
5005
|
+
}
|
|
5006
|
+
if (value !== void 0) {
|
|
5007
|
+
if (valueSchema.safeParse(value).success) {
|
|
5008
|
+
return value === foundValue;
|
|
5009
|
+
}
|
|
5010
|
+
return false;
|
|
5011
|
+
}
|
|
5012
|
+
return foundValue !== void 0;
|
|
5013
|
+
},
|
|
5014
|
+
toQuery: () => ({})
|
|
5015
|
+
});
|
|
5016
|
+
}
|
|
5017
|
+
const scaffolderTemplateRules = { hasTag };
|
|
5018
|
+
const scaffolderActionRules = {
|
|
5019
|
+
hasActionId,
|
|
5020
|
+
hasBooleanProperty,
|
|
5021
|
+
hasNumberProperty,
|
|
5022
|
+
hasStringProperty
|
|
5023
|
+
};
|
|
5024
|
+
|
|
4902
5025
|
const isValidTaskSpec = (taskSpec) => {
|
|
4903
5026
|
return taskSpec.apiVersion === "scaffolder.backstage.io/v1beta3";
|
|
4904
5027
|
};
|
|
@@ -4925,6 +5048,9 @@ const createStepLogger = ({
|
|
|
4925
5048
|
taskLogger.add(new winston__namespace.transports.Stream({ stream: streamLogger }));
|
|
4926
5049
|
return { taskLogger, streamLogger };
|
|
4927
5050
|
};
|
|
5051
|
+
const isActionAuthorized = pluginPermissionNode.createConditionAuthorizer(
|
|
5052
|
+
Object.values(scaffolderActionRules)
|
|
5053
|
+
);
|
|
4928
5054
|
class NunjucksWorkflowRunner {
|
|
4929
5055
|
constructor(options) {
|
|
4930
5056
|
this.options = options;
|
|
@@ -4982,7 +5108,7 @@ class NunjucksWorkflowRunner {
|
|
|
4982
5108
|
return value;
|
|
4983
5109
|
});
|
|
4984
5110
|
}
|
|
4985
|
-
async executeStep(task, step, context, renderTemplate, taskTrack, workspacePath) {
|
|
5111
|
+
async executeStep(task, step, context, renderTemplate, taskTrack, workspacePath, decision) {
|
|
4986
5112
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
4987
5113
|
const stepTrack = await this.tracker.stepStart(task, step);
|
|
4988
5114
|
if (task.cancelSignal.aborted) {
|
|
@@ -5047,6 +5173,15 @@ class NunjucksWorkflowRunner {
|
|
|
5047
5173
|
);
|
|
5048
5174
|
}
|
|
5049
5175
|
}
|
|
5176
|
+
if (!isActionAuthorized(decision, { action: action.id, input })) {
|
|
5177
|
+
throw new errors.NotAllowedError(
|
|
5178
|
+
`Unauthorized action: ${action.id}. The action is not allowed. Input: ${JSON.stringify(
|
|
5179
|
+
input,
|
|
5180
|
+
null,
|
|
5181
|
+
2
|
|
5182
|
+
)}`
|
|
5183
|
+
);
|
|
5184
|
+
}
|
|
5050
5185
|
const tmpDirs = new Array();
|
|
5051
5186
|
const stepOutput = {};
|
|
5052
5187
|
await action.handler({
|
|
@@ -5083,6 +5218,7 @@ class NunjucksWorkflowRunner {
|
|
|
5083
5218
|
}
|
|
5084
5219
|
}
|
|
5085
5220
|
async execute(task) {
|
|
5221
|
+
var _a;
|
|
5086
5222
|
if (!isValidTaskSpec(task.spec)) {
|
|
5087
5223
|
throw new errors.InputError(
|
|
5088
5224
|
"Wrong template version executed with the workflow engine"
|
|
@@ -5108,6 +5244,10 @@ class NunjucksWorkflowRunner {
|
|
|
5108
5244
|
steps: {},
|
|
5109
5245
|
user: task.spec.user
|
|
5110
5246
|
};
|
|
5247
|
+
const [decision] = this.options.permissions && task.spec.steps.length ? await this.options.permissions.authorizeConditional(
|
|
5248
|
+
[{ permission: alpha.actionExecutePermission }],
|
|
5249
|
+
{ token: (_a = task.secrets) == null ? void 0 : _a.backstageToken }
|
|
5250
|
+
) : [{ result: pluginPermissionCommon.AuthorizeResult.ALLOW }];
|
|
5111
5251
|
for (const step of task.spec.steps) {
|
|
5112
5252
|
await this.executeStep(
|
|
5113
5253
|
task,
|
|
@@ -5115,7 +5255,8 @@ class NunjucksWorkflowRunner {
|
|
|
5115
5255
|
context,
|
|
5116
5256
|
renderTemplate,
|
|
5117
5257
|
taskTrack,
|
|
5118
|
-
workspacePath
|
|
5258
|
+
workspacePath,
|
|
5259
|
+
decision
|
|
5119
5260
|
);
|
|
5120
5261
|
}
|
|
5121
5262
|
const output = this.render(task.spec.output, context, renderTemplate);
|
|
@@ -5265,7 +5406,7 @@ class TaskWorker {
|
|
|
5265
5406
|
constructor(options) {
|
|
5266
5407
|
this.options = options;
|
|
5267
5408
|
this.taskQueue = new PQueue__default["default"]({
|
|
5268
|
-
concurrency:
|
|
5409
|
+
concurrency: options.concurrentTasksLimit
|
|
5269
5410
|
});
|
|
5270
5411
|
}
|
|
5271
5412
|
static async create(options) {
|
|
@@ -5278,7 +5419,8 @@ class TaskWorker {
|
|
|
5278
5419
|
additionalTemplateFilters,
|
|
5279
5420
|
concurrentTasksLimit = 10,
|
|
5280
5421
|
// from 1 to Infinity
|
|
5281
|
-
additionalTemplateGlobals
|
|
5422
|
+
additionalTemplateGlobals,
|
|
5423
|
+
permissions
|
|
5282
5424
|
} = options;
|
|
5283
5425
|
const workflowRunner = new NunjucksWorkflowRunner({
|
|
5284
5426
|
actionRegistry,
|
|
@@ -5286,12 +5428,14 @@ class TaskWorker {
|
|
|
5286
5428
|
logger,
|
|
5287
5429
|
workingDirectory,
|
|
5288
5430
|
additionalTemplateFilters,
|
|
5289
|
-
additionalTemplateGlobals
|
|
5431
|
+
additionalTemplateGlobals,
|
|
5432
|
+
permissions
|
|
5290
5433
|
});
|
|
5291
5434
|
return new TaskWorker({
|
|
5292
5435
|
taskBroker,
|
|
5293
5436
|
runners: { workflowRunner },
|
|
5294
|
-
concurrentTasksLimit
|
|
5437
|
+
concurrentTasksLimit,
|
|
5438
|
+
permissions
|
|
5295
5439
|
});
|
|
5296
5440
|
}
|
|
5297
5441
|
start() {
|
|
@@ -5478,22 +5622,6 @@ async function findTemplate(options) {
|
|
|
5478
5622
|
return template;
|
|
5479
5623
|
}
|
|
5480
5624
|
|
|
5481
|
-
const createScaffolderPermissionRule = pluginPermissionNode.makeCreatePermissionRule();
|
|
5482
|
-
const hasTag = createScaffolderPermissionRule({
|
|
5483
|
-
name: "HAS_TAG",
|
|
5484
|
-
resourceType: alpha.RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,
|
|
5485
|
-
description: `Match parameters or steps with the given tag`,
|
|
5486
|
-
paramsSchema: zod.z.object({
|
|
5487
|
-
tag: zod.z.string().describe("Name of the tag to match on")
|
|
5488
|
-
}),
|
|
5489
|
-
apply: (resource, { tag }) => {
|
|
5490
|
-
var _a, _b, _c;
|
|
5491
|
-
return (_c = (_b = (_a = resource["backstage:permissions"]) == null ? void 0 : _a.tags) == null ? void 0 : _b.includes(tag)) != null ? _c : false;
|
|
5492
|
-
},
|
|
5493
|
-
toQuery: () => ({})
|
|
5494
|
-
});
|
|
5495
|
-
const scaffolderTemplateRules = { hasTag };
|
|
5496
|
-
|
|
5497
5625
|
function isSupportedTemplate(entity) {
|
|
5498
5626
|
return entity.apiVersion === "scaffolder.backstage.io/v1beta3";
|
|
5499
5627
|
}
|
|
@@ -5556,7 +5684,7 @@ async function createRouter(options) {
|
|
|
5556
5684
|
scheduler,
|
|
5557
5685
|
additionalTemplateFilters,
|
|
5558
5686
|
additionalTemplateGlobals,
|
|
5559
|
-
|
|
5687
|
+
permissions,
|
|
5560
5688
|
permissionRules
|
|
5561
5689
|
} = options;
|
|
5562
5690
|
const logger = parentLogger.child({ plugin: "scaffolder" });
|
|
@@ -5598,7 +5726,8 @@ async function createRouter(options) {
|
|
|
5598
5726
|
workingDirectory,
|
|
5599
5727
|
additionalTemplateFilters,
|
|
5600
5728
|
additionalTemplateGlobals,
|
|
5601
|
-
concurrentTasksLimit
|
|
5729
|
+
concurrentTasksLimit,
|
|
5730
|
+
permissions
|
|
5602
5731
|
});
|
|
5603
5732
|
workers.push(worker);
|
|
5604
5733
|
}
|
|
@@ -5618,7 +5747,8 @@ async function createRouter(options) {
|
|
|
5618
5747
|
logger,
|
|
5619
5748
|
workingDirectory,
|
|
5620
5749
|
additionalTemplateFilters,
|
|
5621
|
-
additionalTemplateGlobals
|
|
5750
|
+
additionalTemplateGlobals,
|
|
5751
|
+
permissions
|
|
5622
5752
|
});
|
|
5623
5753
|
const templateRules = Object.values(
|
|
5624
5754
|
scaffolderTemplateRules
|
|
@@ -5668,7 +5798,7 @@ async function createRouter(options) {
|
|
|
5668
5798
|
});
|
|
5669
5799
|
res.json(actionsList);
|
|
5670
5800
|
}).post("/v2/tasks", async (req, res) => {
|
|
5671
|
-
var _a, _b
|
|
5801
|
+
var _a, _b;
|
|
5672
5802
|
const templateRef = req.body.templateRef;
|
|
5673
5803
|
const { kind, namespace, name } = catalogModel.parseEntityRef(templateRef, {
|
|
5674
5804
|
defaultKind: "template"
|
|
@@ -5714,11 +5844,7 @@ async function createRouter(options) {
|
|
|
5714
5844
|
ref: userEntityRef
|
|
5715
5845
|
},
|
|
5716
5846
|
templateInfo: {
|
|
5717
|
-
entityRef: catalogModel.stringifyEntityRef({
|
|
5718
|
-
kind,
|
|
5719
|
-
namespace,
|
|
5720
|
-
name: (_c = template.metadata) == null ? void 0 : _c.name
|
|
5721
|
-
}),
|
|
5847
|
+
entityRef: catalogModel.stringifyEntityRef({ kind, name, namespace }),
|
|
5722
5848
|
baseUrl,
|
|
5723
5849
|
entity: {
|
|
5724
5850
|
metadata: template.metadata
|
|
@@ -5899,10 +6025,10 @@ data: ${JSON.stringify(event)}
|
|
|
5899
6025
|
`Unsupported apiVersion field in schema entity, ${template.apiVersion}`
|
|
5900
6026
|
);
|
|
5901
6027
|
}
|
|
5902
|
-
if (!
|
|
6028
|
+
if (!permissions) {
|
|
5903
6029
|
return template;
|
|
5904
6030
|
}
|
|
5905
|
-
const [parameterDecision, stepDecision] = await
|
|
6031
|
+
const [parameterDecision, stepDecision] = await permissions.authorizeConditional(
|
|
5906
6032
|
[
|
|
5907
6033
|
{ permission: alpha.templateParameterReadPermission },
|
|
5908
6034
|
{ permission: alpha.templateStepReadPermission }
|
|
@@ -6011,5 +6137,6 @@ exports.createRouter = createRouter;
|
|
|
6011
6137
|
exports.createWaitAction = createWaitAction;
|
|
6012
6138
|
exports.executeShellCommand = executeShellCommand;
|
|
6013
6139
|
exports.fetchContents = fetchContents;
|
|
6140
|
+
exports.scaffolderActionRules = scaffolderActionRules;
|
|
6014
6141
|
exports.scaffolderTemplateRules = scaffolderTemplateRules;
|
|
6015
|
-
//# sourceMappingURL=ScaffolderEntitiesProcessor-
|
|
6142
|
+
//# sourceMappingURL=ScaffolderEntitiesProcessor-2f24bb9e.cjs.js.map
|