@backstage/plugin-scaffolder-backend 2.0.0-next.1 → 2.0.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 +221 -0
- package/dist/ScaffolderPlugin.cjs.js +7 -16
- package/dist/ScaffolderPlugin.cjs.js.map +1 -1
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +81 -95
- package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js +5 -11
- package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/catalog/register.cjs.js +26 -62
- package/dist/scaffolder/actions/builtin/catalog/register.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/catalog/write.cjs.js +4 -5
- package/dist/scaffolder/actions/builtin/catalog/write.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/debug/log.cjs.js +4 -5
- package/dist/scaffolder/actions/builtin/debug/log.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/debug/wait.cjs.js +9 -15
- package/dist/scaffolder/actions/builtin/debug/wait.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js +9 -19
- package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js +9 -19
- package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/fetch/template.cjs.js +33 -55
- package/dist/scaffolder/actions/builtin/fetch/template.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js +24 -34
- package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js +3 -12
- package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/filesystem/read.cjs.js +14 -14
- package/dist/scaffolder/actions/builtin/filesystem/read.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js +16 -27
- package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js.map +1 -1
- package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js +2 -11
- package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js.map +1 -1
- package/dist/scaffolder/dryrun/createDryRunner.cjs.js.map +1 -1
- package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js +8 -15
- package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js.map +1 -1
- package/dist/scaffolder/tasks/StorageTaskBroker.cjs.js.map +1 -1
- package/dist/scaffolder/tasks/TaskWorker.cjs.js.map +1 -1
- package/dist/service/helpers.cjs.js +4 -2
- package/dist/service/helpers.cjs.js.map +1 -1
- package/dist/service/router.cjs.js +18 -45
- package/dist/service/router.cjs.js.map +1 -1
- package/dist/service/rules.cjs.js +11 -11
- package/dist/service/rules.cjs.js.map +1 -1
- package/dist/util/templating.cjs.js +3 -3
- package/dist/util/templating.cjs.js.map +1 -1
- package/package.json +30 -31
- package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js +0 -158
- package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
-
import {
|
|
2
|
+
import { UrlReaderService, DatabaseService, LoggerService, AuthService, BackstageCredentials, AuditorService } from '@backstage/backend-plugin-api';
|
|
3
3
|
import * as _backstage_plugin_scaffolder_node from '@backstage/plugin-scaffolder-node';
|
|
4
4
|
import { TemplateFilter, TemplateGlobal, TemplateAction, TaskSecrets, SerializedTask, TaskStatus, SerializedTaskEvent, TaskContext, TaskCompletionState, TaskBroker } from '@backstage/plugin-scaffolder-node';
|
|
5
|
-
import * as _backstage_types from '@backstage/types';
|
|
6
|
-
import { HumanDuration, JsonObject, JsonValue } from '@backstage/types';
|
|
7
5
|
import { ScmIntegrations } from '@backstage/integration';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
6
|
+
import { CatalogService } from '@backstage/plugin-catalog-node';
|
|
7
|
+
import { HumanDuration, JsonObject, JsonValue } from '@backstage/types';
|
|
10
8
|
import { Duration } from 'luxon';
|
|
11
9
|
import { Knex } from 'knex';
|
|
12
10
|
import * as _backstage_plugin_scaffolder_common from '@backstage/plugin-scaffolder-common';
|
|
13
11
|
import { TaskSpec, TaskRecovery, TemplateEntityStepV1beta3, TemplateParametersV1beta3 } from '@backstage/plugin-scaffolder-common';
|
|
14
12
|
import { EventsService } from '@backstage/plugin-events-node';
|
|
13
|
+
import { Config } from '@backstage/config';
|
|
15
14
|
import { WorkspaceProvider } from '@backstage/plugin-scaffolder-node/alpha';
|
|
16
|
-
import { Logger } from 'winston';
|
|
17
15
|
import { PermissionEvaluator, PermissionRuleParams } from '@backstage/plugin-permission-common';
|
|
18
16
|
import { PermissionRule } from '@backstage/plugin-permission-node';
|
|
19
17
|
import { RESOURCE_TYPE_SCAFFOLDER_TEMPLATE, RESOURCE_TYPE_SCAFFOLDER_ACTION } from '@backstage/plugin-scaffolder-common/alpha';
|
|
@@ -30,17 +28,25 @@ declare const scaffolderPlugin: _backstage_backend_plugin_api.BackendFeature;
|
|
|
30
28
|
* @public
|
|
31
29
|
*/
|
|
32
30
|
declare function createCatalogRegisterAction(options: {
|
|
33
|
-
|
|
31
|
+
catalog: CatalogService;
|
|
34
32
|
integrations: ScmIntegrations;
|
|
35
|
-
auth?: AuthService;
|
|
36
33
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
37
34
|
catalogInfoUrl: string;
|
|
38
|
-
optional?: boolean;
|
|
35
|
+
optional?: boolean | undefined;
|
|
36
|
+
} | {
|
|
37
|
+
catalogInfoUrl: string;
|
|
38
|
+
optional?: boolean | undefined;
|
|
39
|
+
catalogInfoPath?: string | undefined;
|
|
39
40
|
} | {
|
|
40
41
|
repoContentsUrl: string;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
optional?: boolean | undefined;
|
|
43
|
+
} | {
|
|
44
|
+
repoContentsUrl: string;
|
|
45
|
+
optional?: boolean | undefined;
|
|
46
|
+
catalogInfoPath?: string | undefined;
|
|
47
|
+
}, {
|
|
48
|
+
[x: string]: any;
|
|
49
|
+
}, "v2">;
|
|
44
50
|
|
|
45
51
|
/**
|
|
46
52
|
* Writes a catalog descriptor file containing the provided entity to a path in the workspace.
|
|
@@ -49,7 +55,9 @@ declare function createCatalogRegisterAction(options: {
|
|
|
49
55
|
declare function createCatalogWriteAction(): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
50
56
|
entity: Record<string, any>;
|
|
51
57
|
filePath?: string | undefined;
|
|
52
|
-
},
|
|
58
|
+
}, {
|
|
59
|
+
[x: string]: any;
|
|
60
|
+
}, "v2">;
|
|
53
61
|
|
|
54
62
|
/**
|
|
55
63
|
* Returns entity or entities from the catalog by entity reference(s).
|
|
@@ -57,8 +65,7 @@ declare function createCatalogWriteAction(): _backstage_plugin_scaffolder_node.T
|
|
|
57
65
|
* @public
|
|
58
66
|
*/
|
|
59
67
|
declare function createFetchCatalogEntityAction(options: {
|
|
60
|
-
|
|
61
|
-
auth?: AuthService;
|
|
68
|
+
catalog: CatalogService;
|
|
62
69
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
63
70
|
entityRef?: string | undefined;
|
|
64
71
|
entityRefs?: string[] | undefined;
|
|
@@ -70,50 +77,6 @@ declare function createFetchCatalogEntityAction(options: {
|
|
|
70
77
|
entities?: any[] | undefined;
|
|
71
78
|
}, "v2">;
|
|
72
79
|
|
|
73
|
-
/**
|
|
74
|
-
* The options passed to {@link createBuiltinActions}
|
|
75
|
-
* @public
|
|
76
|
-
*/
|
|
77
|
-
interface CreateBuiltInActionsOptions {
|
|
78
|
-
/**
|
|
79
|
-
* The {@link @backstage/backend-plugin-api#UrlReaderService} interface that will be used in the default actions.
|
|
80
|
-
*/
|
|
81
|
-
reader: UrlReaderService;
|
|
82
|
-
/**
|
|
83
|
-
* The {@link @backstage/integrations#ScmIntegrations} that will be used in the default actions.
|
|
84
|
-
*/
|
|
85
|
-
integrations: ScmIntegrations;
|
|
86
|
-
/**
|
|
87
|
-
* The {@link @backstage/catalog-client#CatalogApi} that will be used in the default actions.
|
|
88
|
-
*/
|
|
89
|
-
catalogClient: CatalogApi;
|
|
90
|
-
/**
|
|
91
|
-
* The {@link @backstage/backend-plugin-api#AuthService} that will be used in the default actions.
|
|
92
|
-
*/
|
|
93
|
-
auth?: AuthService;
|
|
94
|
-
/**
|
|
95
|
-
* The {@link @backstage/config#Config} that will be used in the default actions.
|
|
96
|
-
*/
|
|
97
|
-
config: Config;
|
|
98
|
-
/**
|
|
99
|
-
* Additional custom filters that will be passed to the nunjucks template engine for use in
|
|
100
|
-
* Template Manifests and also template skeleton files when using `fetch:template`.
|
|
101
|
-
*/
|
|
102
|
-
additionalTemplateFilters?: Record<string, TemplateFilter>;
|
|
103
|
-
additionalTemplateGlobals?: Record<string, TemplateGlobal>;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* A function to generate create a list of default actions that the scaffolder provides.
|
|
107
|
-
* Is called internally in the default setup, but can be used when adding your own actions or overriding the default ones
|
|
108
|
-
*
|
|
109
|
-
* TODO(blam): version 2 of the scaffolder shouldn't ship with the additional modules. We should ship the basics, and let people install
|
|
110
|
-
* modules for the providers they want to use.
|
|
111
|
-
* @public
|
|
112
|
-
* @returns A list of actions that can be used in the scaffolder
|
|
113
|
-
*
|
|
114
|
-
*/
|
|
115
|
-
declare const createBuiltinActions: (options: CreateBuiltInActionsOptions) => TemplateAction[];
|
|
116
|
-
|
|
117
80
|
/**
|
|
118
81
|
* Writes a message into the log or lists all files in the workspace
|
|
119
82
|
*
|
|
@@ -124,7 +87,12 @@ declare const createBuiltinActions: (options: CreateBuiltInActionsOptions) => Te
|
|
|
124
87
|
*
|
|
125
88
|
* @public
|
|
126
89
|
*/
|
|
127
|
-
declare function createDebugLogAction(): _backstage_plugin_scaffolder_node.TemplateAction<
|
|
90
|
+
declare function createDebugLogAction(): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
91
|
+
message?: string | undefined;
|
|
92
|
+
listWorkspace?: boolean | "with-contents" | "with-filenames" | undefined;
|
|
93
|
+
}, {
|
|
94
|
+
[x: string]: any;
|
|
95
|
+
}, "v2">;
|
|
128
96
|
|
|
129
97
|
/**
|
|
130
98
|
* Waits for a certain period of time.
|
|
@@ -138,7 +106,13 @@ declare function createDebugLogAction(): _backstage_plugin_scaffolder_node.Templ
|
|
|
138
106
|
*/
|
|
139
107
|
declare function createWaitAction(options?: {
|
|
140
108
|
maxWaitTime?: Duration | HumanDuration;
|
|
141
|
-
}): _backstage_plugin_scaffolder_node.TemplateAction<
|
|
109
|
+
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
110
|
+
minutes?: number | undefined;
|
|
111
|
+
seconds?: number | undefined;
|
|
112
|
+
milliseconds?: number | undefined;
|
|
113
|
+
}, {
|
|
114
|
+
[x: string]: any;
|
|
115
|
+
}, "v2">;
|
|
142
116
|
|
|
143
117
|
/**
|
|
144
118
|
* Downloads content and places it in the workspace, or optionally
|
|
@@ -150,13 +124,14 @@ declare function createFetchPlainAction(options: {
|
|
|
150
124
|
integrations: ScmIntegrations;
|
|
151
125
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
152
126
|
url: string;
|
|
153
|
-
targetPath?: string;
|
|
154
|
-
token?: string;
|
|
155
|
-
},
|
|
127
|
+
targetPath?: string | undefined;
|
|
128
|
+
token?: string | undefined;
|
|
129
|
+
}, {
|
|
130
|
+
[x: string]: any;
|
|
131
|
+
}, "v2">;
|
|
156
132
|
|
|
157
133
|
/**
|
|
158
|
-
* Downloads
|
|
159
|
-
* in a subdirectory specified by the 'targetPath' input option.
|
|
134
|
+
* Downloads a single file and places it in the workspace.
|
|
160
135
|
* @public
|
|
161
136
|
*/
|
|
162
137
|
declare function createFetchPlainFileAction(options: {
|
|
@@ -165,8 +140,10 @@ declare function createFetchPlainFileAction(options: {
|
|
|
165
140
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
166
141
|
url: string;
|
|
167
142
|
targetPath: string;
|
|
168
|
-
token?: string;
|
|
169
|
-
},
|
|
143
|
+
token?: string | undefined;
|
|
144
|
+
}, {
|
|
145
|
+
[x: string]: any;
|
|
146
|
+
}, "v2">;
|
|
170
147
|
|
|
171
148
|
/**
|
|
172
149
|
* Downloads a skeleton, templates variables into file and directory names and content.
|
|
@@ -182,16 +159,19 @@ declare function createFetchTemplateAction(options: {
|
|
|
182
159
|
additionalTemplateGlobals?: Record<string, TemplateGlobal>;
|
|
183
160
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
184
161
|
url: string;
|
|
185
|
-
targetPath?: string;
|
|
186
|
-
values
|
|
187
|
-
|
|
188
|
-
copyWithoutTemplating?: string[];
|
|
189
|
-
cookiecutterCompat?: boolean;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
162
|
+
targetPath?: string | undefined;
|
|
163
|
+
values?: Record<string, any> | undefined;
|
|
164
|
+
copyWithoutRender?: string[] | undefined;
|
|
165
|
+
copyWithoutTemplating?: string[] | undefined;
|
|
166
|
+
cookiecutterCompat?: boolean | undefined;
|
|
167
|
+
templateFileExtension?: string | boolean | undefined;
|
|
168
|
+
replace?: boolean | undefined;
|
|
169
|
+
trimBlocks?: boolean | undefined;
|
|
170
|
+
lstripBlocks?: boolean | undefined;
|
|
171
|
+
token?: string | undefined;
|
|
172
|
+
}, {
|
|
173
|
+
[x: string]: any;
|
|
174
|
+
}, "v2">;
|
|
195
175
|
|
|
196
176
|
/**
|
|
197
177
|
* Downloads a single file and templates variables into file.
|
|
@@ -207,13 +187,15 @@ declare function createFetchTemplateFileAction(options: {
|
|
|
207
187
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
208
188
|
url: string;
|
|
209
189
|
targetPath: string;
|
|
210
|
-
values
|
|
211
|
-
cookiecutterCompat?: boolean;
|
|
212
|
-
replace?: boolean;
|
|
213
|
-
trimBlocks?: boolean;
|
|
214
|
-
lstripBlocks?: boolean;
|
|
215
|
-
token?: string;
|
|
216
|
-
},
|
|
190
|
+
values?: Record<string, any> | undefined;
|
|
191
|
+
cookiecutterCompat?: boolean | undefined;
|
|
192
|
+
replace?: boolean | undefined;
|
|
193
|
+
trimBlocks?: boolean | undefined;
|
|
194
|
+
lstripBlocks?: boolean | undefined;
|
|
195
|
+
token?: string | undefined;
|
|
196
|
+
}, {
|
|
197
|
+
[x: string]: any;
|
|
198
|
+
}, "v2">;
|
|
217
199
|
|
|
218
200
|
/**
|
|
219
201
|
* Creates new action that enables deletion of files and directories in the workspace.
|
|
@@ -221,27 +203,31 @@ declare function createFetchTemplateFileAction(options: {
|
|
|
221
203
|
*/
|
|
222
204
|
declare const createFilesystemDeleteAction: () => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
223
205
|
files: string[];
|
|
224
|
-
},
|
|
206
|
+
}, {
|
|
207
|
+
[x: string]: any;
|
|
208
|
+
}, "v2">;
|
|
225
209
|
|
|
226
210
|
/**
|
|
227
211
|
* Creates a new action that allows renames of files and directories in the workspace.
|
|
228
212
|
* @public
|
|
229
213
|
*/
|
|
230
214
|
declare const createFilesystemRenameAction: () => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
231
|
-
files:
|
|
215
|
+
files: {
|
|
232
216
|
from: string;
|
|
233
217
|
to: string;
|
|
234
|
-
overwrite?: boolean;
|
|
235
|
-
}
|
|
236
|
-
},
|
|
218
|
+
overwrite?: boolean | undefined;
|
|
219
|
+
}[];
|
|
220
|
+
}, {
|
|
221
|
+
[x: string]: any;
|
|
222
|
+
}, "v2">;
|
|
237
223
|
|
|
238
224
|
/**
|
|
239
225
|
* Creates new action that enables reading directories in the workspace.
|
|
240
226
|
* @public
|
|
241
227
|
*/
|
|
242
228
|
declare const createFilesystemReadDirAction: () => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
243
|
-
recursive: boolean;
|
|
244
229
|
paths: string[];
|
|
230
|
+
recursive: boolean;
|
|
245
231
|
}, {
|
|
246
232
|
files: {
|
|
247
233
|
name: string;
|
|
@@ -253,7 +239,7 @@ declare const createFilesystemReadDirAction: () => _backstage_plugin_scaffolder_
|
|
|
253
239
|
path: string;
|
|
254
240
|
fullPath: string;
|
|
255
241
|
}[];
|
|
256
|
-
}, "
|
|
242
|
+
}, "v2">;
|
|
257
243
|
|
|
258
244
|
/**
|
|
259
245
|
* Registry of all registered template actions.
|
|
@@ -534,7 +520,7 @@ declare class TaskManager implements TaskContext {
|
|
|
534
520
|
private readonly auth?;
|
|
535
521
|
private isDone;
|
|
536
522
|
private heartbeatTimeoutId?;
|
|
537
|
-
static create(task: CurrentClaimedTask, storage: TaskStore, abortSignal: AbortSignal, logger:
|
|
523
|
+
static create(task: CurrentClaimedTask, storage: TaskStore, abortSignal: AbortSignal, logger: LoggerService, auth?: AuthService, config?: Config, additionalWorkspaceProviders?: Record<string, WorkspaceProvider>): TaskManager;
|
|
538
524
|
private constructor();
|
|
539
525
|
get spec(): _backstage_plugin_scaffolder_common.TaskSpecV1beta3;
|
|
540
526
|
get cancelSignal(): AbortSignal;
|
|
@@ -609,7 +595,7 @@ type CreateWorkerOptions = {
|
|
|
609
595
|
actionRegistry: TemplateActionRegistry;
|
|
610
596
|
integrations: ScmIntegrations;
|
|
611
597
|
workingDirectory: string;
|
|
612
|
-
logger:
|
|
598
|
+
logger: LoggerService;
|
|
613
599
|
auditor?: AuditorService;
|
|
614
600
|
additionalTemplateFilters?: Record<string, TemplateFilter>;
|
|
615
601
|
/**
|
|
@@ -659,4 +645,4 @@ type TemplatePermissionRuleInput<TParams extends PermissionRuleParams = Permissi
|
|
|
659
645
|
*/
|
|
660
646
|
type ActionPermissionRuleInput<TParams extends PermissionRuleParams = PermissionRuleParams> = PermissionRule<TemplateEntityStepV1beta3 | TemplateParametersV1beta3, {}, typeof RESOURCE_TYPE_SCAFFOLDER_ACTION, TParams>;
|
|
661
647
|
|
|
662
|
-
export { type ActionPermissionRuleInput, type
|
|
648
|
+
export { type ActionPermissionRuleInput, type CreateWorkerOptions, type CurrentClaimedTask, DatabaseTaskStore, type DatabaseTaskStoreOptions, TaskManager, type TaskStore, type TaskStoreCreateTaskOptions, type TaskStoreCreateTaskResult, type TaskStoreEmitOptions, type TaskStoreListEventsOptions, type TaskStoreRecoverTaskOptions, type TaskStoreShutDownTaskOptions, TaskWorker, TemplateActionRegistry, type TemplatePermissionRuleInput, createCatalogRegisterAction, createCatalogWriteAction, createDebugLogAction, createFetchCatalogEntityAction, createFetchPlainAction, createFetchPlainFileAction, createFetchTemplateAction, createFetchTemplateFileAction, createFilesystemDeleteAction, createFilesystemReadDirAction, createFilesystemRenameAction, createWaitAction, scaffolderPlugin as default };
|
|
@@ -6,7 +6,7 @@ var fetch_examples = require('./fetch.examples.cjs.js');
|
|
|
6
6
|
|
|
7
7
|
const id = "catalog:fetch";
|
|
8
8
|
function createFetchCatalogEntityAction(options) {
|
|
9
|
-
const {
|
|
9
|
+
const { catalog } = options;
|
|
10
10
|
return pluginScaffolderNode.createTemplateAction({
|
|
11
11
|
id,
|
|
12
12
|
description: "Returns entity or entities from the catalog by entity reference(s)",
|
|
@@ -45,17 +45,13 @@ function createFetchCatalogEntityAction(options) {
|
|
|
45
45
|
}
|
|
46
46
|
throw new Error("Missing entity reference or references");
|
|
47
47
|
}
|
|
48
|
-
const { token } = await auth?.getPluginRequestToken({
|
|
49
|
-
onBehalfOf: await ctx.getInitiatorCredentials(),
|
|
50
|
-
targetPluginId: "catalog"
|
|
51
|
-
}) ?? { token: ctx.secrets?.backstageToken };
|
|
52
48
|
if (entityRef) {
|
|
53
|
-
const entity = await
|
|
49
|
+
const entity = await catalog.getEntityByRef(
|
|
54
50
|
catalogModel.stringifyEntityRef(
|
|
55
51
|
catalogModel.parseEntityRef(entityRef, { defaultKind, defaultNamespace })
|
|
56
52
|
),
|
|
57
53
|
{
|
|
58
|
-
|
|
54
|
+
credentials: await ctx.getInitiatorCredentials()
|
|
59
55
|
}
|
|
60
56
|
);
|
|
61
57
|
if (!entity && !optional) {
|
|
@@ -64,7 +60,7 @@ function createFetchCatalogEntityAction(options) {
|
|
|
64
60
|
ctx.output("entity", entity ?? null);
|
|
65
61
|
}
|
|
66
62
|
if (entityRefs) {
|
|
67
|
-
const entities = await
|
|
63
|
+
const entities = await catalog.getEntitiesByRefs(
|
|
68
64
|
{
|
|
69
65
|
entityRefs: entityRefs.map(
|
|
70
66
|
(ref) => catalogModel.stringifyEntityRef(
|
|
@@ -72,9 +68,7 @@ function createFetchCatalogEntityAction(options) {
|
|
|
72
68
|
)
|
|
73
69
|
)
|
|
74
70
|
},
|
|
75
|
-
{
|
|
76
|
-
token
|
|
77
|
-
}
|
|
71
|
+
{ credentials: await ctx.getInitiatorCredentials() }
|
|
78
72
|
);
|
|
79
73
|
const finalEntities = entities.items.map((e, i) => {
|
|
80
74
|
if (!e && !optional) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/fetch.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 {
|
|
1
|
+
{"version":3,"file":"fetch.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/fetch.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 { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { parseEntityRef, stringifyEntityRef } from '@backstage/catalog-model';\nimport { examples } from './fetch.examples';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\n\nconst id = 'catalog:fetch';\n\n/**\n * Returns entity or entities from the catalog by entity reference(s).\n *\n * @public\n */\nexport function createFetchCatalogEntityAction(options: {\n catalog: CatalogService;\n}) {\n const { catalog } = options;\n\n return createTemplateAction({\n id,\n description:\n 'Returns entity or entities from the catalog by entity reference(s)',\n examples,\n supportsDryRun: true,\n schema: {\n input: {\n entityRef: z =>\n z\n .string({\n description: 'Entity reference of the entity to get',\n })\n .optional(),\n entityRefs: z =>\n z\n .array(z.string(), {\n description: 'Entity references of the entities to get',\n })\n .optional(),\n optional: z =>\n z\n .boolean({\n description:\n 'Allow the entity or entities to optionally exist. Default: false',\n })\n .optional(),\n defaultKind: z =>\n z.string({ description: 'The default kind' }).optional(),\n defaultNamespace: z =>\n z.string({ description: 'The default namespace' }).optional(),\n },\n output: {\n entity: z =>\n z\n .any({\n description:\n 'Object containing same values used in the Entity schema. Only when used with `entityRef` parameter.',\n })\n .optional(),\n entities: z =>\n z\n .array(\n z.any({\n description:\n 'Array containing objects with same values used in the Entity schema. Only when used with `entityRefs` parameter.',\n }),\n )\n .optional(),\n },\n },\n async handler(ctx) {\n const { entityRef, entityRefs, optional, defaultKind, defaultNamespace } =\n ctx.input;\n\n if (!entityRef && !entityRefs) {\n if (optional) {\n return;\n }\n throw new Error('Missing entity reference or references');\n }\n\n if (entityRef) {\n const entity = await catalog.getEntityByRef(\n stringifyEntityRef(\n parseEntityRef(entityRef, { defaultKind, defaultNamespace }),\n ),\n {\n credentials: await ctx.getInitiatorCredentials(),\n },\n );\n\n if (!entity && !optional) {\n throw new Error(`Entity ${entityRef} not found`);\n }\n ctx.output('entity', entity ?? null);\n }\n\n if (entityRefs) {\n const entities = await catalog.getEntitiesByRefs(\n {\n entityRefs: entityRefs.map(ref =>\n stringifyEntityRef(\n parseEntityRef(ref, { defaultKind, defaultNamespace }),\n ),\n ),\n },\n { credentials: await ctx.getInitiatorCredentials() },\n );\n\n const finalEntities = entities.items.map((e, i) => {\n if (!e && !optional) {\n throw new Error(`Entity ${entityRefs[i]} not found`);\n }\n return e ?? null;\n });\n\n ctx.output('entities', finalEntities);\n }\n },\n });\n}\n"],"names":["createTemplateAction","examples","stringifyEntityRef","parseEntityRef"],"mappings":";;;;;;AAqBA,MAAM,EAAK,GAAA,eAAA;AAOJ,SAAS,+BAA+B,OAE5C,EAAA;AACD,EAAM,MAAA,EAAE,SAAY,GAAA,OAAA;AAEpB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAA;AAAA,IACA,WACE,EAAA,oEAAA;AAAA,cACFC,uBAAA;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,SAAA,EAAW,CACT,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,YAAY,CACV,CAAA,KAAA,CAAA,CACG,KAAM,CAAA,CAAA,CAAE,QAAU,EAAA;AAAA,UACjB,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,QAAA,EAAU,CACR,CAAA,KAAA,CAAA,CACG,OAAQ,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,WAAA,EAAa,OAC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AU,IAAI,CAAA;AAAA;AAGrC,MAAA,IAAI,UAAY,EAAA;AACd,QAAM,MAAA,QAAA,GAAW,MAAM,OAAQ,CAAA,iBAAA;AAAA,UAC7B;AAAA,YACE,YAAY,UAAW,CAAA,GAAA;AAAA,cAAI,CACzB,GAAA,KAAAD,+BAAA;AAAA,gBACEC,2BAAe,CAAA,GAAA,EAAK,EAAE,WAAA,EAAa,kBAAkB;AAAA;AACvD;AACF,WACF;AAAA,UACA,EAAE,WAAA,EAAa,MAAM,GAAA,CAAI,yBAA0B;AAAA,SACrD;AAEA,QAAA,MAAM,gBAAgB,QAAS,CAAA,KAAA,CAAM,GAAI,CAAA,CAAC,GAAG,CAAM,KAAA;AACjD,UAAI,IAAA,CAAC,CAAK,IAAA,CAAC,QAAU,EAAA;AACnB,YAAA,MAAM,IAAI,KAAM,CAAA,CAAA,OAAA,EAAU,UAAW,CAAA,CAAC,CAAC,CAAY,UAAA,CAAA,CAAA;AAAA;AAErD,UAAA,OAAO,CAAK,IAAA,IAAA;AAAA,SACb,CAAA;AAED,QAAI,GAAA,CAAA,MAAA,CAAO,YAAY,aAAa,CAAA;AAAA;AACtC;AACF,GACD,CAAA;AACH;;;;"}
|
|
@@ -7,65 +7,33 @@ var register_examples = require('./register.examples.cjs.js');
|
|
|
7
7
|
|
|
8
8
|
const id = "catalog:register";
|
|
9
9
|
function createCatalogRegisterAction(options) {
|
|
10
|
-
const {
|
|
10
|
+
const { catalog, integrations } = options;
|
|
11
11
|
return pluginScaffolderNode.createTemplateAction({
|
|
12
12
|
id,
|
|
13
13
|
description: "Registers entities from a catalog descriptor file in the workspace into the software catalog.",
|
|
14
14
|
examples: register_examples.examples,
|
|
15
15
|
schema: {
|
|
16
|
-
input:
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
}
|
|
16
|
+
input: (z) => z.union([
|
|
17
|
+
z.object({
|
|
18
|
+
catalogInfoUrl: z.string({
|
|
19
|
+
description: "An absolute URL pointing to the catalog info file location"
|
|
20
|
+
}),
|
|
21
|
+
optional: z.boolean({
|
|
22
|
+
description: "Permit the registered location to optionally exist. Default: false"
|
|
23
|
+
}).optional()
|
|
24
|
+
}),
|
|
25
|
+
z.object({
|
|
26
|
+
repoContentsUrl: z.string({
|
|
27
|
+
description: "An absolute URL pointing to the root of a repository directory tree"
|
|
28
|
+
}),
|
|
29
|
+
catalogInfoPath: z.string({
|
|
30
|
+
description: "A relative path from the repo root pointing to the catalog info file, defaults to /catalog-info.yaml"
|
|
31
|
+
}).optional(),
|
|
32
|
+
optional: z.boolean({
|
|
33
|
+
description: "Permit the registered location to optionally exist. Default: false"
|
|
34
|
+
}).optional()
|
|
35
|
+
})
|
|
36
|
+
])
|
|
69
37
|
},
|
|
70
38
|
async handler(ctx) {
|
|
71
39
|
const { input } = ctx;
|
|
@@ -86,17 +54,13 @@ function createCatalogRegisterAction(options) {
|
|
|
86
54
|
});
|
|
87
55
|
}
|
|
88
56
|
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
57
|
try {
|
|
94
|
-
await
|
|
58
|
+
await catalog.addLocation(
|
|
95
59
|
{
|
|
96
60
|
type: "url",
|
|
97
61
|
target: catalogInfoUrl
|
|
98
62
|
},
|
|
99
|
-
|
|
63
|
+
{ credentials: await ctx.getInitiatorCredentials() }
|
|
100
64
|
);
|
|
101
65
|
} catch (e) {
|
|
102
66
|
if (!input.optional) {
|
|
@@ -104,13 +68,13 @@ function createCatalogRegisterAction(options) {
|
|
|
104
68
|
}
|
|
105
69
|
}
|
|
106
70
|
try {
|
|
107
|
-
const result = await
|
|
71
|
+
const result = await catalog.addLocation(
|
|
108
72
|
{
|
|
109
73
|
dryRun: true,
|
|
110
74
|
type: "url",
|
|
111
75
|
target: catalogInfoUrl
|
|
112
76
|
},
|
|
113
|
-
|
|
77
|
+
{ credentials: await ctx.getInitiatorCredentials() }
|
|
114
78
|
);
|
|
115
79
|
if (result.entities.length) {
|
|
116
80
|
const { entities } = result;
|
|
@@ -1 +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 {
|
|
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 { stringifyEntityRef, Entity } from '@backstage/catalog-model';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { examples } from './register.examples';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\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 catalog: CatalogService;\n integrations: ScmIntegrations;\n}) {\n const { catalog, integrations } = options;\n\n return createTemplateAction({\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: z =>\n z.union([\n z.object({\n catalogInfoUrl: z.string({\n description:\n 'An absolute URL pointing to the catalog info file location',\n }),\n optional: z\n .boolean({\n description:\n 'Permit the registered location to optionally exist. Default: false',\n })\n .optional(),\n }),\n z.object({\n repoContentsUrl: z.string({\n description:\n 'An absolute URL pointing to the root of a repository directory tree',\n }),\n catalogInfoPath: z\n .string({\n description:\n 'A relative path from the repo root pointing to the catalog info file, defaults to /catalog-info.yaml',\n })\n .optional(),\n optional: z\n .boolean({\n description:\n 'Permit the registered location to optionally exist. Default: false',\n })\n .optional(),\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 try {\n // 1st try to register the location, this will throw an error if the location already exists (see catch)\n await catalog.addLocation(\n {\n type: 'url',\n target: catalogInfoUrl,\n },\n { credentials: await ctx.getInitiatorCredentials() },\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 catalog.addLocation(\n {\n dryRun: true,\n type: 'url',\n target: catalogInfoUrl,\n },\n { credentials: await ctx.getInitiatorCredentials() },\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","stringifyEntityR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AChB,OAAK,CAAC,CAAA,CAAE,QAAS,CAAA,IAAA,CAAK,WAAW,YAAY;AAAA,aAC/C;AAAA;AAEF,UAAA,IAAI,CAAC,MAAQ,EAAA;AACX,YAAA,MAAA,GAAS,SAAS,CAAC,CAAA;AAAA;AAGrB,UAAA,GAAA,CAAI,MAAO,CAAA,WAAA,EAAaC,+BAAmB,CAAA,MAAM,CAAC,CAAA;AAAA;AACpD,eACO,CAAG,EAAA;AACV,QAAI,IAAA,CAAC,MAAM,QAAU,EAAA;AACnB,UAAM,MAAA,CAAA;AAAA;AACR;AAGF,MAAI,GAAA,CAAA,MAAA,CAAO,kBAAkB,cAAc,CAAA;AAAA;AAC7C,GACD,CAAA;AACH;;;;"}
|
|
@@ -4,7 +4,6 @@ var fs = require('fs-extra');
|
|
|
4
4
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
5
5
|
var yaml = require('yaml');
|
|
6
6
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
7
|
-
var z = require('zod');
|
|
8
7
|
var write_examples = require('./write.examples.cjs.js');
|
|
9
8
|
|
|
10
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
@@ -36,13 +35,13 @@ function createCatalogWriteAction() {
|
|
|
36
35
|
id,
|
|
37
36
|
description: "Writes the catalog-info.yaml for your template",
|
|
38
37
|
schema: {
|
|
39
|
-
input:
|
|
40
|
-
filePath: z
|
|
38
|
+
input: {
|
|
39
|
+
filePath: (z) => z.string().optional().describe("Defaults to catalog-info.yaml"),
|
|
41
40
|
// TODO: this should reference an zod entity validator if it existed.
|
|
42
|
-
entity: z
|
|
41
|
+
entity: (z) => z.record(z.any()).describe(
|
|
43
42
|
"You can provide the same values used in the Entity schema."
|
|
44
43
|
)
|
|
45
|
-
}
|
|
44
|
+
}
|
|
46
45
|
},
|
|
47
46
|
examples: write_examples.examples,
|
|
48
47
|
supportsDryRun: true,
|
|
@@ -1 +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 {
|
|
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 { 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: {\n filePath: z =>\n z.string().optional().describe('Defaults to catalog-info.yaml'),\n // TODO: this should reference an zod entity validator if it existed.\n entity: z =>\n 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","examples","fs","resolveSafeChildPath","yaml"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,EAAK,GAAA,eAAA;AAOJ,SAAS,wBAA2B,GAAA;AACzC,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAA;AAAA,IACA,WAAa,EAAA,gDAAA;AAAA,IACb,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,QAAA,EAAU,OACR,CAAE,CAAA,MAAA,GAAS,QAAS,EAAA,CAAE,SAAS,+BAA+B,CAAA;AAAA;AAAA,QAEhE,QAAQ,CACN,CAAA,KAAA,CAAA,CACG,OAAO,CAAE,CAAA,GAAA,EAAK,CACd,CAAA,QAAA;AAAA,UACC;AAAA;AACF;AACN,KACF;AAAA,cACAC,uBAAA;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAA,MAAM,EAAE,QAAA,EAAU,MAAO,EAAA,GAAI,GAAI,CAAA,KAAA;AACjC,MAAM,MAAA,SAAA,GAAY,IAAI,YAAc,EAAA,SAAA;AACpC,MAAA,MAAM,OAAO,QAAY,IAAA,mBAAA;AACzB,MAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAAW,QAAA,EAAA,IAAI,CAAE,CAAA,CAAA;AAEjC,MAAA,MAAMC,mBAAG,CAAA,UAAA;AAAA,QACPC,qCAAA,CAAqB,GAAI,CAAA,aAAA,EAAe,IAAI,CAAA;AAAA,QAC5CC,gBAAK,SAAU,CAAA;AAAA,UACb,GAAG,MAAA;AAAA,UACH,QAAU,EAAA;AAAA,YACR,GAAG,MAAO,CAAA,QAAA;AAAA,YACV,GAAI,SACA,GAAA;AAAA,cACE,WAAa,EAAA;AAAA,gBACX,GAAG,OAAO,QAAS,CAAA,WAAA;AAAA,gBACnB,8BAAgC,EAAA;AAAA;AAClC,aAEF,GAAA,KAAA;AAAA;AACN,SACD;AAAA,OACH;AAAA;AACF,GACD,CAAA;AACH;;;;"}
|
|
@@ -5,7 +5,6 @@ var path = require('path');
|
|
|
5
5
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
6
6
|
var log_examples = require('./log.examples.cjs.js');
|
|
7
7
|
var fs = require('fs');
|
|
8
|
-
var z = require('zod');
|
|
9
8
|
|
|
10
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
11
10
|
|
|
@@ -18,12 +17,12 @@ function createDebugLogAction() {
|
|
|
18
17
|
description: "Writes a message into the log and/or lists all files in the workspace.",
|
|
19
18
|
examples: log_examples.examples,
|
|
20
19
|
schema: {
|
|
21
|
-
input:
|
|
22
|
-
message: z
|
|
23
|
-
listWorkspace: z
|
|
20
|
+
input: {
|
|
21
|
+
message: (z) => z.string({ description: "Message to output." }).optional(),
|
|
22
|
+
listWorkspace: (z) => z.union([z.boolean(), z.enum(["with-filenames", "with-contents"])], {
|
|
24
23
|
description: 'List all files in the workspace. If used with "with-contents", also the file contents are listed.'
|
|
25
24
|
}).optional()
|
|
26
|
-
}
|
|
25
|
+
}
|
|
27
26
|
},
|
|
28
27
|
supportsDryRun: true,
|
|
29
28
|
async handler(ctx) {
|