@backstage/plugin-scaffolder-backend 1.2.0-next.0 → 1.2.0-next.1
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 +17 -0
- package/dist/index.cjs.js +33 -7
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +9 -0
- package/migrations/20220129100000_created_by.js +38 -0
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-backend
|
|
2
2
|
|
|
3
|
+
## 1.2.0-next.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f8baf7df44: Added the ability to reference the user in the `template.yaml` manifest
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @backstage/backend-common@0.13.3-next.2
|
|
13
|
+
- @backstage/plugin-catalog-backend@1.1.2-next.2
|
|
14
|
+
- @backstage/plugin-scaffolder-common@1.1.0-next.0
|
|
15
|
+
- @backstage/config@1.0.1-next.0
|
|
16
|
+
- @backstage/catalog-model@1.0.2-next.0
|
|
17
|
+
- @backstage/integration@1.2.0-next.1
|
|
18
|
+
- @backstage/catalog-client@1.0.2-next.0
|
|
19
|
+
|
|
3
20
|
## 1.2.0-next.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -2653,6 +2653,7 @@ class DatabaseTaskStore {
|
|
|
2653
2653
|
this.db = options.database;
|
|
2654
2654
|
}
|
|
2655
2655
|
async getTask(taskId) {
|
|
2656
|
+
var _a;
|
|
2656
2657
|
const [result] = await this.db("tasks").where({ id: taskId }).select();
|
|
2657
2658
|
if (!result) {
|
|
2658
2659
|
throw new errors.NotFoundError(`No task with id '${taskId}' found`);
|
|
@@ -2666,6 +2667,7 @@ class DatabaseTaskStore {
|
|
|
2666
2667
|
status: result.status,
|
|
2667
2668
|
lastHeartbeatAt: result.last_heartbeat_at,
|
|
2668
2669
|
createdAt: result.created_at,
|
|
2670
|
+
createdBy: (_a = result.created_by) != null ? _a : void 0,
|
|
2669
2671
|
secrets
|
|
2670
2672
|
};
|
|
2671
2673
|
} catch (error) {
|
|
@@ -2673,17 +2675,20 @@ class DatabaseTaskStore {
|
|
|
2673
2675
|
}
|
|
2674
2676
|
}
|
|
2675
2677
|
async createTask(options) {
|
|
2678
|
+
var _a;
|
|
2676
2679
|
const taskId = uuid.v4();
|
|
2677
2680
|
await this.db("tasks").insert({
|
|
2678
2681
|
id: taskId,
|
|
2679
2682
|
spec: JSON.stringify(options.spec),
|
|
2680
2683
|
secrets: options.secrets ? JSON.stringify(options.secrets) : void 0,
|
|
2684
|
+
created_by: (_a = options.createdBy) != null ? _a : null,
|
|
2681
2685
|
status: "open"
|
|
2682
2686
|
});
|
|
2683
2687
|
return { taskId };
|
|
2684
2688
|
}
|
|
2685
2689
|
async claimTask() {
|
|
2686
2690
|
return this.db.transaction(async (tx) => {
|
|
2691
|
+
var _a;
|
|
2687
2692
|
const [task] = await tx("tasks").where({
|
|
2688
2693
|
status: "open"
|
|
2689
2694
|
}).limit(1).select();
|
|
@@ -2707,6 +2712,7 @@ class DatabaseTaskStore {
|
|
|
2707
2712
|
status: "processing",
|
|
2708
2713
|
lastHeartbeatAt: task.last_heartbeat_at,
|
|
2709
2714
|
createdAt: task.created_at,
|
|
2715
|
+
createdBy: (_a = task.created_by) != null ? _a : void 0,
|
|
2710
2716
|
secrets
|
|
2711
2717
|
};
|
|
2712
2718
|
} catch (error) {
|
|
@@ -2825,6 +2831,9 @@ class TaskManager {
|
|
|
2825
2831
|
get secrets() {
|
|
2826
2832
|
return this.task.secrets;
|
|
2827
2833
|
}
|
|
2834
|
+
get createdBy() {
|
|
2835
|
+
return this.task.createdBy;
|
|
2836
|
+
}
|
|
2828
2837
|
async getWorkspaceName() {
|
|
2829
2838
|
return this.task.taskId;
|
|
2830
2839
|
}
|
|
@@ -2884,7 +2893,8 @@ class StorageTaskBroker {
|
|
|
2884
2893
|
return TaskManager.create({
|
|
2885
2894
|
taskId: pendingTask.id,
|
|
2886
2895
|
spec: pendingTask.spec,
|
|
2887
|
-
secrets: pendingTask.secrets
|
|
2896
|
+
secrets: pendingTask.secrets,
|
|
2897
|
+
createdBy: pendingTask.createdBy
|
|
2888
2898
|
}, this.storage, this.logger);
|
|
2889
2899
|
}
|
|
2890
2900
|
await this.waitForDispatch();
|
|
@@ -3035,7 +3045,8 @@ class NunjucksWorkflowRunner {
|
|
|
3035
3045
|
await task.emitLog(`Starting up task with ${task.spec.steps.length} steps`);
|
|
3036
3046
|
const context = {
|
|
3037
3047
|
parameters: task.spec.parameters,
|
|
3038
|
-
steps: {}
|
|
3048
|
+
steps: {},
|
|
3049
|
+
user: task.spec.user
|
|
3039
3050
|
};
|
|
3040
3051
|
for (const step of task.spec.steps) {
|
|
3041
3052
|
try {
|
|
@@ -3253,10 +3264,11 @@ async function createRouter(options) {
|
|
|
3253
3264
|
router.get("/v2/templates/:namespace/:kind/:name/parameter-schema", async (req, res) => {
|
|
3254
3265
|
var _a, _b;
|
|
3255
3266
|
const { namespace, kind, name } = req.params;
|
|
3267
|
+
const { token } = parseBearerToken(req.headers.authorization);
|
|
3256
3268
|
const template = await findTemplate({
|
|
3257
3269
|
catalogApi: catalogClient,
|
|
3258
3270
|
entityRef: { kind, namespace, name },
|
|
3259
|
-
token
|
|
3271
|
+
token
|
|
3260
3272
|
});
|
|
3261
3273
|
if (isSupportedTemplate(template)) {
|
|
3262
3274
|
const parameters = [(_a = template.spec.parameters) != null ? _a : []].flat();
|
|
@@ -3288,12 +3300,13 @@ async function createRouter(options) {
|
|
|
3288
3300
|
const { kind, namespace, name } = catalogModel.parseEntityRef(templateRef, {
|
|
3289
3301
|
defaultKind: "template"
|
|
3290
3302
|
});
|
|
3303
|
+
const { token, entityRef: userEntityRef } = parseBearerToken(req.headers.authorization);
|
|
3304
|
+
const userEntity = userEntityRef ? await catalogClient.getEntityByRef(userEntityRef, { token }) : void 0;
|
|
3291
3305
|
const values = req.body.values;
|
|
3292
|
-
const token = getBearerToken(req.headers.authorization);
|
|
3293
3306
|
const template = await findTemplate({
|
|
3294
3307
|
catalogApi: catalogClient,
|
|
3295
3308
|
entityRef: { kind, namespace, name },
|
|
3296
|
-
token
|
|
3309
|
+
token
|
|
3297
3310
|
});
|
|
3298
3311
|
if (!isSupportedTemplate(template)) {
|
|
3299
3312
|
throw new errors.InputError(`Unsupported apiVersion field in schema entity, ${template.apiVersion}`);
|
|
@@ -3318,6 +3331,10 @@ async function createRouter(options) {
|
|
|
3318
3331
|
}),
|
|
3319
3332
|
output: (_b = template.spec.output) != null ? _b : {},
|
|
3320
3333
|
parameters: values,
|
|
3334
|
+
user: {
|
|
3335
|
+
entity: userEntity,
|
|
3336
|
+
ref: userEntityRef
|
|
3337
|
+
},
|
|
3321
3338
|
templateInfo: {
|
|
3322
3339
|
entityRef: catalogModel.stringifyEntityRef({
|
|
3323
3340
|
kind,
|
|
@@ -3329,6 +3346,7 @@ async function createRouter(options) {
|
|
|
3329
3346
|
};
|
|
3330
3347
|
const result = await taskBroker.dispatch({
|
|
3331
3348
|
spec: taskSpec,
|
|
3349
|
+
createdBy: userEntityRef,
|
|
3332
3350
|
secrets: {
|
|
3333
3351
|
...req.body.secrets,
|
|
3334
3352
|
backstageToken: token
|
|
@@ -3403,9 +3421,17 @@ data: ${JSON.stringify(event)}
|
|
|
3403
3421
|
app.use("/", router);
|
|
3404
3422
|
return app;
|
|
3405
3423
|
}
|
|
3406
|
-
function
|
|
3424
|
+
function parseBearerToken(header) {
|
|
3407
3425
|
var _a;
|
|
3408
|
-
|
|
3426
|
+
const token = (_a = header == null ? void 0 : header.match(/Bearer\s+(\S+)/i)) == null ? void 0 : _a[1];
|
|
3427
|
+
if (!token)
|
|
3428
|
+
return {};
|
|
3429
|
+
const [_header, rawPayload, _signature] = token.split(".");
|
|
3430
|
+
const payload = JSON.parse(Buffer.from(rawPayload, "base64").toString());
|
|
3431
|
+
return {
|
|
3432
|
+
entityRef: payload.sub,
|
|
3433
|
+
token
|
|
3434
|
+
};
|
|
3409
3435
|
}
|
|
3410
3436
|
|
|
3411
3437
|
class ScaffolderEntitiesProcessor {
|