@backstage/plugin-scaffolder-backend 1.26.0-next.1 → 1.26.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 +31 -0
- package/alpha/package.json +1 -1
- package/dist/ScaffolderPlugin.cjs.js +168 -0
- package/dist/ScaffolderPlugin.cjs.js.map +1 -0
- package/dist/alpha.cjs.js +7 -196
- package/dist/alpha.cjs.js.map +1 -1
- package/dist/deprecated.cjs.js +15 -0
- package/dist/deprecated.cjs.js.map +1 -0
- package/dist/index.cjs.js +57 -134
- package/dist/index.cjs.js.map +1 -1
- package/dist/lib/templating/SecureTemplater.cjs.js +169 -0
- package/dist/lib/templating/SecureTemplater.cjs.js.map +1 -0
- package/dist/lib/templating/filters.cjs.js +26 -0
- package/dist/lib/templating/filters.cjs.js.map +1 -0
- package/dist/lib/templating/helpers.cjs.js +13 -0
- package/dist/lib/templating/helpers.cjs.js.map +1 -0
- package/dist/scaffolder/actions/TemplateActionRegistry.cjs.js +30 -0
- package/dist/scaffolder/actions/TemplateActionRegistry.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js +93 -0
- package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/catalog/fetch.examples.cjs.js +43 -0
- package/dist/scaffolder/actions/builtin/catalog/fetch.examples.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/catalog/register.cjs.js +142 -0
- package/dist/scaffolder/actions/builtin/catalog/register.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/catalog/register.examples.cjs.js +28 -0
- package/dist/scaffolder/actions/builtin/catalog/register.examples.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/catalog/write.cjs.js +74 -0
- package/dist/scaffolder/actions/builtin/catalog/write.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/catalog/write.examples.cjs.js +56 -0
- package/dist/scaffolder/actions/builtin/catalog/write.examples.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js +156 -0
- package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/debug/log.cjs.js +66 -0
- package/dist/scaffolder/actions/builtin/debug/log.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/debug/log.examples.cjs.js +58 -0
- package/dist/scaffolder/actions/builtin/debug/log.examples.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/debug/wait.cjs.js +66 -0
- package/dist/scaffolder/actions/builtin/debug/wait.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/debug/wait.examples.cjs.js +58 -0
- package/dist/scaffolder/actions/builtin/debug/wait.examples.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js +56 -0
- package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/fetch/plain.examples.cjs.js +44 -0
- package/dist/scaffolder/actions/builtin/fetch/plain.examples.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js +56 -0
- package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/fetch/plainFile.examples.cjs.js +29 -0
- package/dist/scaffolder/actions/builtin/fetch/plainFile.examples.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/fetch/template.cjs.js +241 -0
- package/dist/scaffolder/actions/builtin/fetch/template.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/fetch/template.examples.cjs.js +35 -0
- package/dist/scaffolder/actions/builtin/fetch/template.examples.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js +119 -0
- package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/fetch/templateFile.examples.cjs.js +34 -0
- package/dist/scaffolder/actions/builtin/fetch/templateFile.examples.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js +54 -0
- package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/filesystem/delete.examples.cjs.js +44 -0
- package/dist/scaffolder/actions/builtin/filesystem/delete.examples.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js +83 -0
- package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js.map +1 -0
- package/dist/scaffolder/actions/builtin/filesystem/rename.examples.cjs.js +48 -0
- package/dist/scaffolder/actions/builtin/filesystem/rename.examples.cjs.js.map +1 -0
- package/dist/scaffolder/actions/deprecated.cjs.js +74 -0
- package/dist/scaffolder/actions/deprecated.cjs.js.map +1 -0
- package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js +57 -0
- package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js.map +1 -0
- package/dist/scaffolder/dryrun/createDryRunner.cjs.js +97 -0
- package/dist/scaffolder/dryrun/createDryRunner.cjs.js.map +1 -0
- package/dist/scaffolder/tasks/DatabaseTaskStore.cjs.js +430 -0
- package/dist/scaffolder/tasks/DatabaseTaskStore.cjs.js.map +1 -0
- package/dist/scaffolder/tasks/DatabaseWorkspaceProvider.cjs.js +22 -0
- package/dist/scaffolder/tasks/DatabaseWorkspaceProvider.cjs.js.map +1 -0
- package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js +545 -0
- package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js.map +1 -0
- package/dist/scaffolder/tasks/StorageTaskBroker.cjs.js +318 -0
- package/dist/scaffolder/tasks/StorageTaskBroker.cjs.js.map +1 -0
- package/dist/scaffolder/tasks/TaskWorker.cjs.js +110 -0
- package/dist/scaffolder/tasks/TaskWorker.cjs.js.map +1 -0
- package/dist/scaffolder/tasks/WorkspaceService.cjs.js +50 -0
- package/dist/scaffolder/tasks/WorkspaceService.cjs.js.map +1 -0
- package/dist/scaffolder/tasks/dbUtil.cjs.js +20 -0
- package/dist/scaffolder/tasks/dbUtil.cjs.js.map +1 -0
- package/dist/scaffolder/tasks/helper.cjs.js +46 -0
- package/dist/scaffolder/tasks/helper.cjs.js.map +1 -0
- package/dist/scaffolder/tasks/logger.cjs.js +156 -0
- package/dist/scaffolder/tasks/logger.cjs.js.map +1 -0
- package/dist/scaffolder/tasks/taskRecoveryHelper.cjs.js +18 -0
- package/dist/scaffolder/tasks/taskRecoveryHelper.cjs.js.map +1 -0
- package/dist/service/conditionExports.cjs.js +26 -0
- package/dist/service/conditionExports.cjs.js.map +1 -0
- package/dist/service/helpers.cjs.js +92 -0
- package/dist/service/helpers.cjs.js.map +1 -0
- package/dist/service/router.cjs.js +640 -0
- package/dist/service/router.cjs.js.map +1 -0
- package/dist/service/rules.cjs.js +97 -0
- package/dist/service/rules.cjs.js.map +1 -0
- package/dist/util/checkPermissions.cjs.js +25 -0
- package/dist/util/checkPermissions.cjs.js.map +1 -0
- package/dist/util/metrics.cjs.js +24 -0
- package/dist/util/metrics.cjs.js.map +1 -0
- package/package.json +24 -24
- package/dist/cjs/router-BqZK9yax.cjs.js +0 -4101
- package/dist/cjs/router-BqZK9yax.cjs.js.map +0 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var yaml = require('yaml');
|
|
4
|
+
|
|
5
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var yaml__default = /*#__PURE__*/_interopDefaultCompat(yaml);
|
|
8
|
+
|
|
9
|
+
const examples = [
|
|
10
|
+
{
|
|
11
|
+
description: "Fetch entity by reference",
|
|
12
|
+
example: yaml__default.default.stringify({
|
|
13
|
+
steps: [
|
|
14
|
+
{
|
|
15
|
+
action: "catalog:fetch",
|
|
16
|
+
id: "fetch",
|
|
17
|
+
name: "Fetch catalog entity",
|
|
18
|
+
input: {
|
|
19
|
+
entityRef: "component:default/name"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
})
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
description: "Fetch multiple entities by reference",
|
|
27
|
+
example: yaml__default.default.stringify({
|
|
28
|
+
steps: [
|
|
29
|
+
{
|
|
30
|
+
action: "catalog:fetch",
|
|
31
|
+
id: "fetchMultiple",
|
|
32
|
+
name: "Fetch catalog entities",
|
|
33
|
+
input: {
|
|
34
|
+
entityRefs: ["component:default/name"]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
exports.examples = examples;
|
|
43
|
+
//# sourceMappingURL=fetch.examples.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.examples.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/fetch.examples.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description: 'Fetch entity by reference',\n example: yaml.stringify({\n steps: [\n {\n action: 'catalog:fetch',\n id: 'fetch',\n name: 'Fetch catalog entity',\n input: {\n entityRef: 'component:default/name',\n },\n },\n ],\n }),\n },\n {\n description: 'Fetch multiple entities by reference',\n example: yaml.stringify({\n steps: [\n {\n action: 'catalog:fetch',\n id: 'fetchMultiple',\n name: 'Fetch catalog entities',\n input: {\n entityRefs: ['component:default/name'],\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WAAa,EAAA,2BAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,MAAQ,EAAA,eAAA;AAAA,UACR,EAAI,EAAA,OAAA;AAAA,UACJ,IAAM,EAAA,sBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,SAAW,EAAA,wBAAA;AAAA,WACb;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAa,EAAA,sCAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,MAAQ,EAAA,eAAA;AAAA,UACR,EAAI,EAAA,eAAA;AAAA,UACJ,IAAM,EAAA,wBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,UAAA,EAAY,CAAC,wBAAwB,CAAA;AAAA,WACvC;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA;AAAA,GACH;AACF;;;;"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var errors = require('@backstage/errors');
|
|
4
|
+
var catalogModel = require('@backstage/catalog-model');
|
|
5
|
+
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
6
|
+
var register_examples = require('./register.examples.cjs.js');
|
|
7
|
+
|
|
8
|
+
const id = "catalog:register";
|
|
9
|
+
function createCatalogRegisterAction(options) {
|
|
10
|
+
const { catalogClient, integrations, auth } = options;
|
|
11
|
+
return pluginScaffolderNode.createTemplateAction({
|
|
12
|
+
id,
|
|
13
|
+
description: "Registers entities from a catalog descriptor file in the workspace into the software catalog.",
|
|
14
|
+
examples: register_examples.examples,
|
|
15
|
+
schema: {
|
|
16
|
+
input: {
|
|
17
|
+
oneOf: [
|
|
18
|
+
{
|
|
19
|
+
type: "object",
|
|
20
|
+
required: ["catalogInfoUrl"],
|
|
21
|
+
properties: {
|
|
22
|
+
catalogInfoUrl: {
|
|
23
|
+
title: "Catalog Info URL",
|
|
24
|
+
description: "An absolute URL pointing to the catalog info file location",
|
|
25
|
+
type: "string"
|
|
26
|
+
},
|
|
27
|
+
optional: {
|
|
28
|
+
title: "Optional",
|
|
29
|
+
description: "Permit the registered location to optionally exist. Default: false",
|
|
30
|
+
type: "boolean"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
type: "object",
|
|
36
|
+
required: ["repoContentsUrl"],
|
|
37
|
+
properties: {
|
|
38
|
+
repoContentsUrl: {
|
|
39
|
+
title: "Repository Contents URL",
|
|
40
|
+
description: "An absolute URL pointing to the root of a repository directory tree",
|
|
41
|
+
type: "string"
|
|
42
|
+
},
|
|
43
|
+
catalogInfoPath: {
|
|
44
|
+
title: "Fetch URL",
|
|
45
|
+
description: "A relative path from the repo root pointing to the catalog info file, defaults to /catalog-info.yaml",
|
|
46
|
+
type: "string"
|
|
47
|
+
},
|
|
48
|
+
optional: {
|
|
49
|
+
title: "Optional",
|
|
50
|
+
description: "Permit the registered location to optionally exist. Default: false",
|
|
51
|
+
type: "boolean"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
output: {
|
|
58
|
+
type: "object",
|
|
59
|
+
required: ["catalogInfoUrl"],
|
|
60
|
+
properties: {
|
|
61
|
+
entityRef: {
|
|
62
|
+
type: "string"
|
|
63
|
+
},
|
|
64
|
+
catalogInfoUrl: {
|
|
65
|
+
type: "string"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
async handler(ctx) {
|
|
71
|
+
const { input } = ctx;
|
|
72
|
+
let catalogInfoUrl;
|
|
73
|
+
if ("catalogInfoUrl" in input) {
|
|
74
|
+
catalogInfoUrl = input.catalogInfoUrl;
|
|
75
|
+
} else {
|
|
76
|
+
const { repoContentsUrl, catalogInfoPath = "/catalog-info.yaml" } = input;
|
|
77
|
+
const integration = integrations.byUrl(repoContentsUrl);
|
|
78
|
+
if (!integration) {
|
|
79
|
+
throw new errors.InputError(
|
|
80
|
+
`No integration found for host ${repoContentsUrl}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
catalogInfoUrl = integration.resolveUrl({
|
|
84
|
+
base: repoContentsUrl,
|
|
85
|
+
url: catalogInfoPath
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
ctx.logger.info(`Registering ${catalogInfoUrl} in the catalog`);
|
|
89
|
+
const { token } = await auth?.getPluginRequestToken({
|
|
90
|
+
onBehalfOf: await ctx.getInitiatorCredentials(),
|
|
91
|
+
targetPluginId: "catalog"
|
|
92
|
+
}) ?? { token: ctx.secrets?.backstageToken };
|
|
93
|
+
try {
|
|
94
|
+
await catalogClient.addLocation(
|
|
95
|
+
{
|
|
96
|
+
type: "url",
|
|
97
|
+
target: catalogInfoUrl
|
|
98
|
+
},
|
|
99
|
+
token ? { token } : {}
|
|
100
|
+
);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
if (!input.optional) {
|
|
103
|
+
throw e;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const result = await catalogClient.addLocation(
|
|
108
|
+
{
|
|
109
|
+
dryRun: true,
|
|
110
|
+
type: "url",
|
|
111
|
+
target: catalogInfoUrl
|
|
112
|
+
},
|
|
113
|
+
token ? { token } : {}
|
|
114
|
+
);
|
|
115
|
+
if (result.entities.length) {
|
|
116
|
+
const { entities } = result;
|
|
117
|
+
let entity;
|
|
118
|
+
entity = entities.find(
|
|
119
|
+
(e) => !e.metadata.name.startsWith("generated-") && e.kind === "Component"
|
|
120
|
+
);
|
|
121
|
+
if (!entity) {
|
|
122
|
+
entity = entities.find(
|
|
123
|
+
(e) => !e.metadata.name.startsWith("generated-")
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (!entity) {
|
|
127
|
+
entity = entities[0];
|
|
128
|
+
}
|
|
129
|
+
ctx.output("entityRef", catalogModel.stringifyEntityRef(entity));
|
|
130
|
+
}
|
|
131
|
+
} catch (e) {
|
|
132
|
+
if (!input.optional) {
|
|
133
|
+
throw e;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
ctx.output("catalogInfoUrl", catalogInfoUrl);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
exports.createCatalogRegisterAction = createCatalogRegisterAction;
|
|
142
|
+
//# sourceMappingURL=register.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/register.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { CatalogApi } from '@backstage/catalog-client';\nimport { stringifyEntityRef, Entity } from '@backstage/catalog-model';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { examples } from './register.examples';\nimport { AuthService } from '@backstage/backend-plugin-api';\n\nconst id = 'catalog:register';\n\n/**\n * Registers entities from a catalog descriptor file in the workspace into the software catalog.\n * @public\n */\nexport function createCatalogRegisterAction(options: {\n catalogClient: CatalogApi;\n integrations: ScmIntegrations;\n auth?: AuthService;\n}) {\n const { catalogClient, integrations, auth } = options;\n\n return createTemplateAction<\n | { catalogInfoUrl: string; optional?: boolean }\n | { repoContentsUrl: string; catalogInfoPath?: string; optional?: boolean }\n >({\n id,\n description:\n 'Registers entities from a catalog descriptor file in the workspace into the software catalog.',\n examples,\n schema: {\n input: {\n oneOf: [\n {\n type: 'object',\n required: ['catalogInfoUrl'],\n properties: {\n catalogInfoUrl: {\n title: 'Catalog Info URL',\n description:\n 'An absolute URL pointing to the catalog info file location',\n type: 'string',\n },\n optional: {\n title: 'Optional',\n description:\n 'Permit the registered location to optionally exist. Default: false',\n type: 'boolean',\n },\n },\n },\n {\n type: 'object',\n required: ['repoContentsUrl'],\n properties: {\n repoContentsUrl: {\n title: 'Repository Contents URL',\n description:\n 'An absolute URL pointing to the root of a repository directory tree',\n type: 'string',\n },\n catalogInfoPath: {\n title: 'Fetch URL',\n description:\n 'A relative path from the repo root pointing to the catalog info file, defaults to /catalog-info.yaml',\n type: 'string',\n },\n optional: {\n title: 'Optional',\n description:\n 'Permit the registered location to optionally exist. Default: false',\n type: 'boolean',\n },\n },\n },\n ],\n },\n output: {\n type: 'object',\n required: ['catalogInfoUrl'],\n properties: {\n entityRef: {\n type: 'string',\n },\n catalogInfoUrl: {\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const { input } = ctx;\n\n let catalogInfoUrl;\n if ('catalogInfoUrl' in input) {\n catalogInfoUrl = input.catalogInfoUrl;\n } else {\n const { repoContentsUrl, catalogInfoPath = '/catalog-info.yaml' } =\n input;\n const integration = integrations.byUrl(repoContentsUrl);\n if (!integration) {\n throw new InputError(\n `No integration found for host ${repoContentsUrl}`,\n );\n }\n\n catalogInfoUrl = integration.resolveUrl({\n base: repoContentsUrl,\n url: catalogInfoPath,\n });\n }\n\n ctx.logger.info(`Registering ${catalogInfoUrl} in the catalog`);\n\n const { token } = (await auth?.getPluginRequestToken({\n onBehalfOf: await ctx.getInitiatorCredentials(),\n targetPluginId: 'catalog',\n })) ?? { token: ctx.secrets?.backstageToken };\n\n try {\n // 1st try to register the location, this will throw an error if the location already exists (see catch)\n await catalogClient.addLocation(\n {\n type: 'url',\n target: catalogInfoUrl,\n },\n token ? { token } : {},\n );\n } catch (e) {\n if (!input.optional) {\n // if optional is false or unset, it is not allowed to register the same location twice, we rethrow the error\n throw e;\n }\n }\n\n try {\n // 2nd retry the registration as a dry run, this will not throw an error if the location already exists\n const result = await catalogClient.addLocation(\n {\n dryRun: true,\n type: 'url',\n target: catalogInfoUrl,\n },\n token ? { token } : {},\n );\n\n if (result.entities.length) {\n const { entities } = result;\n let entity: Entity | undefined;\n // prioritise 'Component' type as it is the most central kind of entity\n entity = entities.find(\n e =>\n !e.metadata.name.startsWith('generated-') &&\n e.kind === 'Component',\n );\n if (!entity) {\n entity = entities.find(\n e => !e.metadata.name.startsWith('generated-'),\n );\n }\n if (!entity) {\n entity = entities[0];\n }\n\n ctx.output('entityRef', stringifyEntityRef(entity));\n }\n } catch (e) {\n if (!input.optional) {\n throw e;\n }\n }\n\n ctx.output('catalogInfoUrl', catalogInfoUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","InputError","stringifyEntityRef"],"mappings":";;;;;;;AAwBA,MAAM,EAAK,GAAA,kBAAA,CAAA;AAMJ,SAAS,4BAA4B,OAIzC,EAAA;AACD,EAAA,MAAM,EAAE,aAAA,EAAe,YAAc,EAAA,IAAA,EAAS,GAAA,OAAA,CAAA;AAE9C,EAAA,OAAOA,yCAGL,CAAA;AAAA,IACA,EAAA;AAAA,IACA,WACE,EAAA,+FAAA;AAAA,cACFC,0BAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,KAAO,EAAA;AAAA,UACL;AAAA,YACE,IAAM,EAAA,QAAA;AAAA,YACN,QAAA,EAAU,CAAC,gBAAgB,CAAA;AAAA,YAC3B,UAAY,EAAA;AAAA,cACV,cAAgB,EAAA;AAAA,gBACd,K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A;AAAA,YACR,IAAM,EAAA,KAAA;AAAA,YACN,MAAQ,EAAA,cAAA;AAAA,WACV;AAAA,UACA,KAAQ,GAAA,EAAE,KAAM,EAAA,GAAI,EAAC;AAAA,SACvB,CAAA;AAEA,QAAI,IAAA,MAAA,CAAO,SAAS,MAAQ,EAAA;AAC1B,UAAM,MAAA,EAAE,UAAa,GAAA,MAAA,CAAA;AACrB,UAAI,IAAA,MAAA,CAAA;AAEJ,UAAA,MAAA,GAAS,QAAS,CAAA,IAAA;AAAA,YAChB,CAAA,CAAA,KACE,CAAC,CAAE,CAAA,QAAA,CAAS,KAAK,UAAW,CAAA,YAAY,CACxC,IAAA,CAAA,CAAE,IAAS,KAAA,WAAA;AAAA,WACf,CAAA;AACA,UAAA,IAAI,CAAC,MAAQ,EAAA;AACX,YAAA,MAAA,GAAS,QAAS,CAAA,IAAA;AAAA,cAChB,OAAK,CAAC,CAAA,CAAE,QAAS,CAAA,IAAA,CAAK,WAAW,YAAY,CAAA;AAAA,aAC/C,CAAA;AAAA,WACF;AACA,UAAA,IAAI,CAAC,MAAQ,EAAA;AACX,YAAA,MAAA,GAAS,SAAS,CAAC,CAAA,CAAA;AAAA,WACrB;AAEA,UAAA,GAAA,CAAI,MAAO,CAAA,WAAA,EAAaC,+BAAmB,CAAA,MAAM,CAAC,CAAA,CAAA;AAAA,SACpD;AAAA,eACO,CAAG,EAAA;AACV,QAAI,IAAA,CAAC,MAAM,QAAU,EAAA;AACnB,UAAM,MAAA,CAAA,CAAA;AAAA,SACR;AAAA,OACF;AAEA,MAAI,GAAA,CAAA,MAAA,CAAO,kBAAkB,cAAc,CAAA,CAAA;AAAA,KAC7C;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var yaml = require('yaml');
|
|
4
|
+
|
|
5
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var yaml__default = /*#__PURE__*/_interopDefaultCompat(yaml);
|
|
8
|
+
|
|
9
|
+
const examples = [
|
|
10
|
+
{
|
|
11
|
+
description: "Register with the catalog",
|
|
12
|
+
example: yaml__default.default.stringify({
|
|
13
|
+
steps: [
|
|
14
|
+
{
|
|
15
|
+
action: "catalog:register",
|
|
16
|
+
id: "register-with-catalog",
|
|
17
|
+
name: "Register with the catalog",
|
|
18
|
+
input: {
|
|
19
|
+
catalogInfoUrl: "http://github.com/backstage/backstage/blob/master/catalog-info.yaml"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
exports.examples = examples;
|
|
28
|
+
//# sourceMappingURL=register.examples.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.examples.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/register.examples.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description: 'Register with the catalog',\n example: yaml.stringify({\n steps: [\n {\n action: 'catalog:register',\n id: 'register-with-catalog',\n name: 'Register with the catalog',\n input: {\n catalogInfoUrl:\n 'http://github.com/backstage/backstage/blob/master/catalog-info.yaml',\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WAAa,EAAA,2BAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,MAAQ,EAAA,kBAAA;AAAA,UACR,EAAI,EAAA,uBAAA;AAAA,UACJ,IAAM,EAAA,2BAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,cACE,EAAA,qEAAA;AAAA,WACJ;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA;AAAA,GACH;AACF;;;;"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs-extra');
|
|
4
|
+
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
5
|
+
var yaml = require('yaml');
|
|
6
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
7
|
+
var zod = require('zod');
|
|
8
|
+
var write_examples = require('./write.examples.cjs.js');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
function _interopNamespaceCompat(e) {
|
|
13
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
31
|
+
var yaml__namespace = /*#__PURE__*/_interopNamespaceCompat(yaml);
|
|
32
|
+
|
|
33
|
+
const id = "catalog:write";
|
|
34
|
+
function createCatalogWriteAction() {
|
|
35
|
+
return pluginScaffolderNode.createTemplateAction({
|
|
36
|
+
id,
|
|
37
|
+
description: "Writes the catalog-info.yaml for your template",
|
|
38
|
+
schema: {
|
|
39
|
+
input: zod.z.object({
|
|
40
|
+
filePath: zod.z.string().optional().describe("Defaults to catalog-info.yaml"),
|
|
41
|
+
// TODO: this should reference an zod entity validator if it existed.
|
|
42
|
+
entity: zod.z.record(zod.z.any()).describe(
|
|
43
|
+
"You can provide the same values used in the Entity schema."
|
|
44
|
+
)
|
|
45
|
+
})
|
|
46
|
+
},
|
|
47
|
+
examples: write_examples.examples,
|
|
48
|
+
supportsDryRun: true,
|
|
49
|
+
async handler(ctx) {
|
|
50
|
+
const { filePath, entity } = ctx.input;
|
|
51
|
+
const entityRef = ctx.templateInfo?.entityRef;
|
|
52
|
+
const path = filePath ?? "catalog-info.yaml";
|
|
53
|
+
ctx.logger.info(`Writing ${path}`);
|
|
54
|
+
await fs__default.default.outputFile(
|
|
55
|
+
backendPluginApi.resolveSafeChildPath(ctx.workspacePath, path),
|
|
56
|
+
yaml__namespace.stringify({
|
|
57
|
+
...entity,
|
|
58
|
+
metadata: {
|
|
59
|
+
...entity.metadata,
|
|
60
|
+
...entityRef ? {
|
|
61
|
+
annotations: {
|
|
62
|
+
...entity.metadata.annotations,
|
|
63
|
+
"backstage.io/source-template": entityRef
|
|
64
|
+
}
|
|
65
|
+
} : void 0
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
exports.createCatalogWriteAction = createCatalogWriteAction;
|
|
74
|
+
//# sourceMappingURL=write.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/write.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs-extra';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport * as yaml from 'yaml';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { z } from 'zod';\nimport { examples } from './write.examples';\n\nconst id = 'catalog:write';\n\n/**\n * Writes a catalog descriptor file containing the provided entity to a path in the workspace.\n * @public\n */\n\nexport function createCatalogWriteAction() {\n return createTemplateAction({\n id,\n description: 'Writes the catalog-info.yaml for your template',\n schema: {\n input: z.object({\n filePath: z\n .string()\n .optional()\n .describe('Defaults to catalog-info.yaml'),\n // TODO: this should reference an zod entity validator if it existed.\n entity: z\n .record(z.any())\n .describe(\n 'You can provide the same values used in the Entity schema.',\n ),\n }),\n },\n examples,\n supportsDryRun: true,\n async handler(ctx) {\n const { filePath, entity } = ctx.input;\n const entityRef = ctx.templateInfo?.entityRef;\n const path = filePath ?? 'catalog-info.yaml';\n ctx.logger.info(`Writing ${path}`);\n\n await fs.outputFile(\n resolveSafeChildPath(ctx.workspacePath, path),\n yaml.stringify({\n ...entity,\n metadata: {\n ...entity.metadata,\n ...(entityRef\n ? {\n annotations: {\n ...entity.metadata.annotations,\n 'backstage.io/source-template': entityRef,\n },\n }\n : undefined),\n },\n }),\n );\n },\n });\n}\n"],"names":["createTemplateAction","z","examples","fs","resolveSafeChildPath","yaml"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,EAAK,GAAA,eAAA,CAAA;AAOJ,SAAS,wBAA2B,GAAA;AACzC,EAAA,OAAOA,yC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|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var yaml = require('yaml');
|
|
4
|
+
|
|
5
|
+
function _interopNamespaceCompat(e) {
|
|
6
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var yaml__namespace = /*#__PURE__*/_interopNamespaceCompat(yaml);
|
|
24
|
+
|
|
25
|
+
const examples = [
|
|
26
|
+
{
|
|
27
|
+
description: "Write a catalog yaml file",
|
|
28
|
+
example: yaml__namespace.stringify({
|
|
29
|
+
steps: [
|
|
30
|
+
{
|
|
31
|
+
action: "catalog:write",
|
|
32
|
+
id: "create-catalog-info-file",
|
|
33
|
+
name: "Create catalog file",
|
|
34
|
+
input: {
|
|
35
|
+
entity: {
|
|
36
|
+
apiVersion: "backstage.io/v1alpha1",
|
|
37
|
+
kind: "Component",
|
|
38
|
+
metadata: {
|
|
39
|
+
name: "test",
|
|
40
|
+
annotations: {}
|
|
41
|
+
},
|
|
42
|
+
spec: {
|
|
43
|
+
type: "service",
|
|
44
|
+
lifecycle: "production",
|
|
45
|
+
owner: "default/owner"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
exports.examples = examples;
|
|
56
|
+
//# sourceMappingURL=write.examples.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.examples.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/write.examples.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport * as yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description: 'Write a catalog yaml file',\n example: yaml.stringify({\n steps: [\n {\n action: 'catalog:write',\n id: 'create-catalog-info-file',\n name: 'Create catalog file',\n input: {\n entity: {\n apiVersion: 'backstage.io/v1alpha1',\n kind: 'Component',\n metadata: {\n name: 'test',\n annotations: {},\n },\n spec: {\n type: 'service',\n lifecycle: 'production',\n owner: 'default/owner',\n },\n },\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WAAa,EAAA,2BAAA;AAAA,IACb,OAAA,EAASA,gBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,MAAQ,EAAA,eAAA;AAAA,UACR,EAAI,EAAA,0BAAA;AAAA,UACJ,IAAM,EAAA,qBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,MAAQ,EAAA;AAAA,cACN,UAAY,EAAA,uBAAA;AAAA,cACZ,IAAM,EAAA,WAAA;AAAA,cACN,QAAU,EAAA;AAAA,gBACR,IAAM,EAAA,MAAA;AAAA,gBACN,aAAa,EAAC;AAAA,eAChB;AAAA,cACA,IAAM,EAAA;AAAA,gBACJ,IAAM,EAAA,SAAA;AAAA,gBACN,SAAW,EAAA,YAAA;AAAA,gBACX,KAAO,EAAA,eAAA;AAAA,eACT;AAAA,aACF;AAAA,WACF;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA;AAAA,GACH;AACF;;;;"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var integration = require('@backstage/integration');
|
|
4
|
+
var register = require('./catalog/register.cjs.js');
|
|
5
|
+
var write = require('./catalog/write.cjs.js');
|
|
6
|
+
var fetch = require('./catalog/fetch.cjs.js');
|
|
7
|
+
var log = require('./debug/log.cjs.js');
|
|
8
|
+
var wait = require('./debug/wait.cjs.js');
|
|
9
|
+
var plain = require('./fetch/plain.cjs.js');
|
|
10
|
+
var plainFile = require('./fetch/plainFile.cjs.js');
|
|
11
|
+
var template = require('./fetch/template.cjs.js');
|
|
12
|
+
var templateFile = require('./fetch/templateFile.cjs.js');
|
|
13
|
+
var _delete = require('./filesystem/delete.cjs.js');
|
|
14
|
+
var rename = require('./filesystem/rename.cjs.js');
|
|
15
|
+
var github = require('@backstage/plugin-scaffolder-backend-module-github');
|
|
16
|
+
var azure = require('@backstage/plugin-scaffolder-backend-module-azure');
|
|
17
|
+
var bitbucket = require('@backstage/plugin-scaffolder-backend-module-bitbucket');
|
|
18
|
+
var bitbucketCloud = require('@backstage/plugin-scaffolder-backend-module-bitbucket-cloud');
|
|
19
|
+
var bitbucketServer = require('@backstage/plugin-scaffolder-backend-module-bitbucket-server');
|
|
20
|
+
var gerrit = require('@backstage/plugin-scaffolder-backend-module-gerrit');
|
|
21
|
+
var gitlab = require('@backstage/plugin-scaffolder-backend-module-gitlab');
|
|
22
|
+
var pluginScaffolderBackendModuleGitea = require('@backstage/plugin-scaffolder-backend-module-gitea');
|
|
23
|
+
|
|
24
|
+
const createBuiltinActions = (options) => {
|
|
25
|
+
const {
|
|
26
|
+
reader,
|
|
27
|
+
integrations,
|
|
28
|
+
catalogClient,
|
|
29
|
+
auth,
|
|
30
|
+
config,
|
|
31
|
+
additionalTemplateFilters,
|
|
32
|
+
additionalTemplateGlobals
|
|
33
|
+
} = options;
|
|
34
|
+
const githubCredentialsProvider = integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations);
|
|
35
|
+
const actions = [
|
|
36
|
+
plain.createFetchPlainAction({
|
|
37
|
+
reader,
|
|
38
|
+
integrations
|
|
39
|
+
}),
|
|
40
|
+
plainFile.createFetchPlainFileAction({
|
|
41
|
+
reader,
|
|
42
|
+
integrations
|
|
43
|
+
}),
|
|
44
|
+
template.createFetchTemplateAction({
|
|
45
|
+
integrations,
|
|
46
|
+
reader,
|
|
47
|
+
additionalTemplateFilters,
|
|
48
|
+
additionalTemplateGlobals
|
|
49
|
+
}),
|
|
50
|
+
templateFile.createFetchTemplateFileAction({
|
|
51
|
+
integrations,
|
|
52
|
+
reader,
|
|
53
|
+
additionalTemplateFilters,
|
|
54
|
+
additionalTemplateGlobals
|
|
55
|
+
}),
|
|
56
|
+
gerrit.createPublishGerritAction({
|
|
57
|
+
integrations,
|
|
58
|
+
config
|
|
59
|
+
}),
|
|
60
|
+
gerrit.createPublishGerritReviewAction({
|
|
61
|
+
integrations,
|
|
62
|
+
config
|
|
63
|
+
}),
|
|
64
|
+
pluginScaffolderBackendModuleGitea.createPublishGiteaAction({
|
|
65
|
+
integrations,
|
|
66
|
+
config
|
|
67
|
+
}),
|
|
68
|
+
github.createPublishGithubAction({
|
|
69
|
+
integrations,
|
|
70
|
+
config,
|
|
71
|
+
githubCredentialsProvider
|
|
72
|
+
}),
|
|
73
|
+
github.createPublishGithubPullRequestAction({
|
|
74
|
+
integrations,
|
|
75
|
+
githubCredentialsProvider,
|
|
76
|
+
config
|
|
77
|
+
}),
|
|
78
|
+
gitlab.createPublishGitlabAction({
|
|
79
|
+
integrations,
|
|
80
|
+
config
|
|
81
|
+
}),
|
|
82
|
+
gitlab.createPublishGitlabMergeRequestAction({
|
|
83
|
+
integrations
|
|
84
|
+
}),
|
|
85
|
+
gitlab.createGitlabRepoPushAction({
|
|
86
|
+
integrations
|
|
87
|
+
}),
|
|
88
|
+
bitbucket.createPublishBitbucketAction({
|
|
89
|
+
integrations,
|
|
90
|
+
config
|
|
91
|
+
}),
|
|
92
|
+
bitbucketCloud.createPublishBitbucketCloudAction({
|
|
93
|
+
integrations,
|
|
94
|
+
config
|
|
95
|
+
}),
|
|
96
|
+
bitbucketCloud.createPublishBitbucketCloudPullRequestAction({ integrations, config }),
|
|
97
|
+
bitbucketServer.createPublishBitbucketServerAction({
|
|
98
|
+
integrations,
|
|
99
|
+
config
|
|
100
|
+
}),
|
|
101
|
+
bitbucketServer.createPublishBitbucketServerPullRequestAction({
|
|
102
|
+
integrations,
|
|
103
|
+
config
|
|
104
|
+
}),
|
|
105
|
+
azure.createPublishAzureAction({
|
|
106
|
+
integrations,
|
|
107
|
+
config
|
|
108
|
+
}),
|
|
109
|
+
log.createDebugLogAction(),
|
|
110
|
+
wait.createWaitAction(),
|
|
111
|
+
register.createCatalogRegisterAction({ catalogClient, integrations, auth }),
|
|
112
|
+
fetch.createFetchCatalogEntityAction({ catalogClient, auth }),
|
|
113
|
+
write.createCatalogWriteAction(),
|
|
114
|
+
_delete.createFilesystemDeleteAction(),
|
|
115
|
+
rename.createFilesystemRenameAction(),
|
|
116
|
+
github.createGithubActionsDispatchAction({
|
|
117
|
+
integrations,
|
|
118
|
+
githubCredentialsProvider
|
|
119
|
+
}),
|
|
120
|
+
github.createGithubWebhookAction({
|
|
121
|
+
integrations,
|
|
122
|
+
githubCredentialsProvider
|
|
123
|
+
}),
|
|
124
|
+
github.createGithubIssuesLabelAction({
|
|
125
|
+
integrations,
|
|
126
|
+
githubCredentialsProvider
|
|
127
|
+
}),
|
|
128
|
+
github.createGithubRepoCreateAction({
|
|
129
|
+
integrations,
|
|
130
|
+
githubCredentialsProvider
|
|
131
|
+
}),
|
|
132
|
+
github.createGithubRepoPushAction({
|
|
133
|
+
integrations,
|
|
134
|
+
config,
|
|
135
|
+
githubCredentialsProvider
|
|
136
|
+
}),
|
|
137
|
+
github.createGithubEnvironmentAction({
|
|
138
|
+
integrations,
|
|
139
|
+
catalogClient
|
|
140
|
+
}),
|
|
141
|
+
github.createGithubDeployKeyAction({
|
|
142
|
+
integrations
|
|
143
|
+
}),
|
|
144
|
+
github.createGithubAutolinksAction({
|
|
145
|
+
integrations,
|
|
146
|
+
githubCredentialsProvider
|
|
147
|
+
}),
|
|
148
|
+
bitbucketCloud.createBitbucketPipelinesRunAction({
|
|
149
|
+
integrations
|
|
150
|
+
})
|
|
151
|
+
];
|
|
152
|
+
return actions;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
exports.createBuiltinActions = createBuiltinActions;
|
|
156
|
+
//# sourceMappingURL=createBuiltinActions.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBuiltinActions.cjs.js","sources":["../../../../src/scaffolder/actions/builtin/createBuiltinActions.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CatalogApi } from '@backstage/catalog-client';\nimport { Config } from '@backstage/config';\nimport {\n DefaultGithubCredentialsProvider,\n GithubCredentialsProvider,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n TemplateAction,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport {\n createCatalogRegisterAction,\n createCatalogWriteAction,\n createFetchCatalogEntityAction,\n} from './catalog';\n\nimport { createDebugLogAction, createWaitAction } from './debug';\nimport {\n createFetchPlainAction,\n createFetchPlainFileAction,\n createFetchTemplateAction,\n createFetchTemplateFileAction,\n} from './fetch';\nimport {\n createFilesystemDeleteAction,\n createFilesystemRenameAction,\n} from './filesystem';\nimport {\n createGithubActionsDispatchAction,\n createGithubAutolinksAction,\n createGithubDeployKeyAction,\n createGithubEnvironmentAction,\n createGithubIssuesLabelAction,\n createGithubRepoCreateAction,\n createGithubRepoPushAction,\n createGithubWebhookAction,\n createPublishGithubAction,\n createPublishGithubPullRequestAction,\n} from '@backstage/plugin-scaffolder-backend-module-github';\n\nimport { createPublishAzureAction } from '@backstage/plugin-scaffolder-backend-module-azure';\n\nimport { createPublishBitbucketAction } from '@backstage/plugin-scaffolder-backend-module-bitbucket';\n\nimport {\n createPublishBitbucketCloudAction,\n createBitbucketPipelinesRunAction,\n createPublishBitbucketCloudPullRequestAction,\n} from '@backstage/plugin-scaffolder-backend-module-bitbucket-cloud';\n\nimport {\n createPublishBitbucketServerAction,\n createPublishBitbucketServerPullRequestAction,\n} from '@backstage/plugin-scaffolder-backend-module-bitbucket-server';\n\nimport {\n createPublishGerritAction,\n createPublishGerritReviewAction,\n} from '@backstage/plugin-scaffolder-backend-module-gerrit';\n\nimport {\n createPublishGitlabAction,\n createGitlabRepoPushAction,\n createPublishGitlabMergeRequestAction,\n} from '@backstage/plugin-scaffolder-backend-module-gitlab';\n\nimport { createPublishGiteaAction } from '@backstage/plugin-scaffolder-backend-module-gitea';\nimport { AuthService, UrlReaderService } from '@backstage/backend-plugin-api';\n\n/**\n * The options passed to {@link createBuiltinActions}\n * @public\n */\nexport interface CreateBuiltInActionsOptions {\n /**\n * The {@link @backstage/backend-plugin-api#UrlReaderService} interface that will be used in the default actions.\n */\n reader: UrlReaderService;\n /**\n * The {@link @backstage/integrations#ScmIntegrations} that will be used in the default actions.\n */\n integrations: ScmIntegrations;\n /**\n * The {@link @backstage/catalog-client#CatalogApi} that will be used in the default actions.\n */\n catalogClient: CatalogApi;\n /**\n * The {@link @backstage/backend-plugin-api#AuthService} that will be used in the default actions.\n */\n auth?: AuthService;\n /**\n * The {@link @backstage/config#Config} that will be used in the default actions.\n */\n config: Config;\n /**\n * Additional custom filters that will be passed to the nunjucks template engine for use in\n * Template Manifests and also template skeleton files when using `fetch:template`.\n */\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}\n\n/**\n * A function to generate create a list of default actions that the scaffolder provides.\n * Is called internally in the default setup, but can be used when adding your own actions or overriding the default ones\n *\n * TODO(blam): version 2 of the scaffolder shouldn't ship with the additional modules. We should ship the basics, and let people install\n * modules for the providers they want to use.\n * @public\n * @returns A list of actions that can be used in the scaffolder\n *\n */\nexport const createBuiltinActions = (\n options: CreateBuiltInActionsOptions,\n): TemplateAction[] => {\n const {\n reader,\n integrations,\n catalogClient,\n auth,\n config,\n additionalTemplateFilters,\n additionalTemplateGlobals,\n } = options;\n\n const githubCredentialsProvider: GithubCredentialsProvider =\n DefaultGithubCredentialsProvider.fromIntegrations(integrations);\n\n const actions = [\n createFetchPlainAction({\n reader,\n integrations,\n }),\n createFetchPlainFileAction({\n reader,\n integrations,\n }),\n createFetchTemplateAction({\n integrations,\n reader,\n additionalTemplateFilters,\n additionalTemplateGlobals,\n }),\n createFetchTemplateFileAction({\n integrations,\n reader,\n additionalTemplateFilters,\n additionalTemplateGlobals,\n }),\n createPublishGerritAction({\n integrations,\n config,\n }),\n createPublishGerritReviewAction({\n integrations,\n config,\n }),\n createPublishGiteaAction({\n integrations,\n config,\n }),\n createPublishGithubAction({\n integrations,\n config,\n githubCredentialsProvider,\n }),\n createPublishGithubPullRequestAction({\n integrations,\n githubCredentialsProvider,\n config,\n }),\n createPublishGitlabAction({\n integrations,\n config,\n }),\n createPublishGitlabMergeRequestAction({\n integrations,\n }),\n createGitlabRepoPushAction({\n integrations,\n }),\n createPublishBitbucketAction({\n integrations,\n config,\n }),\n createPublishBitbucketCloudAction({\n integrations,\n config,\n }),\n createPublishBitbucketCloudPullRequestAction({ integrations, config }),\n createPublishBitbucketServerAction({\n integrations,\n config,\n }),\n createPublishBitbucketServerPullRequestAction({\n integrations,\n config,\n }),\n createPublishAzureAction({\n integrations,\n config,\n }),\n createDebugLogAction(),\n createWaitAction(),\n createCatalogRegisterAction({ catalogClient, integrations, auth }),\n createFetchCatalogEntityAction({ catalogClient, auth }),\n createCatalogWriteAction(),\n createFilesystemDeleteAction(),\n createFilesystemRenameAction(),\n createGithubActionsDispatchAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubWebhookAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubIssuesLabelAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubRepoCreateAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubRepoPushAction({\n integrations,\n config,\n githubCredentialsProvider,\n }),\n createGithubEnvironmentAction({\n integrations,\n catalogClient,\n }),\n createGithubDeployKeyAction({\n integrations,\n }),\n createGithubAutolinksAction({\n integrations,\n githubCredentialsProvider,\n }),\n createBitbucketPipelinesRunAction({\n integrations,\n }),\n ];\n\n return actions as TemplateAction[];\n};\n"],"names":["DefaultGithubCredentialsProvider","createFetchPlainAction","createFetchPlainFileAction","createFetchTemplateAction","createFetchTemplateFileAction","createPublishGerritAction","createPublishGerritReviewAction","createPublishGiteaAction","createPublishGithubAction","createPublishGithubPullRequestAction","createPublishGitlabAction","createPublishGitlabMergeRequestAction","createGitlabRepoPushAction","createPublishBitbucketAction","createPublishBitbucketCloudAction","createPublishBitbucketCloudPullRequestAction","createPublishBitbucketServerAction","createPublishBitbucketServerPullRequestAction","createPublishAzureAction","createDebugLogAction","createWaitAction","createCatalogRegisterAction","createFetchCatalogEntityAction","createCatalogWriteAction","createFilesystemDeleteAction","createFilesystemRenameAction","createGithubActionsDispatchAction","createGithubWebhookAction","createGithubIssuesLabelAction","createGithubRepoCreateAction","createGithubRepoPushAction","createGithubEnvironmentAction","createGithubDeployKeyAction","createGithubAutolinksAction","createBitbucketPipelinesRun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MACzB,YAAA;AAAA,MACA,MAAA;AAAA,MACA,yBAAA;AAAA,KACD,CAAA;AAAA,IACDC,oCAA8B,CAAA;AAAA,MAC5B,YAAA;AAAA,MACA,aAAA;AAAA,KACD,CAAA;AAAA,IACDC,kCAA4B,CAAA;AAAA,MAC1B,YAAA;AAAA,KACD,CAAA;AAAA,IACDC,kCAA4B,CAAA;AAAA,MAC1B,YAAA;AAAA,MACA,yBAAA;AAAA,KACD,CAAA;AAAA,IACDC,gDAAkC,CAAA;AAAA,MAChC,YAAA;AAAA,KACD,CAAA;AAAA,GACH,CAAA;AAEA,EAAO,OAAA,OAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs$1 = require('fs-extra');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
6
|
+
var log_examples = require('./log.examples.cjs.js');
|
|
7
|
+
var fs = require('fs');
|
|
8
|
+
var zod = require('zod');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
13
|
+
|
|
14
|
+
const id = "debug:log";
|
|
15
|
+
function createDebugLogAction() {
|
|
16
|
+
return pluginScaffolderNode.createTemplateAction({
|
|
17
|
+
id,
|
|
18
|
+
description: "Writes a message into the log and/or lists all files in the workspace.",
|
|
19
|
+
examples: log_examples.examples,
|
|
20
|
+
schema: {
|
|
21
|
+
input: zod.z.object({
|
|
22
|
+
message: zod.z.string({ description: "Message to output." }).optional(),
|
|
23
|
+
listWorkspace: zod.z.union([zod.z.boolean(), zod.z.enum(["with-filenames", "with-contents"])], {
|
|
24
|
+
description: 'List all files in the workspace. If used with "with-contents", also the file contents are listed.'
|
|
25
|
+
}).optional()
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
supportsDryRun: true,
|
|
29
|
+
async handler(ctx) {
|
|
30
|
+
ctx.logger.info(JSON.stringify(ctx.input, null, 2));
|
|
31
|
+
if (ctx.input?.message) {
|
|
32
|
+
ctx.logger.info(ctx.input.message);
|
|
33
|
+
}
|
|
34
|
+
if (ctx.input?.listWorkspace) {
|
|
35
|
+
const files = await recursiveReadDir(ctx.workspacePath);
|
|
36
|
+
ctx.logger.info(
|
|
37
|
+
`Workspace:
|
|
38
|
+
${files.map((f) => {
|
|
39
|
+
const relativePath = path.relative(ctx.workspacePath, f);
|
|
40
|
+
if (ctx.input?.listWorkspace === "with-contents") {
|
|
41
|
+
const content = fs__default.default.readFileSync(f, "utf-8");
|
|
42
|
+
return ` - ${relativePath}:
|
|
43
|
+
|
|
44
|
+
${content}`;
|
|
45
|
+
}
|
|
46
|
+
return ` - ${relativePath}`;
|
|
47
|
+
}).join("\n")}`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async function recursiveReadDir(dir) {
|
|
54
|
+
const subdirs = await fs$1.readdir(dir);
|
|
55
|
+
const files = await Promise.all(
|
|
56
|
+
subdirs.map(async (subdir) => {
|
|
57
|
+
const res = path.join(dir, subdir);
|
|
58
|
+
return (await fs$1.stat(res)).isDirectory() ? recursiveReadDir(res) : [res];
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
return files.reduce((a, f) => a.concat(f), []);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.createDebugLogAction = createDebugLogAction;
|
|
65
|
+
exports.recursiveReadDir = recursiveReadDir;
|
|
66
|
+
//# sourceMappingURL=log.cjs.js.map
|