@backstage/plugin-scaffolder-backend 1.12.0-next.1 → 1.12.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 +49 -0
- package/README.md +1 -1
- package/alpha/package.json +1 -1
- package/dist/alpha.cjs.js +71 -26
- package/dist/alpha.cjs.js.map +1 -1
- package/dist/index.cjs.js +71 -26
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/package.json +16 -16
package/dist/index.cjs.js
CHANGED
|
@@ -256,7 +256,7 @@ function createCatalogWriteAction() {
|
|
|
256
256
|
input: zod.z.object({
|
|
257
257
|
filePath: zod.z.string().optional().describe("Defaults to catalog-info.yaml"),
|
|
258
258
|
// TODO: this should reference an zod entity validator if it existed.
|
|
259
|
-
entity: zod.z.object({}).describe(
|
|
259
|
+
entity: zod.z.object({}).passthrough().describe(
|
|
260
260
|
"You can provide the same values used in the Entity schema."
|
|
261
261
|
)
|
|
262
262
|
})
|
|
@@ -291,17 +291,31 @@ const examples$1 = [
|
|
|
291
291
|
}
|
|
292
292
|
]
|
|
293
293
|
})
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
description: "Fetch multiple entities by referencse",
|
|
297
|
+
example: yaml__default["default"].stringify({
|
|
298
|
+
steps: [
|
|
299
|
+
{
|
|
300
|
+
action: id$1,
|
|
301
|
+
id: "fetchMultiple",
|
|
302
|
+
name: "Fetch catalog entities",
|
|
303
|
+
input: {
|
|
304
|
+
entityRefs: ["component:default/name"]
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
})
|
|
294
309
|
}
|
|
295
310
|
];
|
|
296
311
|
function createFetchCatalogEntityAction(options) {
|
|
297
312
|
const { catalogClient } = options;
|
|
298
313
|
return pluginScaffolderNode.createTemplateAction({
|
|
299
314
|
id: id$1,
|
|
300
|
-
description: "Returns entity from the catalog by entity reference",
|
|
315
|
+
description: "Returns entity or entities from the catalog by entity reference(s)",
|
|
301
316
|
examples: examples$1,
|
|
302
317
|
schema: {
|
|
303
318
|
input: {
|
|
304
|
-
required: ["entityRef"],
|
|
305
319
|
type: "object",
|
|
306
320
|
properties: {
|
|
307
321
|
entityRef: {
|
|
@@ -309,9 +323,14 @@ function createFetchCatalogEntityAction(options) {
|
|
|
309
323
|
title: "Entity reference",
|
|
310
324
|
description: "Entity reference of the entity to get"
|
|
311
325
|
},
|
|
326
|
+
entityRefs: {
|
|
327
|
+
type: "array",
|
|
328
|
+
title: "Entity references",
|
|
329
|
+
description: "Entity references of the entities to get"
|
|
330
|
+
},
|
|
312
331
|
optional: {
|
|
313
332
|
title: "Optional",
|
|
314
|
-
description: "
|
|
333
|
+
description: "Allow the entity or entities to optionally exist. Default: false",
|
|
315
334
|
type: "boolean"
|
|
316
335
|
}
|
|
317
336
|
}
|
|
@@ -322,28 +341,50 @@ function createFetchCatalogEntityAction(options) {
|
|
|
322
341
|
entity: {
|
|
323
342
|
title: "Entity found by the entity reference",
|
|
324
343
|
type: "object",
|
|
325
|
-
description: "Object containing same values used in the Entity schema."
|
|
344
|
+
description: "Object containing same values used in the Entity schema. Only when used with `entityRef` parameter."
|
|
345
|
+
},
|
|
346
|
+
entities: {
|
|
347
|
+
title: "Entities found by the entity references",
|
|
348
|
+
type: "array",
|
|
349
|
+
items: { type: "object" },
|
|
350
|
+
description: "Array containing objects with same values used in the Entity schema. Only when used with `entityRefs` parameter."
|
|
326
351
|
}
|
|
327
352
|
}
|
|
328
353
|
}
|
|
329
354
|
},
|
|
330
355
|
async handler(ctx) {
|
|
331
|
-
var _a;
|
|
332
|
-
const { entityRef, optional } = ctx.input;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
356
|
+
var _a, _b;
|
|
357
|
+
const { entityRef, entityRefs, optional } = ctx.input;
|
|
358
|
+
if (!entityRef && !entityRefs) {
|
|
359
|
+
if (optional) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
throw new Error("Missing entity reference or references");
|
|
363
|
+
}
|
|
364
|
+
if (entityRef) {
|
|
365
|
+
const entity = await catalogClient.getEntityByRef(entityRef, {
|
|
336
366
|
token: (_a = ctx.secrets) == null ? void 0 : _a.backstageToken
|
|
337
367
|
});
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
throw e;
|
|
368
|
+
if (!entity && !optional) {
|
|
369
|
+
throw new Error(`Entity ${entityRef} not found`);
|
|
341
370
|
}
|
|
371
|
+
ctx.output("entity", entity != null ? entity : null);
|
|
342
372
|
}
|
|
343
|
-
if (
|
|
344
|
-
|
|
373
|
+
if (entityRefs) {
|
|
374
|
+
const entities = await catalogClient.getEntitiesByRefs(
|
|
375
|
+
{ entityRefs },
|
|
376
|
+
{
|
|
377
|
+
token: (_b = ctx.secrets) == null ? void 0 : _b.backstageToken
|
|
378
|
+
}
|
|
379
|
+
);
|
|
380
|
+
const finalEntities = entities.items.map((e, i) => {
|
|
381
|
+
if (!e && !optional) {
|
|
382
|
+
throw new Error(`Entity ${entityRefs[i]} not found`);
|
|
383
|
+
}
|
|
384
|
+
return e != null ? e : null;
|
|
385
|
+
});
|
|
386
|
+
ctx.output("entities", finalEntities);
|
|
345
387
|
}
|
|
346
|
-
ctx.output("entity", entity != null ? entity : null);
|
|
347
388
|
}
|
|
348
389
|
});
|
|
349
390
|
}
|
|
@@ -3486,11 +3527,12 @@ const defaultClientFactory = async ({
|
|
|
3486
3527
|
...{ throttle: { enabled: false } }
|
|
3487
3528
|
});
|
|
3488
3529
|
};
|
|
3489
|
-
const createPublishGithubPullRequestAction = ({
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3530
|
+
const createPublishGithubPullRequestAction = (options) => {
|
|
3531
|
+
const {
|
|
3532
|
+
integrations,
|
|
3533
|
+
githubCredentialsProvider,
|
|
3534
|
+
clientFactory = defaultClientFactory
|
|
3535
|
+
} = options;
|
|
3494
3536
|
return pluginScaffolderNode.createTemplateAction({
|
|
3495
3537
|
id: "publish:github:pull-request",
|
|
3496
3538
|
schema: {
|
|
@@ -4386,7 +4428,8 @@ class DatabaseTaskStore {
|
|
|
4386
4428
|
});
|
|
4387
4429
|
return { events };
|
|
4388
4430
|
}
|
|
4389
|
-
async shutdownTask(
|
|
4431
|
+
async shutdownTask(options) {
|
|
4432
|
+
const { taskId } = options;
|
|
4390
4433
|
const message = `This task was marked as stale as it exceeded its timeout`;
|
|
4391
4434
|
const statusStepEvents = (await this.listEvents({ taskId })).events.filter(
|
|
4392
4435
|
({ body }) => body == null ? void 0 : body.stepId
|
|
@@ -5191,13 +5234,12 @@ async function findTemplate(options) {
|
|
|
5191
5234
|
function isSupportedTemplate(entity) {
|
|
5192
5235
|
return entity.apiVersion === "scaffolder.backstage.io/v1beta3";
|
|
5193
5236
|
}
|
|
5194
|
-
function buildDefaultIdentityClient({
|
|
5195
|
-
logger
|
|
5196
|
-
}) {
|
|
5237
|
+
function buildDefaultIdentityClient(options) {
|
|
5197
5238
|
return {
|
|
5198
5239
|
getIdentity: async ({ request }) => {
|
|
5199
5240
|
var _a;
|
|
5200
5241
|
const header = request.headers.authorization;
|
|
5242
|
+
const { logger } = options;
|
|
5201
5243
|
if (!header) {
|
|
5202
5244
|
return void 0;
|
|
5203
5245
|
}
|
|
@@ -5217,6 +5259,9 @@ function buildDefaultIdentityClient({
|
|
|
5217
5259
|
if (typeof sub !== "string") {
|
|
5218
5260
|
throw new TypeError("Expected string sub claim");
|
|
5219
5261
|
}
|
|
5262
|
+
if (sub === "backstage-server") {
|
|
5263
|
+
return void 0;
|
|
5264
|
+
}
|
|
5220
5265
|
catalogModel.parseEntityRef(sub);
|
|
5221
5266
|
return {
|
|
5222
5267
|
identity: {
|
|
@@ -5250,7 +5295,7 @@ async function createRouter(options) {
|
|
|
5250
5295
|
additionalTemplateGlobals
|
|
5251
5296
|
} = options;
|
|
5252
5297
|
const logger = parentLogger.child({ plugin: "scaffolder" });
|
|
5253
|
-
const identity = options.identity || buildDefaultIdentityClient(
|
|
5298
|
+
const identity = options.identity || buildDefaultIdentityClient(options);
|
|
5254
5299
|
const workingDirectory = await getWorkingDirectory(config, logger);
|
|
5255
5300
|
const integrations = integration.ScmIntegrations.fromConfig(config);
|
|
5256
5301
|
let taskBroker;
|