plugin-git-manager 1.2.26 → 1.2.27
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.
|
@@ -28,12 +28,14 @@ var registry_content_service_exports = {};
|
|
|
28
28
|
__export(registry_content_service_exports, {
|
|
29
29
|
REGISTRY_CONTENT_LIMIT_EXCEEDED: () => REGISTRY_CONTENT_LIMIT_EXCEEDED,
|
|
30
30
|
REGISTRY_EXPORT_NOT_GRANTED: () => REGISTRY_EXPORT_NOT_GRANTED,
|
|
31
|
+
REGISTRY_GIT_COMMAND_FAILED: () => REGISTRY_GIT_COMMAND_FAILED,
|
|
31
32
|
REGISTRY_GIT_CONTENT_CAPABILITIES: () => REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
32
33
|
REGISTRY_GIT_CONTENT_CONTRACT_VERSION: () => REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
33
34
|
REGISTRY_GIT_FILE_NOT_FOUND: () => REGISTRY_GIT_FILE_NOT_FOUND,
|
|
34
35
|
REGISTRY_REPOSITORY_ACCESS_DENIED: () => REGISTRY_REPOSITORY_ACCESS_DENIED,
|
|
35
36
|
RegistryContentLimitError: () => RegistryContentLimitError,
|
|
36
37
|
RegistryExportNotGrantedError: () => RegistryExportNotGrantedError,
|
|
38
|
+
RegistryGitCommandError: () => RegistryGitCommandError,
|
|
37
39
|
RegistryGitContentService: () => RegistryGitContentService,
|
|
38
40
|
RegistryGitFileNotFoundError: () => RegistryGitFileNotFoundError,
|
|
39
41
|
RegistryRepositoryAccessDeniedError: () => RegistryRepositoryAccessDeniedError,
|
|
@@ -54,13 +56,13 @@ function positiveLimit(value, fallback, maximum = Number.MAX_SAFE_INTEGER) {
|
|
|
54
56
|
}
|
|
55
57
|
const DEFAULT_REGISTRY_GIT_CONTENT_LIMITS = {
|
|
56
58
|
get maxFileBytes() {
|
|
57
|
-
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_FILE_BYTES,
|
|
59
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_FILE_BYTES, 100 * 1024 * 1024);
|
|
58
60
|
},
|
|
59
61
|
get maxTreeEntries() {
|
|
60
|
-
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_ENTRIES,
|
|
62
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_ENTRIES, 5e4);
|
|
61
63
|
},
|
|
62
64
|
get maxTreeOutputBytes() {
|
|
63
|
-
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_OUTPUT_BYTES,
|
|
65
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_OUTPUT_BYTES, 64 * 1024 * 1024);
|
|
64
66
|
}
|
|
65
67
|
};
|
|
66
68
|
const REGISTRY_EXPORT_NOT_GRANTED = "REGISTRY_EXPORT_NOT_GRANTED";
|
|
@@ -112,6 +114,14 @@ class RegistryGitFileNotFoundError extends Error {
|
|
|
112
114
|
this.name = "RegistryGitFileNotFoundError";
|
|
113
115
|
}
|
|
114
116
|
}
|
|
117
|
+
const REGISTRY_GIT_COMMAND_FAILED = "REGISTRY_GIT_COMMAND_FAILED";
|
|
118
|
+
class RegistryGitCommandError extends Error {
|
|
119
|
+
code = REGISTRY_GIT_COMMAND_FAILED;
|
|
120
|
+
constructor(message) {
|
|
121
|
+
super(message);
|
|
122
|
+
this.name = "RegistryGitCommandError";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
115
125
|
const REGISTRY_CONTENT_ACCESS_POLICY = {
|
|
116
126
|
contractVersion: REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
117
127
|
capabilities: REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
@@ -192,7 +202,7 @@ function runGitBuffer(localPath, args, maximumBytes, timeoutMs) {
|
|
|
192
202
|
reject(new RegistryGitFileNotFoundError());
|
|
193
203
|
return;
|
|
194
204
|
}
|
|
195
|
-
reject(new
|
|
205
|
+
reject(new RegistryGitCommandError(`git command failed: ${stderr.trim() || String(code)}`));
|
|
196
206
|
return;
|
|
197
207
|
}
|
|
198
208
|
resolve(Buffer.concat(chunks, outputBytes));
|
|
@@ -266,7 +276,7 @@ class GitContentService {
|
|
|
266
276
|
DEFAULT_GIT_TIMEOUT_MS
|
|
267
277
|
)).toString("utf8").trim();
|
|
268
278
|
if (!/^[a-f0-9]{40,64}$/i.test(result)) {
|
|
269
|
-
throw new
|
|
279
|
+
throw new RegistryGitCommandError("Git reference did not resolve to a commit SHA");
|
|
270
280
|
}
|
|
271
281
|
return result.toLowerCase();
|
|
272
282
|
}
|
|
@@ -334,7 +344,7 @@ class GitContentService {
|
|
|
334
344
|
child.once("spawn", () => resolve(child.stdout));
|
|
335
345
|
child.once("close", (code) => {
|
|
336
346
|
if (code !== 0) {
|
|
337
|
-
child.stdout.destroy(new
|
|
347
|
+
child.stdout.destroy(new RegistryGitCommandError(`git archive failed: ${stderr.trim() || String(code)}`));
|
|
338
348
|
}
|
|
339
349
|
});
|
|
340
350
|
});
|
|
@@ -377,7 +387,7 @@ class GitContentService {
|
|
|
377
387
|
assertCommitSha(value) {
|
|
378
388
|
const normalized = (0, import_git_actions.validateRef)(value);
|
|
379
389
|
if (!/^[a-f0-9]{40,64}$/i.test(normalized)) {
|
|
380
|
-
throw new
|
|
390
|
+
throw new RegistryGitCommandError("Registry reads require a full commit SHA");
|
|
381
391
|
}
|
|
382
392
|
return normalized.toLowerCase();
|
|
383
393
|
}
|
|
@@ -396,12 +406,14 @@ class SkillHubGitContentService extends GitContentService {
|
|
|
396
406
|
0 && (module.exports = {
|
|
397
407
|
REGISTRY_CONTENT_LIMIT_EXCEEDED,
|
|
398
408
|
REGISTRY_EXPORT_NOT_GRANTED,
|
|
409
|
+
REGISTRY_GIT_COMMAND_FAILED,
|
|
399
410
|
REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
400
411
|
REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
401
412
|
REGISTRY_GIT_FILE_NOT_FOUND,
|
|
402
413
|
REGISTRY_REPOSITORY_ACCESS_DENIED,
|
|
403
414
|
RegistryContentLimitError,
|
|
404
415
|
RegistryExportNotGrantedError,
|
|
416
|
+
RegistryGitCommandError,
|
|
405
417
|
RegistryGitContentService,
|
|
406
418
|
RegistryGitFileNotFoundError,
|
|
407
419
|
RegistryRepositoryAccessDeniedError,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"displayName": "Git Manager",
|
|
4
4
|
"displayName.zh-CN": "Git 管理器",
|
|
5
5
|
"description": "Manage Git repositories with PAT authentication - pull, push, fetch, diff, file browsing",
|
|
6
|
-
"version": "1.2.
|
|
6
|
+
"version": "1.2.27",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/server/index.js",
|
|
9
9
|
"files": [
|
|
@@ -1,473 +1,484 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
2
|
-
import { existsSync } from 'fs';
|
|
3
|
-
import type { Readable } from 'stream';
|
|
4
|
-
|
|
5
|
-
import type { Database } from '@nocobase/database';
|
|
6
|
-
|
|
7
|
-
import { getGitBinaryPath, validateLocalPath, validateRef } from '../actions/git-actions';
|
|
8
|
-
import {
|
|
9
|
-
hasRepositoryAccess,
|
|
10
|
-
type RegistryGitAccessContext,
|
|
11
|
-
type RepositoryPermissionChecker,
|
|
12
|
-
} from '../repository-access';
|
|
13
|
-
|
|
14
|
-
export type { RegistryGitAccessContext } from '../repository-access';
|
|
15
|
-
|
|
16
|
-
function positiveLimit(value: string | undefined, fallback: number, maximum = Number.MAX_SAFE_INTEGER): number {
|
|
17
|
-
const parsed = Number(value);
|
|
18
|
-
return Number.isSafeInteger(parsed) && parsed > 0 && parsed <= maximum ? parsed : fallback;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Registry reads are bounded before their buffers can be handed to a provider.
|
|
22
|
-
// The defaults stay below the Registry artifact limits and can be tightened per deployment.
|
|
23
|
-
export interface RegistryGitContentLimits {
|
|
24
|
-
maxFileBytes: number;
|
|
25
|
-
maxTreeEntries: number;
|
|
26
|
-
maxTreeOutputBytes: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Getter-based limits re-read env vars on every access, so runtime settings
|
|
30
|
-
// applied via Skill Registry's applyRuntimeOverrides() take effect without restart.
|
|
31
|
-
const DEFAULT_REGISTRY_GIT_CONTENT_LIMITS: RegistryGitContentLimits = {
|
|
32
|
-
get maxFileBytes() {
|
|
33
|
-
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_FILE_BYTES,
|
|
34
|
-
},
|
|
35
|
-
get maxTreeEntries() {
|
|
36
|
-
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_ENTRIES,
|
|
37
|
-
},
|
|
38
|
-
get maxTreeOutputBytes() {
|
|
39
|
-
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_OUTPUT_BYTES,
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export interface RegistryGitTreeEntry {
|
|
44
|
-
type: 'blob' | 'tree';
|
|
45
|
-
path: string;
|
|
46
|
-
size: number;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
type RepositoryModel = {
|
|
50
|
-
get(attribute: string): unknown;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const REGISTRY_EXPORT_NOT_GRANTED = 'REGISTRY_EXPORT_NOT_GRANTED';
|
|
54
|
-
export const REGISTRY_REPOSITORY_ACCESS_DENIED = 'REGISTRY_REPOSITORY_ACCESS_DENIED';
|
|
55
|
-
export const SKILL_HUB_REPOSITORY_ACCESS_DENIED = 'SKILL_HUB_REPOSITORY_ACCESS_DENIED';
|
|
56
|
-
export const REGISTRY_CONTENT_LIMIT_EXCEEDED = 'REGISTRY_CONTENT_LIMIT_EXCEEDED';
|
|
57
|
-
export const REGISTRY_GIT_FILE_NOT_FOUND = 'REGISTRY_GIT_FILE_NOT_FOUND';
|
|
58
|
-
export const REGISTRY_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
59
|
-
export const REGISTRY_GIT_CONTENT_CAPABILITIES = [
|
|
60
|
-
'registry-content-with-actor',
|
|
61
|
-
'registry-content-authorize-source',
|
|
62
|
-
] as const;
|
|
63
|
-
export const SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
64
|
-
export const SKILL_HUB_GIT_CONTENT_CAPABILITIES = ['skill-hub-content-with-actor'] as const;
|
|
65
|
-
|
|
66
|
-
const DEFAULT_GIT_TIMEOUT_MS = 30_000;
|
|
67
|
-
const MAX_STDERR_BYTES = 64 * 1024;
|
|
68
|
-
|
|
69
|
-
export class RegistryExportNotGrantedError extends Error {
|
|
70
|
-
readonly code = REGISTRY_EXPORT_NOT_GRANTED;
|
|
71
|
-
|
|
72
|
-
constructor() {
|
|
73
|
-
super('Registry export is not enabled for this repository.');
|
|
74
|
-
this.name = 'RegistryExportNotGrantedError';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export class RegistryRepositoryAccessDeniedError extends Error {
|
|
79
|
-
readonly code = REGISTRY_REPOSITORY_ACCESS_DENIED;
|
|
80
|
-
|
|
81
|
-
constructor() {
|
|
82
|
-
super('The current actor is not authorized to read this repository for registry export.');
|
|
83
|
-
this.name = 'RegistryRepositoryAccessDeniedError';
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export class SkillHubRepositoryAccessDeniedError extends Error {
|
|
88
|
-
readonly code = SKILL_HUB_REPOSITORY_ACCESS_DENIED;
|
|
89
|
-
|
|
90
|
-
constructor() {
|
|
91
|
-
super('The current actor is not authorized to read this repository for Skill Hub.');
|
|
92
|
-
this.name = 'SkillHubRepositoryAccessDeniedError';
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export class RegistryContentLimitError extends Error {
|
|
97
|
-
readonly code = REGISTRY_CONTENT_LIMIT_EXCEEDED;
|
|
98
|
-
|
|
99
|
-
constructor(message: string) {
|
|
100
|
-
super(message);
|
|
101
|
-
this.name = 'RegistryContentLimitError';
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export class RegistryGitFileNotFoundError extends Error {
|
|
106
|
-
readonly code = REGISTRY_GIT_FILE_NOT_FOUND;
|
|
107
|
-
|
|
108
|
-
constructor() {
|
|
109
|
-
super('Git file was not found at the pinned commit.');
|
|
110
|
-
this.name = 'RegistryGitFileNotFoundError';
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
child.
|
|
178
|
-
if (
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function
|
|
230
|
-
const normalized =
|
|
231
|
-
if (!normalized) {
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
return
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
)
|
|
294
|
-
|
|
295
|
-
.
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
)
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
throw
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
throw
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import type { Readable } from 'stream';
|
|
4
|
+
|
|
5
|
+
import type { Database } from '@nocobase/database';
|
|
6
|
+
|
|
7
|
+
import { getGitBinaryPath, validateLocalPath, validateRef } from '../actions/git-actions';
|
|
8
|
+
import {
|
|
9
|
+
hasRepositoryAccess,
|
|
10
|
+
type RegistryGitAccessContext,
|
|
11
|
+
type RepositoryPermissionChecker,
|
|
12
|
+
} from '../repository-access';
|
|
13
|
+
|
|
14
|
+
export type { RegistryGitAccessContext } from '../repository-access';
|
|
15
|
+
|
|
16
|
+
function positiveLimit(value: string | undefined, fallback: number, maximum = Number.MAX_SAFE_INTEGER): number {
|
|
17
|
+
const parsed = Number(value);
|
|
18
|
+
return Number.isSafeInteger(parsed) && parsed > 0 && parsed <= maximum ? parsed : fallback;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Registry reads are bounded before their buffers can be handed to a provider.
|
|
22
|
+
// The defaults stay below the Registry artifact limits and can be tightened per deployment.
|
|
23
|
+
export interface RegistryGitContentLimits {
|
|
24
|
+
maxFileBytes: number;
|
|
25
|
+
maxTreeEntries: number;
|
|
26
|
+
maxTreeOutputBytes: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Getter-based limits re-read env vars on every access, so runtime settings
|
|
30
|
+
// applied via Skill Registry's applyRuntimeOverrides() take effect without restart.
|
|
31
|
+
const DEFAULT_REGISTRY_GIT_CONTENT_LIMITS: RegistryGitContentLimits = {
|
|
32
|
+
get maxFileBytes() {
|
|
33
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_FILE_BYTES, 100 * 1024 * 1024);
|
|
34
|
+
},
|
|
35
|
+
get maxTreeEntries() {
|
|
36
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_ENTRIES, 50000);
|
|
37
|
+
},
|
|
38
|
+
get maxTreeOutputBytes() {
|
|
39
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_OUTPUT_BYTES, 64 * 1024 * 1024);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export interface RegistryGitTreeEntry {
|
|
44
|
+
type: 'blob' | 'tree';
|
|
45
|
+
path: string;
|
|
46
|
+
size: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type RepositoryModel = {
|
|
50
|
+
get(attribute: string): unknown;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const REGISTRY_EXPORT_NOT_GRANTED = 'REGISTRY_EXPORT_NOT_GRANTED';
|
|
54
|
+
export const REGISTRY_REPOSITORY_ACCESS_DENIED = 'REGISTRY_REPOSITORY_ACCESS_DENIED';
|
|
55
|
+
export const SKILL_HUB_REPOSITORY_ACCESS_DENIED = 'SKILL_HUB_REPOSITORY_ACCESS_DENIED';
|
|
56
|
+
export const REGISTRY_CONTENT_LIMIT_EXCEEDED = 'REGISTRY_CONTENT_LIMIT_EXCEEDED';
|
|
57
|
+
export const REGISTRY_GIT_FILE_NOT_FOUND = 'REGISTRY_GIT_FILE_NOT_FOUND';
|
|
58
|
+
export const REGISTRY_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
59
|
+
export const REGISTRY_GIT_CONTENT_CAPABILITIES = [
|
|
60
|
+
'registry-content-with-actor',
|
|
61
|
+
'registry-content-authorize-source',
|
|
62
|
+
] as const;
|
|
63
|
+
export const SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
64
|
+
export const SKILL_HUB_GIT_CONTENT_CAPABILITIES = ['skill-hub-content-with-actor'] as const;
|
|
65
|
+
|
|
66
|
+
const DEFAULT_GIT_TIMEOUT_MS = 30_000;
|
|
67
|
+
const MAX_STDERR_BYTES = 64 * 1024;
|
|
68
|
+
|
|
69
|
+
export class RegistryExportNotGrantedError extends Error {
|
|
70
|
+
readonly code = REGISTRY_EXPORT_NOT_GRANTED;
|
|
71
|
+
|
|
72
|
+
constructor() {
|
|
73
|
+
super('Registry export is not enabled for this repository.');
|
|
74
|
+
this.name = 'RegistryExportNotGrantedError';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export class RegistryRepositoryAccessDeniedError extends Error {
|
|
79
|
+
readonly code = REGISTRY_REPOSITORY_ACCESS_DENIED;
|
|
80
|
+
|
|
81
|
+
constructor() {
|
|
82
|
+
super('The current actor is not authorized to read this repository for registry export.');
|
|
83
|
+
this.name = 'RegistryRepositoryAccessDeniedError';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export class SkillHubRepositoryAccessDeniedError extends Error {
|
|
88
|
+
readonly code = SKILL_HUB_REPOSITORY_ACCESS_DENIED;
|
|
89
|
+
|
|
90
|
+
constructor() {
|
|
91
|
+
super('The current actor is not authorized to read this repository for Skill Hub.');
|
|
92
|
+
this.name = 'SkillHubRepositoryAccessDeniedError';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export class RegistryContentLimitError extends Error {
|
|
97
|
+
readonly code = REGISTRY_CONTENT_LIMIT_EXCEEDED;
|
|
98
|
+
|
|
99
|
+
constructor(message: string) {
|
|
100
|
+
super(message);
|
|
101
|
+
this.name = 'RegistryContentLimitError';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export class RegistryGitFileNotFoundError extends Error {
|
|
106
|
+
readonly code = REGISTRY_GIT_FILE_NOT_FOUND;
|
|
107
|
+
|
|
108
|
+
constructor() {
|
|
109
|
+
super('Git file was not found at the pinned commit.');
|
|
110
|
+
this.name = 'RegistryGitFileNotFoundError';
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const REGISTRY_GIT_COMMAND_FAILED = 'REGISTRY_GIT_COMMAND_FAILED';
|
|
115
|
+
|
|
116
|
+
export class RegistryGitCommandError extends Error {
|
|
117
|
+
readonly code = REGISTRY_GIT_COMMAND_FAILED;
|
|
118
|
+
|
|
119
|
+
constructor(message: string) {
|
|
120
|
+
super(message);
|
|
121
|
+
this.name = 'RegistryGitCommandError';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface GitContentAccessPolicy {
|
|
126
|
+
contractVersion: number;
|
|
127
|
+
capabilities: readonly string[];
|
|
128
|
+
allowsSystemScheduledSync: boolean;
|
|
129
|
+
requiresRegistryExport: boolean;
|
|
130
|
+
createAccessDeniedError(): Error;
|
|
131
|
+
createRepositoryUnavailableError(): Error;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const REGISTRY_CONTENT_ACCESS_POLICY: GitContentAccessPolicy = {
|
|
135
|
+
contractVersion: REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
136
|
+
capabilities: REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
137
|
+
allowsSystemScheduledSync: true,
|
|
138
|
+
requiresRegistryExport: true,
|
|
139
|
+
createAccessDeniedError: () => new RegistryRepositoryAccessDeniedError(),
|
|
140
|
+
createRepositoryUnavailableError: () => new RegistryExportNotGrantedError(),
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const SKILL_HUB_CONTENT_ACCESS_POLICY: GitContentAccessPolicy = {
|
|
144
|
+
contractVersion: SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION,
|
|
145
|
+
capabilities: SKILL_HUB_GIT_CONTENT_CAPABILITIES,
|
|
146
|
+
allowsSystemScheduledSync: false,
|
|
147
|
+
requiresRegistryExport: false,
|
|
148
|
+
createAccessDeniedError: () => new SkillHubRepositoryAccessDeniedError(),
|
|
149
|
+
createRepositoryUnavailableError: () => new SkillHubRepositoryAccessDeniedError(),
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
function boundedPositive(value: number | undefined, fallback: number, maximum: number): number {
|
|
153
|
+
return Number.isSafeInteger(value) && Number(value) > 0 && Number(value) <= maximum ? Number(value) : fallback;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function runGitBuffer(localPath: string, args: string[], maximumBytes: number, timeoutMs: number): Promise<Buffer> {
|
|
157
|
+
return new Promise<Buffer>((resolve, reject) => {
|
|
158
|
+
const child = spawn(getGitBinaryPath(), ['-C', localPath, ...args], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
159
|
+
const chunks: Buffer[] = [];
|
|
160
|
+
let outputBytes = 0;
|
|
161
|
+
let stderr = '';
|
|
162
|
+
let stderrBytes = 0;
|
|
163
|
+
let settled = false;
|
|
164
|
+
let pendingFailure: Error | undefined;
|
|
165
|
+
const stop = (error: Error) => {
|
|
166
|
+
if (settled || pendingFailure) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
pendingFailure = error;
|
|
170
|
+
clearTimeout(timer);
|
|
171
|
+
child.kill();
|
|
172
|
+
};
|
|
173
|
+
const timer = setTimeout(() => {
|
|
174
|
+
stop(new RegistryContentLimitError('Git registry read exceeded its execution timeout.'));
|
|
175
|
+
}, timeoutMs);
|
|
176
|
+
|
|
177
|
+
child.stdout.on('data', (chunk: Buffer) => {
|
|
178
|
+
if (settled) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
outputBytes += chunk.length;
|
|
182
|
+
if (outputBytes > maximumBytes) {
|
|
183
|
+
stop(new RegistryContentLimitError('Git registry read exceeded its output limit.'));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
chunks.push(chunk);
|
|
187
|
+
});
|
|
188
|
+
child.stderr.on('data', (chunk: Buffer) => {
|
|
189
|
+
if (stderrBytes >= MAX_STDERR_BYTES) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const remaining = MAX_STDERR_BYTES - stderrBytes;
|
|
193
|
+
const bounded = chunk.subarray(0, remaining);
|
|
194
|
+
stderrBytes += bounded.length;
|
|
195
|
+
stderr += bounded.toString('utf8');
|
|
196
|
+
});
|
|
197
|
+
child.once('error', (error) => {
|
|
198
|
+
if (!pendingFailure) {
|
|
199
|
+
pendingFailure = error;
|
|
200
|
+
clearTimeout(timer);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
child.once('close', (code) => {
|
|
204
|
+
if (settled) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
settled = true;
|
|
208
|
+
clearTimeout(timer);
|
|
209
|
+
// `close` guarantees that the child process and both stdio streams have
|
|
210
|
+
// released their handles. In particular, Windows otherwise may still
|
|
211
|
+
// hold a temporary Git repository directory after an output-limit kill.
|
|
212
|
+
if (pendingFailure) {
|
|
213
|
+
reject(pendingFailure);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (code !== 0) {
|
|
217
|
+
if (/does not exist in|exists on disk, but not in|path .* does not exist/i.test(stderr)) {
|
|
218
|
+
reject(new RegistryGitFileNotFoundError());
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
reject(new RegistryGitCommandError(`git command failed: ${stderr.trim() || String(code)}`));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
resolve(Buffer.concat(chunks, outputBytes));
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function normalizeRootPath(value: string): string {
|
|
230
|
+
const normalized = value.replace(/\\/g, '/').replace(/^\/+|\/+$/g, '');
|
|
231
|
+
if (!normalized) {
|
|
232
|
+
return '';
|
|
233
|
+
}
|
|
234
|
+
if (normalized.includes('\0') || normalized.split('/').some((part) => part === '.' || part === '..' || part === '')) {
|
|
235
|
+
throw new Error('Invalid repository path');
|
|
236
|
+
}
|
|
237
|
+
return normalized;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function normalizeFilePath(value: string): string {
|
|
241
|
+
const normalized = normalizeRootPath(value);
|
|
242
|
+
if (!normalized) {
|
|
243
|
+
throw new Error('File path is required');
|
|
244
|
+
}
|
|
245
|
+
return normalized;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function repositoryValue(repository: RepositoryModel, field: string): string {
|
|
249
|
+
const value = repository.get(field);
|
|
250
|
+
return typeof value === 'string' ? value : value === null || value === undefined ? '' : String(value);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function parseTreeLine(line: string, rootPath: string): RegistryGitTreeEntry | null {
|
|
254
|
+
const match = line.match(/^(\d+)\s+(blob|tree)\s+([a-f0-9]+)\s+(-|\d+)\t(.+)$/);
|
|
255
|
+
if (!match) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const candidatePath = match[5].replace(/\\/g, '/');
|
|
259
|
+
const prefix = rootPath ? `${rootPath}/` : '';
|
|
260
|
+
const path = candidatePath.startsWith(prefix) ? candidatePath.slice(prefix.length) : candidatePath;
|
|
261
|
+
return {
|
|
262
|
+
type: match[2] as 'blob' | 'tree',
|
|
263
|
+
path: normalizeRootPath(path),
|
|
264
|
+
size: match[4] === '-' ? 0 : Number.parseInt(match[4], 10),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
class GitContentService {
|
|
269
|
+
readonly contractVersion: number;
|
|
270
|
+
readonly capabilities: readonly string[];
|
|
271
|
+
|
|
272
|
+
constructor(
|
|
273
|
+
private readonly database: Database,
|
|
274
|
+
private readonly limits: RegistryGitContentLimits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS,
|
|
275
|
+
private readonly acl?: RepositoryPermissionChecker,
|
|
276
|
+
private readonly accessPolicy: GitContentAccessPolicy = REGISTRY_CONTENT_ACCESS_POLICY,
|
|
277
|
+
) {
|
|
278
|
+
this.contractVersion = accessPolicy.contractVersion;
|
|
279
|
+
this.capabilities = accessPolicy.capabilities;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Validates actor access before a cross-plugin service binds or reads a
|
|
284
|
+
* repository. The concrete service policy decides whether Registry export
|
|
285
|
+
* opt-in or scheduled system access is permitted.
|
|
286
|
+
*/
|
|
287
|
+
async assertRepositoryAccess(repositoryId: string | number, access?: RegistryGitAccessContext): Promise<void> {
|
|
288
|
+
await this.findRepository(repositoryId, access);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async resolveCommit(repositoryId: string | number, ref: string, access?: RegistryGitAccessContext): Promise<string> {
|
|
292
|
+
const repository = await this.findRepository(repositoryId, access);
|
|
293
|
+
const localPath = validateLocalPath(repositoryValue(repository, 'localPath'));
|
|
294
|
+
if (!existsSync(localPath)) {
|
|
295
|
+
throw new Error('Repository directory does not exist. Clone the repository before reading its content.');
|
|
296
|
+
}
|
|
297
|
+
const result = (
|
|
298
|
+
await runGitBuffer(
|
|
299
|
+
localPath,
|
|
300
|
+
['rev-parse', '--verify', `${validateRef(ref)}^{commit}`],
|
|
301
|
+
256,
|
|
302
|
+
DEFAULT_GIT_TIMEOUT_MS,
|
|
303
|
+
)
|
|
304
|
+
)
|
|
305
|
+
.toString('utf8')
|
|
306
|
+
.trim();
|
|
307
|
+
if (!/^[a-f0-9]{40,64}$/i.test(result)) {
|
|
308
|
+
throw new RegistryGitCommandError('Git reference did not resolve to a commit SHA');
|
|
309
|
+
}
|
|
310
|
+
return result.toLowerCase();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async listTree(
|
|
314
|
+
input: {
|
|
315
|
+
repositoryId: string | number;
|
|
316
|
+
commitSha: string;
|
|
317
|
+
rootPath: string;
|
|
318
|
+
recursive: boolean;
|
|
319
|
+
},
|
|
320
|
+
access?: RegistryGitAccessContext,
|
|
321
|
+
): Promise<RegistryGitTreeEntry[]> {
|
|
322
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
323
|
+
const localPath = validateLocalPath(repositoryValue(repository, 'localPath'));
|
|
324
|
+
if (!existsSync(localPath)) {
|
|
325
|
+
throw new Error('Repository directory does not exist. Clone the repository before reading its content.');
|
|
326
|
+
}
|
|
327
|
+
const commitSha = this.assertCommitSha(input.commitSha);
|
|
328
|
+
const rootPath = normalizeRootPath(input.rootPath);
|
|
329
|
+
const target = rootPath ? `${commitSha}:${rootPath}` : commitSha;
|
|
330
|
+
const output = await runGitBuffer(
|
|
331
|
+
localPath,
|
|
332
|
+
['ls-tree', '-l', ...(input.recursive ? ['-r'] : []), target],
|
|
333
|
+
this.limits.maxTreeOutputBytes,
|
|
334
|
+
DEFAULT_GIT_TIMEOUT_MS,
|
|
335
|
+
);
|
|
336
|
+
const lines = output.toString('utf8').trim().split('\n').filter(Boolean);
|
|
337
|
+
if (lines.length > this.limits.maxTreeEntries) {
|
|
338
|
+
throw new RegistryContentLimitError('Git tree contains too many entries for registry export.');
|
|
339
|
+
}
|
|
340
|
+
return lines
|
|
341
|
+
.map((line) => parseTreeLine(line, rootPath))
|
|
342
|
+
.filter((entry): entry is RegistryGitTreeEntry => entry !== null)
|
|
343
|
+
.sort((left, right) => left.path.localeCompare(right.path));
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async readFile(
|
|
347
|
+
input: {
|
|
348
|
+
repositoryId: string | number;
|
|
349
|
+
commitSha: string;
|
|
350
|
+
filePath: string;
|
|
351
|
+
maxBytes?: number;
|
|
352
|
+
},
|
|
353
|
+
access?: RegistryGitAccessContext,
|
|
354
|
+
): Promise<Buffer> {
|
|
355
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
356
|
+
const localPath = validateLocalPath(repositoryValue(repository, 'localPath'));
|
|
357
|
+
if (!existsSync(localPath)) {
|
|
358
|
+
throw new Error('Repository directory does not exist. Clone the repository before reading its content.');
|
|
359
|
+
}
|
|
360
|
+
const commitSha = this.assertCommitSha(input.commitSha);
|
|
361
|
+
const filePath = normalizeFilePath(input.filePath);
|
|
362
|
+
const maximumBytes = boundedPositive(input.maxBytes, this.limits.maxFileBytes, this.limits.maxFileBytes);
|
|
363
|
+
try {
|
|
364
|
+
return await runGitBuffer(localPath, ['show', `${commitSha}:${filePath}`], maximumBytes, DEFAULT_GIT_TIMEOUT_MS);
|
|
365
|
+
} catch (error) {
|
|
366
|
+
if (error instanceof RegistryContentLimitError && error.message.includes('output limit')) {
|
|
367
|
+
throw new RegistryContentLimitError('Git file exceeds the registry source-file limit.');
|
|
368
|
+
}
|
|
369
|
+
throw error;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
async archiveTree(
|
|
374
|
+
input: { repositoryId: string | number; commitSha: string; rootPath: string },
|
|
375
|
+
access?: RegistryGitAccessContext,
|
|
376
|
+
): Promise<Readable> {
|
|
377
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
378
|
+
const localPath = validateLocalPath(repositoryValue(repository, 'localPath'));
|
|
379
|
+
if (!existsSync(localPath)) {
|
|
380
|
+
throw new Error('Repository directory does not exist. Clone the repository before reading its content.');
|
|
381
|
+
}
|
|
382
|
+
const commitSha = this.assertCommitSha(input.commitSha);
|
|
383
|
+
const rootPath = normalizeRootPath(input.rootPath);
|
|
384
|
+
return new Promise<Readable>((resolve, reject) => {
|
|
385
|
+
const child = spawn(
|
|
386
|
+
getGitBinaryPath(),
|
|
387
|
+
['-C', localPath, 'archive', '--format=zip', commitSha, ...(rootPath ? [rootPath] : [])],
|
|
388
|
+
{ stdio: ['ignore', 'pipe', 'pipe'] },
|
|
389
|
+
);
|
|
390
|
+
let stderr = '';
|
|
391
|
+
child.stderr.on('data', (chunk: Buffer) => {
|
|
392
|
+
if (Buffer.byteLength(stderr, 'utf8') >= MAX_STDERR_BYTES) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
stderr += chunk.toString('utf8').slice(0, MAX_STDERR_BYTES - Buffer.byteLength(stderr, 'utf8'));
|
|
396
|
+
});
|
|
397
|
+
child.once('error', reject);
|
|
398
|
+
child.once('spawn', () => resolve(child.stdout));
|
|
399
|
+
child.once('close', (code) => {
|
|
400
|
+
if (code !== 0) {
|
|
401
|
+
child.stdout.destroy(new RegistryGitCommandError(`git archive failed: ${stderr.trim() || String(code)}`));
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
private async findRepository(
|
|
408
|
+
repositoryId: string | number,
|
|
409
|
+
access?: RegistryGitAccessContext,
|
|
410
|
+
): Promise<RepositoryModel> {
|
|
411
|
+
await this.assertAccess(repositoryId, access);
|
|
412
|
+
const repository = await this.database.getRepository('gitRepositories').findOne({ filterByTk: repositoryId });
|
|
413
|
+
if (!repository) {
|
|
414
|
+
// Do not distinguish a missing repository from one that exists but has not
|
|
415
|
+
// granted registry export. Callers cannot use this bridge to enumerate
|
|
416
|
+
// repository IDs or infer private repository existence.
|
|
417
|
+
throw this.accessPolicy.createRepositoryUnavailableError();
|
|
418
|
+
}
|
|
419
|
+
const repositoryModel = repository as unknown as RepositoryModel;
|
|
420
|
+
if (this.accessPolicy.requiresRegistryExport && repositoryModel.get('registryExportEnabled') !== true) {
|
|
421
|
+
throw new RegistryExportNotGrantedError();
|
|
422
|
+
}
|
|
423
|
+
return repositoryModel;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
private async assertAccess(repositoryId: string | number, access?: RegistryGitAccessContext): Promise<void> {
|
|
427
|
+
if (!access) {
|
|
428
|
+
// The old call shape is intentionally retained for a stable TypeScript
|
|
429
|
+
// boundary, but treating missing identity as a system caller would let
|
|
430
|
+
// user-triggered cross-plugin calls bypass repository-scoped ACL.
|
|
431
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
432
|
+
}
|
|
433
|
+
if (access.kind === 'system') {
|
|
434
|
+
if (this.accessPolicy.allowsSystemScheduledSync && access.reason === 'scheduled-sync') {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
438
|
+
}
|
|
439
|
+
if (
|
|
440
|
+
access.kind !== 'user' ||
|
|
441
|
+
!Array.isArray(access.roles) ||
|
|
442
|
+
!access.roles.every((role) => typeof role === 'string')
|
|
443
|
+
) {
|
|
444
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
445
|
+
}
|
|
446
|
+
const allowed = await hasRepositoryAccess({
|
|
447
|
+
acl: this.acl,
|
|
448
|
+
roles: access.roles,
|
|
449
|
+
repositoryId,
|
|
450
|
+
action: 'fileContent',
|
|
451
|
+
});
|
|
452
|
+
if (!allowed) {
|
|
453
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
private assertCommitSha(value: string): string {
|
|
458
|
+
const normalized = validateRef(value);
|
|
459
|
+
if (!/^[a-f0-9]{40,64}$/i.test(normalized)) {
|
|
460
|
+
throw new RegistryGitCommandError('Registry reads require a full commit SHA');
|
|
461
|
+
}
|
|
462
|
+
return normalized.toLowerCase();
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export class RegistryGitContentService extends GitContentService {
|
|
467
|
+
constructor(
|
|
468
|
+
database: Database,
|
|
469
|
+
limits: RegistryGitContentLimits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS,
|
|
470
|
+
acl?: RepositoryPermissionChecker,
|
|
471
|
+
) {
|
|
472
|
+
super(database, limits, acl, REGISTRY_CONTENT_ACCESS_POLICY);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export class SkillHubGitContentService extends GitContentService {
|
|
477
|
+
constructor(
|
|
478
|
+
database: Database,
|
|
479
|
+
limits: RegistryGitContentLimits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS,
|
|
480
|
+
acl?: RepositoryPermissionChecker,
|
|
481
|
+
) {
|
|
482
|
+
super(database, limits, acl, SKILL_HUB_CONTENT_ACCESS_POLICY);
|
|
483
|
+
}
|
|
484
|
+
}
|