@backstage/plugin-scaffolder-backend 1.22.0-next.0 → 1.22.0-next.2
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 +71 -0
- package/alpha/package.json +1 -1
- package/dist/alpha.cjs.js +12 -3
- package/dist/alpha.cjs.js.map +1 -1
- package/dist/cjs/{router-ae706822.cjs.js → router-52d79583.cjs.js} +235 -51
- package/dist/cjs/router-52d79583.cjs.js.map +1 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.d.ts +15 -4
- package/package.json +51 -50
- package/dist/cjs/router-ae706822.cjs.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var backendCommon = require('@backstage/backend-common');
|
|
3
4
|
var catalogModel = require('@backstage/catalog-model');
|
|
4
5
|
var config = require('@backstage/config');
|
|
5
6
|
var errors = require('@backstage/errors');
|
|
@@ -13,7 +14,6 @@ var zod = require('zod');
|
|
|
13
14
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
14
15
|
var yaml = require('yaml');
|
|
15
16
|
var fs = require('fs-extra');
|
|
16
|
-
var backendCommon = require('@backstage/backend-common');
|
|
17
17
|
var path = require('path');
|
|
18
18
|
var luxon = require('luxon');
|
|
19
19
|
var globby = require('globby');
|
|
@@ -95,7 +95,7 @@ const examples$9 = [
|
|
|
95
95
|
|
|
96
96
|
const id$4 = "catalog:register";
|
|
97
97
|
function createCatalogRegisterAction(options) {
|
|
98
|
-
const { catalogClient, integrations } = options;
|
|
98
|
+
const { catalogClient, integrations, auth } = options;
|
|
99
99
|
return pluginScaffolderNode.createTemplateAction({
|
|
100
100
|
id: id$4,
|
|
101
101
|
description: "Registers entities from a catalog descriptor file in the workspace into the software catalog.",
|
|
@@ -175,13 +175,17 @@ function createCatalogRegisterAction(options) {
|
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
177
|
ctx.logger.info(`Registering ${catalogInfoUrl} in the catalog`);
|
|
178
|
+
const { token } = (_b = await (auth == null ? void 0 : auth.getPluginRequestToken({
|
|
179
|
+
onBehalfOf: await ctx.getInitiatorCredentials(),
|
|
180
|
+
targetPluginId: "catalog"
|
|
181
|
+
}))) != null ? _b : { token: (_a = ctx.secrets) == null ? void 0 : _a.backstageToken };
|
|
178
182
|
try {
|
|
179
183
|
await catalogClient.addLocation(
|
|
180
184
|
{
|
|
181
185
|
type: "url",
|
|
182
186
|
target: catalogInfoUrl
|
|
183
187
|
},
|
|
184
|
-
|
|
188
|
+
token ? { token } : {}
|
|
185
189
|
);
|
|
186
190
|
} catch (e) {
|
|
187
191
|
if (!input.optional) {
|
|
@@ -195,7 +199,7 @@ function createCatalogRegisterAction(options) {
|
|
|
195
199
|
type: "url",
|
|
196
200
|
target: catalogInfoUrl
|
|
197
201
|
},
|
|
198
|
-
|
|
202
|
+
token ? { token } : {}
|
|
199
203
|
);
|
|
200
204
|
if (result.entities.length) {
|
|
201
205
|
const { entities } = result;
|
|
@@ -270,7 +274,7 @@ function createCatalogWriteAction() {
|
|
|
270
274
|
examples: examples$8,
|
|
271
275
|
supportsDryRun: true,
|
|
272
276
|
async handler(ctx) {
|
|
273
|
-
ctx.
|
|
277
|
+
ctx.logger.info(`Writing catalog-info.yaml`);
|
|
274
278
|
const { filePath, entity } = ctx.input;
|
|
275
279
|
const path = filePath != null ? filePath : "catalog-info.yaml";
|
|
276
280
|
await fs__default["default"].writeFile(
|
|
@@ -316,7 +320,7 @@ const examples$7 = [
|
|
|
316
320
|
|
|
317
321
|
const id$2 = "catalog:fetch";
|
|
318
322
|
function createFetchCatalogEntityAction(options) {
|
|
319
|
-
const { catalogClient } = options;
|
|
323
|
+
const { catalogClient, auth } = options;
|
|
320
324
|
return pluginScaffolderNode.createTemplateAction({
|
|
321
325
|
id: id$2,
|
|
322
326
|
description: "Returns entity or entities from the catalog by entity reference(s)",
|
|
@@ -356,13 +360,17 @@ function createFetchCatalogEntityAction(options) {
|
|
|
356
360
|
}
|
|
357
361
|
throw new Error("Missing entity reference or references");
|
|
358
362
|
}
|
|
363
|
+
const { token } = (_b = await (auth == null ? void 0 : auth.getPluginRequestToken({
|
|
364
|
+
onBehalfOf: await ctx.getInitiatorCredentials(),
|
|
365
|
+
targetPluginId: "catalog"
|
|
366
|
+
}))) != null ? _b : { token: (_a = ctx.secrets) == null ? void 0 : _a.backstageToken };
|
|
359
367
|
if (entityRef) {
|
|
360
368
|
const entity = await catalogClient.getEntityByRef(
|
|
361
369
|
catalogModel.stringifyEntityRef(
|
|
362
370
|
catalogModel.parseEntityRef(entityRef, { defaultKind, defaultNamespace })
|
|
363
371
|
),
|
|
364
372
|
{
|
|
365
|
-
token
|
|
373
|
+
token
|
|
366
374
|
}
|
|
367
375
|
);
|
|
368
376
|
if (!entity && !optional) {
|
|
@@ -380,7 +388,7 @@ function createFetchCatalogEntityAction(options) {
|
|
|
380
388
|
)
|
|
381
389
|
},
|
|
382
390
|
{
|
|
383
|
-
token
|
|
391
|
+
token
|
|
384
392
|
}
|
|
385
393
|
);
|
|
386
394
|
const finalEntities = entities.items.map((e, i) => {
|
|
@@ -457,11 +465,11 @@ function createDebugLogAction() {
|
|
|
457
465
|
var _a, _b;
|
|
458
466
|
ctx.logger.info(JSON.stringify(ctx.input, null, 2));
|
|
459
467
|
if ((_a = ctx.input) == null ? void 0 : _a.message) {
|
|
460
|
-
ctx.
|
|
468
|
+
ctx.logger.info(ctx.input.message);
|
|
461
469
|
}
|
|
462
470
|
if ((_b = ctx.input) == null ? void 0 : _b.listWorkspace) {
|
|
463
471
|
const files = await recursiveReadDir(ctx.workspacePath);
|
|
464
|
-
ctx.
|
|
472
|
+
ctx.logger.info(
|
|
465
473
|
`Workspace:
|
|
466
474
|
${files.map((f) => ` - ${path.relative(ctx.workspacePath, f)}`).join("\n")}`
|
|
467
475
|
);
|
|
@@ -1320,6 +1328,7 @@ const createBuiltinActions = (options) => {
|
|
|
1320
1328
|
reader,
|
|
1321
1329
|
integrations,
|
|
1322
1330
|
catalogClient,
|
|
1331
|
+
auth,
|
|
1323
1332
|
config,
|
|
1324
1333
|
additionalTemplateFilters,
|
|
1325
1334
|
additionalTemplateGlobals
|
|
@@ -1393,8 +1402,8 @@ const createBuiltinActions = (options) => {
|
|
|
1393
1402
|
}),
|
|
1394
1403
|
createDebugLogAction(),
|
|
1395
1404
|
createWaitAction(),
|
|
1396
|
-
createCatalogRegisterAction({ catalogClient, integrations }),
|
|
1397
|
-
createFetchCatalogEntityAction({ catalogClient }),
|
|
1405
|
+
createCatalogRegisterAction({ catalogClient, integrations, auth }),
|
|
1406
|
+
createFetchCatalogEntityAction({ catalogClient, auth }),
|
|
1398
1407
|
createCatalogWriteAction(),
|
|
1399
1408
|
createFilesystemDeleteAction(),
|
|
1400
1409
|
createFilesystemRenameAction(),
|
|
@@ -1893,16 +1902,17 @@ var __publicField$2 = (obj, key, value) => {
|
|
|
1893
1902
|
};
|
|
1894
1903
|
class TaskManager {
|
|
1895
1904
|
// Runs heartbeat internally
|
|
1896
|
-
constructor(task, storage, signal, logger) {
|
|
1905
|
+
constructor(task, storage, signal, logger, auth) {
|
|
1897
1906
|
this.task = task;
|
|
1898
1907
|
this.storage = storage;
|
|
1899
1908
|
this.signal = signal;
|
|
1900
1909
|
this.logger = logger;
|
|
1910
|
+
this.auth = auth;
|
|
1901
1911
|
__publicField$2(this, "isDone", false);
|
|
1902
1912
|
__publicField$2(this, "heartbeatTimeoutId");
|
|
1903
1913
|
}
|
|
1904
|
-
static create(task, storage, abortSignal, logger) {
|
|
1905
|
-
const agent = new TaskManager(task, storage, abortSignal, logger);
|
|
1914
|
+
static create(task, storage, abortSignal, logger, auth) {
|
|
1915
|
+
const agent = new TaskManager(task, storage, abortSignal, logger, auth);
|
|
1906
1916
|
agent.startTimeout();
|
|
1907
1917
|
return agent;
|
|
1908
1918
|
}
|
|
@@ -1975,6 +1985,17 @@ class TaskManager {
|
|
|
1975
1985
|
}
|
|
1976
1986
|
}, 1e3);
|
|
1977
1987
|
}
|
|
1988
|
+
async getInitiatorCredentials() {
|
|
1989
|
+
if (this.task.secrets && "__initiatorCredentials" in this.task.secrets) {
|
|
1990
|
+
return JSON.parse(this.task.secrets.__initiatorCredentials);
|
|
1991
|
+
}
|
|
1992
|
+
if (!this.auth) {
|
|
1993
|
+
throw new Error(
|
|
1994
|
+
"Failed to create none credentials in scaffolder task. The TaskManager has not been initialized with an auth service implementation"
|
|
1995
|
+
);
|
|
1996
|
+
}
|
|
1997
|
+
return this.auth.getNoneCredentials();
|
|
1998
|
+
}
|
|
1978
1999
|
}
|
|
1979
2000
|
function defer() {
|
|
1980
2001
|
let resolve = () => {
|
|
@@ -1985,10 +2006,11 @@ function defer() {
|
|
|
1985
2006
|
return { promise, resolve };
|
|
1986
2007
|
}
|
|
1987
2008
|
class StorageTaskBroker {
|
|
1988
|
-
constructor(storage, logger, config) {
|
|
2009
|
+
constructor(storage, logger, config, auth) {
|
|
1989
2010
|
this.storage = storage;
|
|
1990
2011
|
this.logger = logger;
|
|
1991
2012
|
this.config = config;
|
|
2013
|
+
this.auth = auth;
|
|
1992
2014
|
__publicField$2(this, "deferredDispatch", defer());
|
|
1993
2015
|
}
|
|
1994
2016
|
async list(options) {
|
|
@@ -2059,7 +2081,8 @@ class StorageTaskBroker {
|
|
|
2059
2081
|
},
|
|
2060
2082
|
this.storage,
|
|
2061
2083
|
abortController.signal,
|
|
2062
|
-
this.logger
|
|
2084
|
+
this.logger,
|
|
2085
|
+
this.auth
|
|
2063
2086
|
);
|
|
2064
2087
|
}
|
|
2065
2088
|
await this.waitForDispatch();
|
|
@@ -2246,6 +2269,137 @@ const scaffolderActionRules = {
|
|
|
2246
2269
|
hasStringProperty
|
|
2247
2270
|
};
|
|
2248
2271
|
|
|
2272
|
+
var __accessCheck = (obj, member, msg) => {
|
|
2273
|
+
if (!member.has(obj))
|
|
2274
|
+
throw TypeError("Cannot " + msg);
|
|
2275
|
+
};
|
|
2276
|
+
var __privateGet = (obj, member, getter) => {
|
|
2277
|
+
__accessCheck(obj, member, "read from private field");
|
|
2278
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
2279
|
+
};
|
|
2280
|
+
var __privateAdd = (obj, member, value) => {
|
|
2281
|
+
if (member.has(obj))
|
|
2282
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
2283
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2284
|
+
};
|
|
2285
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
2286
|
+
__accessCheck(obj, member, "write to private field");
|
|
2287
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
2288
|
+
return value;
|
|
2289
|
+
};
|
|
2290
|
+
var _winston, _addRedactions;
|
|
2291
|
+
const escapeRegExp = (text) => {
|
|
2292
|
+
return text.replace(/[.*+?^${}(\)|[\]\\]/g, "\\$&");
|
|
2293
|
+
};
|
|
2294
|
+
const _WinstonLogger = class _WinstonLogger {
|
|
2295
|
+
constructor(winston, addRedactions) {
|
|
2296
|
+
__privateAdd(this, _winston, void 0);
|
|
2297
|
+
__privateAdd(this, _addRedactions, void 0);
|
|
2298
|
+
__privateSet(this, _winston, winston);
|
|
2299
|
+
__privateSet(this, _addRedactions, addRedactions);
|
|
2300
|
+
}
|
|
2301
|
+
/**
|
|
2302
|
+
* Creates a {@link WinstonLogger} instance.
|
|
2303
|
+
*/
|
|
2304
|
+
static create(options) {
|
|
2305
|
+
var _a;
|
|
2306
|
+
const redacter = _WinstonLogger.redacter();
|
|
2307
|
+
let logger = winston.createLogger({
|
|
2308
|
+
level: options.level,
|
|
2309
|
+
format: winston.format.combine(redacter.format, options.format),
|
|
2310
|
+
transports: (_a = options.transports) != null ? _a : new winston.transports.Console()
|
|
2311
|
+
});
|
|
2312
|
+
if (options.meta) {
|
|
2313
|
+
logger = logger.child(options.meta);
|
|
2314
|
+
}
|
|
2315
|
+
return new _WinstonLogger(logger, redacter.add);
|
|
2316
|
+
}
|
|
2317
|
+
/**
|
|
2318
|
+
* Creates a winston log formatter for redacting secrets.
|
|
2319
|
+
*/
|
|
2320
|
+
static redacter() {
|
|
2321
|
+
const redactionSet = /* @__PURE__ */ new Set();
|
|
2322
|
+
let redactionPattern = void 0;
|
|
2323
|
+
return {
|
|
2324
|
+
format: winston.format((info) => {
|
|
2325
|
+
if (redactionPattern && typeof info.message === "string") {
|
|
2326
|
+
info.message = info.message.replace(redactionPattern, "[REDACTED]");
|
|
2327
|
+
}
|
|
2328
|
+
if (redactionPattern && typeof info.stack === "string") {
|
|
2329
|
+
info.stack = info.stack.replace(redactionPattern, "[REDACTED]");
|
|
2330
|
+
}
|
|
2331
|
+
return info;
|
|
2332
|
+
})(),
|
|
2333
|
+
add(newRedactions) {
|
|
2334
|
+
let added = 0;
|
|
2335
|
+
for (const redactionToTrim of newRedactions) {
|
|
2336
|
+
const redaction = redactionToTrim.trim();
|
|
2337
|
+
if (redaction.length <= 1) {
|
|
2338
|
+
continue;
|
|
2339
|
+
}
|
|
2340
|
+
if (!redactionSet.has(redaction)) {
|
|
2341
|
+
redactionSet.add(redaction);
|
|
2342
|
+
added += 1;
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
if (added > 0) {
|
|
2346
|
+
const redactions = Array.from(redactionSet).map((r) => escapeRegExp(r)).join("|");
|
|
2347
|
+
redactionPattern = new RegExp(`(${redactions})`, "g");
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
/**
|
|
2353
|
+
* Creates a pretty printed winston log formatter.
|
|
2354
|
+
*/
|
|
2355
|
+
static colorFormat() {
|
|
2356
|
+
const colorizer = winston.format.colorize();
|
|
2357
|
+
return winston.format.combine(
|
|
2358
|
+
winston.format.timestamp(),
|
|
2359
|
+
winston.format.colorize({
|
|
2360
|
+
colors: {
|
|
2361
|
+
timestamp: "dim",
|
|
2362
|
+
prefix: "blue",
|
|
2363
|
+
field: "cyan",
|
|
2364
|
+
debug: "grey"
|
|
2365
|
+
}
|
|
2366
|
+
}),
|
|
2367
|
+
winston.format.printf((info) => {
|
|
2368
|
+
const { timestamp, level, message, plugin, service, ...fields } = info;
|
|
2369
|
+
const prefix = plugin || service;
|
|
2370
|
+
const timestampColor = colorizer.colorize("timestamp", timestamp);
|
|
2371
|
+
const prefixColor = colorizer.colorize("prefix", prefix);
|
|
2372
|
+
const extraFields = Object.entries(fields).map(
|
|
2373
|
+
([key, value]) => `${colorizer.colorize("field", `${key}`)}=${value}`
|
|
2374
|
+
).join(" ");
|
|
2375
|
+
return `${timestampColor} ${prefixColor} ${level} ${message} ${extraFields}`;
|
|
2376
|
+
})
|
|
2377
|
+
);
|
|
2378
|
+
}
|
|
2379
|
+
error(message, meta) {
|
|
2380
|
+
__privateGet(this, _winston).error(message, meta);
|
|
2381
|
+
}
|
|
2382
|
+
warn(message, meta) {
|
|
2383
|
+
__privateGet(this, _winston).warn(message, meta);
|
|
2384
|
+
}
|
|
2385
|
+
info(message, meta) {
|
|
2386
|
+
__privateGet(this, _winston).info(message, meta);
|
|
2387
|
+
}
|
|
2388
|
+
debug(message, meta) {
|
|
2389
|
+
__privateGet(this, _winston).debug(message, meta);
|
|
2390
|
+
}
|
|
2391
|
+
child(meta) {
|
|
2392
|
+
return new _WinstonLogger(__privateGet(this, _winston).child(meta));
|
|
2393
|
+
}
|
|
2394
|
+
addRedactions(redactions) {
|
|
2395
|
+
var _a;
|
|
2396
|
+
(_a = __privateGet(this, _addRedactions)) == null ? void 0 : _a.call(this, redactions);
|
|
2397
|
+
}
|
|
2398
|
+
};
|
|
2399
|
+
_winston = new WeakMap();
|
|
2400
|
+
_addRedactions = new WeakMap();
|
|
2401
|
+
let WinstonLogger = _WinstonLogger;
|
|
2402
|
+
|
|
2249
2403
|
var __defProp$1 = Object.defineProperty;
|
|
2250
2404
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2251
2405
|
var __publicField$1 = (obj, key, value) => {
|
|
@@ -2259,23 +2413,33 @@ const createStepLogger = ({
|
|
|
2259
2413
|
task,
|
|
2260
2414
|
step
|
|
2261
2415
|
}) => {
|
|
2262
|
-
|
|
2263
|
-
const
|
|
2416
|
+
var _a;
|
|
2417
|
+
const stepLogStream = new stream.PassThrough();
|
|
2418
|
+
stepLogStream.on("data", async (data) => {
|
|
2419
|
+
const message = data.toString().trim();
|
|
2420
|
+
if ((message == null ? void 0 : message.length) > 1) {
|
|
2421
|
+
await task.emitLog(message, { stepId: step.id });
|
|
2422
|
+
}
|
|
2423
|
+
});
|
|
2424
|
+
const taskLogger = WinstonLogger.create({
|
|
2264
2425
|
level: process.env.LOG_LEVEL || "info",
|
|
2265
2426
|
format: winston__namespace.format.combine(
|
|
2266
2427
|
winston__namespace.format.colorize(),
|
|
2267
2428
|
winston__namespace.format.simple()
|
|
2268
2429
|
),
|
|
2269
|
-
|
|
2430
|
+
transports: [
|
|
2431
|
+
new winston__namespace.transports.Console(),
|
|
2432
|
+
new winston__namespace.transports.Stream({ stream: stepLogStream })
|
|
2433
|
+
]
|
|
2270
2434
|
});
|
|
2435
|
+
taskLogger.addRedactions(Object.values((_a = task.secrets) != null ? _a : {}));
|
|
2271
2436
|
const streamLogger = new stream.PassThrough();
|
|
2272
2437
|
streamLogger.on("data", async (data) => {
|
|
2273
2438
|
const message = data.toString().trim();
|
|
2274
2439
|
if ((message == null ? void 0 : message.length) > 1) {
|
|
2275
|
-
|
|
2440
|
+
taskLogger.info(message);
|
|
2276
2441
|
}
|
|
2277
2442
|
});
|
|
2278
|
-
taskLogger.add(new winston__namespace.transports.Stream({ stream: streamLogger }));
|
|
2279
2443
|
return { taskLogger, streamLogger };
|
|
2280
2444
|
};
|
|
2281
2445
|
const isActionAuthorized = pluginPermissionNode.createConditionAuthorizer(
|
|
@@ -2449,7 +2613,8 @@ class NunjucksWorkflowRunner {
|
|
|
2449
2613
|
await action.handler({
|
|
2450
2614
|
input: iteration.input,
|
|
2451
2615
|
secrets: (_f = task.secrets) != null ? _f : {},
|
|
2452
|
-
|
|
2616
|
+
// TODO(blam): move to LoggerService and away from Winston
|
|
2617
|
+
logger: backendCommon.loggerToWinstonLogger(taskLogger),
|
|
2453
2618
|
logStream: streamLogger,
|
|
2454
2619
|
workspacePath,
|
|
2455
2620
|
async checkpoint(keySuffix, fn) {
|
|
@@ -2499,7 +2664,8 @@ class NunjucksWorkflowRunner {
|
|
|
2499
2664
|
templateInfo: task.spec.templateInfo,
|
|
2500
2665
|
user: task.spec.user,
|
|
2501
2666
|
isDryRun: task.isDryRun,
|
|
2502
|
-
signal: task.cancelSignal
|
|
2667
|
+
signal: task.cancelSignal,
|
|
2668
|
+
getInitiatorCredentials: task.getInitiatorCredentials
|
|
2503
2669
|
});
|
|
2504
2670
|
}
|
|
2505
2671
|
for (const tmpDir of tmpDirs) {
|
|
@@ -2517,7 +2683,6 @@ class NunjucksWorkflowRunner {
|
|
|
2517
2683
|
}
|
|
2518
2684
|
}
|
|
2519
2685
|
async execute(task) {
|
|
2520
|
-
var _a;
|
|
2521
2686
|
if (!isValidTaskSpec(task.spec)) {
|
|
2522
2687
|
throw new errors.InputError(
|
|
2523
2688
|
"Wrong template version executed with the workflow engine"
|
|
@@ -2545,7 +2710,7 @@ class NunjucksWorkflowRunner {
|
|
|
2545
2710
|
};
|
|
2546
2711
|
const [decision] = this.options.permissions && task.spec.steps.length ? await this.options.permissions.authorizeConditional(
|
|
2547
2712
|
[{ permission: alpha.actionExecutePermission }],
|
|
2548
|
-
{
|
|
2713
|
+
{ credentials: await task.getInitiatorCredentials() }
|
|
2549
2714
|
) : [{ result: pluginPermissionCommon.AuthorizeResult.ALLOW }];
|
|
2550
2715
|
for (const step of task.spec.steps) {
|
|
2551
2716
|
await this.executeStep(
|
|
@@ -2868,6 +3033,7 @@ function createDryRunner(options) {
|
|
|
2868
3033
|
}
|
|
2869
3034
|
},
|
|
2870
3035
|
secrets: input.secrets,
|
|
3036
|
+
getInitiatorCredentials: () => Promise.resolve(input.credentials),
|
|
2871
3037
|
// No need to update this at the end of the run, so just hard-code it
|
|
2872
3038
|
done: false,
|
|
2873
3039
|
isDryRun: true,
|
|
@@ -3026,17 +3192,23 @@ async function createRouter(options) {
|
|
|
3026
3192
|
additionalTemplateFilters,
|
|
3027
3193
|
additionalTemplateGlobals,
|
|
3028
3194
|
permissions,
|
|
3029
|
-
permissionRules
|
|
3195
|
+
permissionRules,
|
|
3196
|
+
discovery = backendCommon.HostDiscovery.fromConfig(config),
|
|
3197
|
+
identity = buildDefaultIdentityClient(options)
|
|
3030
3198
|
} = options;
|
|
3199
|
+
const { auth, httpAuth } = backendCommon.createLegacyAuthAdapters({
|
|
3200
|
+
...options,
|
|
3201
|
+
identity,
|
|
3202
|
+
discovery
|
|
3203
|
+
});
|
|
3031
3204
|
const concurrentTasksLimit = (_a = options.concurrentTasksLimit) != null ? _a : options.config.getOptionalNumber("scaffolder.concurrentTasksLimit");
|
|
3032
3205
|
const logger = parentLogger.child({ plugin: "scaffolder" });
|
|
3033
|
-
const identity = options.identity || buildDefaultIdentityClient(options);
|
|
3034
3206
|
const workingDirectory = await getWorkingDirectory(config, logger);
|
|
3035
3207
|
const integrations = integration.ScmIntegrations.fromConfig(config);
|
|
3036
3208
|
let taskBroker;
|
|
3037
3209
|
if (!options.taskBroker) {
|
|
3038
3210
|
const databaseTaskStore = await DatabaseTaskStore.create({ database });
|
|
3039
|
-
taskBroker = new StorageTaskBroker(databaseTaskStore, logger, config);
|
|
3211
|
+
taskBroker = new StorageTaskBroker(databaseTaskStore, logger, config, auth);
|
|
3040
3212
|
if (scheduler && databaseTaskStore.listStaleTasks) {
|
|
3041
3213
|
await scheduler.scheduleTask({
|
|
3042
3214
|
id: "close_stale_tasks",
|
|
@@ -3090,7 +3262,8 @@ async function createRouter(options) {
|
|
|
3090
3262
|
reader,
|
|
3091
3263
|
config,
|
|
3092
3264
|
additionalTemplateFilters,
|
|
3093
|
-
additionalTemplateGlobals
|
|
3265
|
+
additionalTemplateGlobals,
|
|
3266
|
+
auth
|
|
3094
3267
|
});
|
|
3095
3268
|
actionsToRegister.forEach((action) => actionRegistry.register(action));
|
|
3096
3269
|
const launchWorkers = () => workers.forEach((worker) => worker.start());
|
|
@@ -3144,11 +3317,16 @@ async function createRouter(options) {
|
|
|
3144
3317
|
"/v2/templates/:namespace/:kind/:name/parameter-schema",
|
|
3145
3318
|
async (req, res) => {
|
|
3146
3319
|
var _a2, _b;
|
|
3147
|
-
const
|
|
3148
|
-
|
|
3320
|
+
const credentials = await httpAuth.credentials(req);
|
|
3321
|
+
const { token } = await auth.getPluginRequestToken({
|
|
3322
|
+
onBehalfOf: credentials,
|
|
3323
|
+
targetPluginId: "catalog"
|
|
3149
3324
|
});
|
|
3150
|
-
const
|
|
3151
|
-
|
|
3325
|
+
const template = await authorizeTemplate(
|
|
3326
|
+
req.params,
|
|
3327
|
+
token,
|
|
3328
|
+
credentials
|
|
3329
|
+
);
|
|
3152
3330
|
const parameters = [(_a2 = template.spec.parameters) != null ? _a2 : []].flat();
|
|
3153
3331
|
const presentation = template.spec.presentation;
|
|
3154
3332
|
res.json({
|
|
@@ -3182,11 +3360,12 @@ async function createRouter(options) {
|
|
|
3182
3360
|
const { kind, namespace, name } = catalogModel.parseEntityRef(templateRef, {
|
|
3183
3361
|
defaultKind: "template"
|
|
3184
3362
|
});
|
|
3185
|
-
const
|
|
3186
|
-
|
|
3363
|
+
const credentials = await httpAuth.credentials(req);
|
|
3364
|
+
const { token } = await auth.getPluginRequestToken({
|
|
3365
|
+
onBehalfOf: credentials,
|
|
3366
|
+
targetPluginId: "catalog"
|
|
3187
3367
|
});
|
|
3188
|
-
const
|
|
3189
|
-
const userEntityRef = callerIdentity == null ? void 0 : callerIdentity.identity.userEntityRef;
|
|
3368
|
+
const userEntityRef = auth.isPrincipal(credentials, "user") ? credentials.principal.userEntityRef : void 0;
|
|
3190
3369
|
const userEntity = userEntityRef ? await catalogClient.getEntityByRef(userEntityRef, { token }) : void 0;
|
|
3191
3370
|
let auditLog = `Scaffolding task for ${templateRef}`;
|
|
3192
3371
|
if (userEntityRef) {
|
|
@@ -3196,7 +3375,8 @@ async function createRouter(options) {
|
|
|
3196
3375
|
const values = req.body.values;
|
|
3197
3376
|
const template = await authorizeTemplate(
|
|
3198
3377
|
{ kind, namespace, name },
|
|
3199
|
-
token
|
|
3378
|
+
token,
|
|
3379
|
+
credentials
|
|
3200
3380
|
);
|
|
3201
3381
|
for (const parameters of [(_a2 = template.spec.parameters) != null ? _a2 : []].flat()) {
|
|
3202
3382
|
const result2 = jsonschema.validate(values, parameters);
|
|
@@ -3236,7 +3416,8 @@ async function createRouter(options) {
|
|
|
3236
3416
|
createdBy: userEntityRef,
|
|
3237
3417
|
secrets: {
|
|
3238
3418
|
...req.body.secrets,
|
|
3239
|
-
backstageToken: token
|
|
3419
|
+
backstageToken: token,
|
|
3420
|
+
initiatorCredentials: JSON.stringify(credentials)
|
|
3240
3421
|
}
|
|
3241
3422
|
});
|
|
3242
3423
|
res.status(201).json({ id: result.taskId });
|
|
@@ -3331,7 +3512,7 @@ data: ${JSON.stringify(event)}
|
|
|
3331
3512
|
clearTimeout(timeout);
|
|
3332
3513
|
});
|
|
3333
3514
|
}).post("/v2/dry-run", async (req, res) => {
|
|
3334
|
-
var _a2, _b, _c
|
|
3515
|
+
var _a2, _b, _c;
|
|
3335
3516
|
const bodySchema = zod.z.object({
|
|
3336
3517
|
template: zod.z.unknown(),
|
|
3337
3518
|
values: zod.z.record(zod.z.unknown()),
|
|
@@ -3347,10 +3528,12 @@ data: ${JSON.stringify(event)}
|
|
|
3347
3528
|
if (!await pluginScaffolderCommon.templateEntityV1beta3Validator.check(template)) {
|
|
3348
3529
|
throw new errors.InputError("Input template is not a template");
|
|
3349
3530
|
}
|
|
3350
|
-
const
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3531
|
+
const credentials = await httpAuth.credentials(req);
|
|
3532
|
+
const { token } = await auth.getPluginRequestToken({
|
|
3533
|
+
onBehalfOf: credentials,
|
|
3534
|
+
targetPluginId: "catalog"
|
|
3535
|
+
});
|
|
3536
|
+
for (const parameters of [(_a2 = template.spec.parameters) != null ? _a2 : []].flat()) {
|
|
3354
3537
|
const result2 = jsonschema.validate(body.values, parameters);
|
|
3355
3538
|
if (!result2.valid) {
|
|
3356
3539
|
res.status(400).json({ errors: result2.errors });
|
|
@@ -3369,17 +3552,18 @@ data: ${JSON.stringify(event)}
|
|
|
3369
3552
|
spec: {
|
|
3370
3553
|
apiVersion: template.apiVersion,
|
|
3371
3554
|
steps,
|
|
3372
|
-
output: (
|
|
3555
|
+
output: (_b = template.spec.output) != null ? _b : {},
|
|
3373
3556
|
parameters: body.values
|
|
3374
3557
|
},
|
|
3375
|
-
directoryContents: ((
|
|
3558
|
+
directoryContents: ((_c = body.directoryContents) != null ? _c : []).map((file) => ({
|
|
3376
3559
|
path: file.path,
|
|
3377
3560
|
content: Buffer.from(file.base64Content, "base64")
|
|
3378
3561
|
})),
|
|
3379
3562
|
secrets: {
|
|
3380
3563
|
...body.secrets,
|
|
3381
3564
|
...token && { backstageToken: token }
|
|
3382
|
-
}
|
|
3565
|
+
},
|
|
3566
|
+
credentials
|
|
3383
3567
|
});
|
|
3384
3568
|
res.status(200).json({
|
|
3385
3569
|
...result,
|
|
@@ -3394,7 +3578,7 @@ data: ${JSON.stringify(event)}
|
|
|
3394
3578
|
const app = express__default["default"]();
|
|
3395
3579
|
app.set("logger", logger);
|
|
3396
3580
|
app.use("/", router);
|
|
3397
|
-
async function authorizeTemplate(entityRef, token) {
|
|
3581
|
+
async function authorizeTemplate(entityRef, token, credentials) {
|
|
3398
3582
|
const template = await findTemplate({
|
|
3399
3583
|
catalogApi: catalogClient,
|
|
3400
3584
|
entityRef,
|
|
@@ -3413,7 +3597,7 @@ data: ${JSON.stringify(event)}
|
|
|
3413
3597
|
{ permission: alpha.templateParameterReadPermission },
|
|
3414
3598
|
{ permission: alpha.templateStepReadPermission }
|
|
3415
3599
|
],
|
|
3416
|
-
{
|
|
3600
|
+
{ credentials }
|
|
3417
3601
|
);
|
|
3418
3602
|
if (Array.isArray(template.spec.parameters)) {
|
|
3419
3603
|
template.spec.parameters = template.spec.parameters.filter(
|
|
@@ -3448,4 +3632,4 @@ exports.createRouter = createRouter;
|
|
|
3448
3632
|
exports.createWaitAction = createWaitAction;
|
|
3449
3633
|
exports.scaffolderActionRules = scaffolderActionRules;
|
|
3450
3634
|
exports.scaffolderTemplateRules = scaffolderTemplateRules;
|
|
3451
|
-
//# sourceMappingURL=router-
|
|
3635
|
+
//# sourceMappingURL=router-52d79583.cjs.js.map
|