@goodandready/dsh-cron 0.3.6 → 0.3.7
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/lib/index.js +4 -0
- package/lib/metrics.js +5 -0
- package/lib/routes.js +20 -1
- package/lib/validators.js +2 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -305,6 +305,10 @@ export function apply(ctx, rawConfig) {
|
|
|
305
305
|
path: '/dsh-cron/settings',
|
|
306
306
|
handler: async (req, res) => {
|
|
307
307
|
try {
|
|
308
|
+
const settings = store && typeof store.getSettings === 'function' ? store.getSettings() : {};
|
|
309
|
+
const apiToken = settings.apiToken;
|
|
310
|
+
if (rejectCrossOrigin(req, res, { apiToken })) return;
|
|
311
|
+
|
|
308
312
|
if (req.method === 'GET') {
|
|
309
313
|
const unwrapped = {
|
|
310
314
|
...unwrapConfig(getContextConfig(ctx, rawConfig)),
|
package/lib/metrics.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rejectCrossOrigin } from './http-utils.js';
|
|
1
2
|
/**
|
|
2
3
|
* Prometheus exposition of the scheduler (#53).
|
|
3
4
|
*
|
|
@@ -108,6 +109,10 @@ export function createMetricsHandler({ store, scheduler }) {
|
|
|
108
109
|
res.end('Method not allowed' + NL);
|
|
109
110
|
return;
|
|
110
111
|
}
|
|
112
|
+
const settings = store && typeof store.getSettings === 'function' ? store.getSettings() : {};
|
|
113
|
+
const apiToken = settings.apiToken;
|
|
114
|
+
if (rejectCrossOrigin(req, res, { apiToken })) return;
|
|
115
|
+
|
|
111
116
|
const body = renderMetrics({
|
|
112
117
|
tasks: store.list({ status: 'all' }),
|
|
113
118
|
stats: store.getAggregatedStats(),
|
package/lib/routes.js
CHANGED
|
@@ -88,6 +88,9 @@ export function registerRoutes(ctx, { store, scheduler, recommendations }) {
|
|
|
88
88
|
kind: 'exact',
|
|
89
89
|
path: '/dsh-cron/models',
|
|
90
90
|
handler: async (req, res) => {
|
|
91
|
+
const settings = store && typeof store.getSettings === 'function' ? store.getSettings() : {};
|
|
92
|
+
const apiToken = settings.apiToken;
|
|
93
|
+
if (rejectCrossOrigin(req, res, { apiToken })) return;
|
|
91
94
|
await getModelsHandler(ctx, req, res, sendJson);
|
|
92
95
|
}
|
|
93
96
|
}), 'dsh-cron: /models');
|
|
@@ -108,6 +111,10 @@ export function registerRoutes(ctx, { store, scheduler, recommendations }) {
|
|
|
108
111
|
path: '/dsh-cron/analytics',
|
|
109
112
|
handler: async (req, res) => {
|
|
110
113
|
try {
|
|
114
|
+
const settings = store && typeof store.getSettings === 'function' ? store.getSettings() : {};
|
|
115
|
+
const apiToken = settings.apiToken;
|
|
116
|
+
if (rejectCrossOrigin(req, res, { apiToken })) return;
|
|
117
|
+
|
|
111
118
|
const url = new URL(req.url, 'http://127.0.0.1');
|
|
112
119
|
const path = url.pathname;
|
|
113
120
|
|
|
@@ -211,6 +218,8 @@ export function registerRoutes(ctx, { store, scheduler, recommendations }) {
|
|
|
211
218
|
return;
|
|
212
219
|
}
|
|
213
220
|
const settings = store.getSettings ? store.getSettings() : {};
|
|
221
|
+
const apiToken = settings.apiToken;
|
|
222
|
+
if (rejectCrossOrigin(req, res, { apiToken })) return;
|
|
214
223
|
const categories = recipesByCategory();
|
|
215
224
|
const recipes = listVerifiedRecipes(settings);
|
|
216
225
|
sendJson(res, 200, { ok: true, categories, recipes });
|
|
@@ -230,6 +239,10 @@ export function registerRoutes(ctx, { store, scheduler, recommendations }) {
|
|
|
230
239
|
sendJson(res, 405, { ok: false, error: 'Method not allowed' });
|
|
231
240
|
return;
|
|
232
241
|
}
|
|
242
|
+
const settings = store.getSettings ? store.getSettings() : {};
|
|
243
|
+
const apiToken = settings.apiToken;
|
|
244
|
+
if (rejectCrossOrigin(req, res, { apiToken })) return;
|
|
245
|
+
|
|
233
246
|
const tasks = store.list({ status: 'active' });
|
|
234
247
|
const lastRuns = tasks.map((t) => t.lastRunAt || 0);
|
|
235
248
|
sendJson(res, 200, {
|
|
@@ -319,7 +332,9 @@ export function registerRoutes(ctx, { store, scheduler, recommendations }) {
|
|
|
319
332
|
* Handler for chain step retries (#319)
|
|
320
333
|
*/
|
|
321
334
|
export async function handleChainRoutes(store, scheduler, req, res) {
|
|
322
|
-
|
|
335
|
+
const settings = store && typeof store.getSettings === 'function' ? store.getSettings() : {};
|
|
336
|
+
const apiToken = settings.apiToken;
|
|
337
|
+
if (rejectCrossOrigin(req, res, { apiToken })) return;
|
|
323
338
|
const url = new URL(req.url, 'http://localhost');
|
|
324
339
|
|
|
325
340
|
// GET /dsh-cron/chains/:chainRunId (#334)
|
|
@@ -374,6 +389,10 @@ export async function handleRunArtifactRoutes(store, req, res) {
|
|
|
374
389
|
sendJson(res, 405, { ok: false, error: 'Method not allowed' });
|
|
375
390
|
return;
|
|
376
391
|
}
|
|
392
|
+
const settings = store && typeof store.getSettings === 'function' ? store.getSettings() : {};
|
|
393
|
+
const apiToken = settings.apiToken;
|
|
394
|
+
if (rejectCrossOrigin(req, res, { apiToken })) return;
|
|
395
|
+
|
|
377
396
|
const [, runId, artifactId, action] = m;
|
|
378
397
|
if (!artifactId) {
|
|
379
398
|
const artifacts = store.getArtifactsForRun(runId);
|
package/lib/validators.js
CHANGED
|
@@ -128,7 +128,8 @@ export function validateRunResult(task, runInfo, options = {}) {
|
|
|
128
128
|
// Guard against directory traversal escaping baseDir
|
|
129
129
|
const resolvedPath = path.resolve(baseDir, relPath);
|
|
130
130
|
const resolvedBase = path.resolve(baseDir);
|
|
131
|
-
|
|
131
|
+
const basePrefix = resolvedBase.endsWith(path.sep) ? resolvedBase : resolvedBase + path.sep;
|
|
132
|
+
if (resolvedPath !== resolvedBase && !resolvedPath.startsWith(basePrefix)) {
|
|
132
133
|
const message = `File path "${relPath}" escapes allowed directory boundary`;
|
|
133
134
|
details.push({ type: 'file', passed: false, message });
|
|
134
135
|
return { ok: false, status: 'failed', error: message, details };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-cron",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Background automation runner for DSH: isolated agent runs, script/HTTP/SSH/Docker runtimes, cost guard, notifications, heartbeats.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|