@runeditrun/rer 0.2.30 → 0.2.32
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/README.md +110 -0
- package/cli/README.md +49 -0
- package/cli/business/api.mjs +61 -0
- package/cli/business/command.mjs +51 -0
- package/cli/business/config-policy.mjs +25 -0
- package/cli/business/connect.mjs +50 -0
- package/cli/business/detector.mjs +42 -0
- package/cli/business/discovery-task.mjs +180 -0
- package/cli/business/files.mjs +25 -0
- package/cli/business/keychain.mjs +113 -0
- package/cli/business/lease.mjs +68 -0
- package/cli/business/local-commands.mjs +82 -0
- package/cli/business/outbound.mjs +29 -0
- package/cli/business/parsers-config.mjs +91 -0
- package/cli/business/parsers-infrastructure.mjs +68 -0
- package/cli/business/parsers-packages.mjs +84 -0
- package/cli/business/parsers-pulumi.mjs +64 -0
- package/cli/business/parsers-syntax.mjs +115 -0
- package/cli/business/parsers-terraform.mjs +53 -0
- package/cli/business/parsers.mjs +68 -0
- package/cli/business/permissions.mjs +143 -0
- package/cli/business/policy.mjs +52 -0
- package/cli/business/progress.mjs +18 -0
- package/cli/business/prompts.mjs +12 -0
- package/cli/business/questions.mjs +98 -0
- package/cli/business/repository.mjs +17 -0
- package/cli/business/scan-command.mjs +27 -0
- package/cli/business/scan.mjs +74 -0
- package/cli/business/service.mjs +152 -0
- package/cli/business/state.mjs +46 -0
- package/cli/business/supervisor.mjs +92 -0
- package/cli/business/vendors/README.md +101 -0
- package/cli/business/vendors/calendly.mjs +80 -0
- package/cli/business/vendors/common.mjs +103 -0
- package/cli/business/vendors/index.mjs +75 -0
- package/cli/business/vendors/pagerduty.mjs +70 -0
- package/cli/business/vendors/sentry.mjs +84 -0
- package/cli/business/vendors/uptimerobot.mjs +20 -0
- package/cli/contract.mjs +1 -1
- package/cli/deploy-command.mjs +3 -2
- package/cli/deploy-inputs.mjs +9 -0
- package/cli/deploy.mjs +3 -2
- package/cli/main.mjs +1 -0
- package/cli/release.mjs +5 -2
- package/global/CHANGELOG.md +30 -0
- package/global/README.md +110 -0
- package/global/cli/describe.mjs +20 -0
- package/global/cli/install.mjs +3 -3
- package/global/cli/repo-command.mjs +53 -0
- package/global/cli/repository-contract.mjs +7 -0
- package/global/cli/repository.mjs +84 -0
- package/global/launch/prepare.mjs +9 -6
- package/global/main.mjs +23 -0
- package/install.sh +7 -0
- package/modules/deploy-kit/owner-cli.mjs +5 -2
- package/modules/deploy-kit/owner.mjs +6 -4
- package/modules/deploy-kit/public-origin.mjs +17 -0
- package/modules/owner-claim/verify.d.mts +5 -0
- package/modules/release/README.md +11 -1
- package/modules/release/github-verify.mjs +30 -26
- package/modules/release/produce.mjs +2 -2
- package/modules/release/source-verification.mjs +2 -2
- package/modules/release/verify-workflow.mjs +23 -0
- package/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
const service = 'com.runeditrun.business';
|
|
4
|
+
const unavailable = () => new Error('OS credential storage is unavailable or locked. Unlock macOS Keychain or install and unlock Linux Secret Service (secret-tool); otherwise use the wizard or Managed. No credential was written to a file.');
|
|
5
|
+
|
|
6
|
+
// All process output stays in memory. In particular, never attach a child error:
|
|
7
|
+
// OS tools may put credential material in their diagnostics.
|
|
8
|
+
function execute(command, args, input, env) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const child = spawn(command, args, { env, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
11
|
+
const out = [], err = []; let size = 0, failed = false;
|
|
12
|
+
const timer = setTimeout(() => { failed = true; child.kill('SIGKILL'); }, 30000);
|
|
13
|
+
const collect = list => chunk => { size += chunk.length; if (size > 262144) { failed = true; child.kill('SIGKILL'); } else list.push(chunk); };
|
|
14
|
+
child.stdout.on('data', collect(out)); child.stderr.on('data', collect(err));
|
|
15
|
+
child.stdin.on('error', () => {});
|
|
16
|
+
child.on('error', () => { clearTimeout(timer); reject(unavailable()); });
|
|
17
|
+
child.on('close', code => {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
if (failed || code === null) reject(unavailable());
|
|
20
|
+
else resolve({ code, stdout: Buffer.concat(out).toString('utf8'), stderr: Buffer.concat(err).toString('utf8') });
|
|
21
|
+
});
|
|
22
|
+
child.stdin.end(input);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function checkedHandle(handle) {
|
|
27
|
+
if (typeof handle !== 'string' || !/^[a-zA-Z0-9][a-zA-Z0-9:._/-]{0,253}$/.test(handle)) throw new Error('Invalid credential handle.');
|
|
28
|
+
return handle;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function checkedSecret(secret) {
|
|
32
|
+
if (typeof secret !== 'string' || !secret.length || Buffer.byteLength(secret) > 65536 || /[\x00-\x1f\x7f]/.test(secret)) throw new Error('Enter a nonempty, single-line credential.');
|
|
33
|
+
return secret;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Secrets cross only stdin/stdout pipes, never arguments, files, or exceptions.
|
|
37
|
+
* run is a process-edge seam for tests, not a selectable storage backend.
|
|
38
|
+
*/
|
|
39
|
+
export function createCredentialStore({ platform = process.platform, env = process.env, run } = {}) {
|
|
40
|
+
const command = run ?? ((binary, args, input) => execute(binary, args, input, env));
|
|
41
|
+
if (!['darwin', 'linux'].includes(platform)) throw unavailable();
|
|
42
|
+
const call = async (...args) => { try { return await command(...args); } catch { throw unavailable(); } };
|
|
43
|
+
const macArgs = handle => ['-s', service, '-a', handle];
|
|
44
|
+
const linuxArgs = handle => ['application', service, 'handle', handle];
|
|
45
|
+
async function get(handle) {
|
|
46
|
+
checkedHandle(handle);
|
|
47
|
+
const result = platform === 'darwin'
|
|
48
|
+
? await call('/usr/bin/security', ['find-generic-password', ...macArgs(handle), '-w'])
|
|
49
|
+
: await call('secret-tool', ['lookup', ...linuxArgs(handle)]);
|
|
50
|
+
if (platform === 'darwin' && result.code === 44 || platform === 'linux' && result.code === 1 && !result.stderr.trim()) return null;
|
|
51
|
+
if (result.code !== 0) throw unavailable();
|
|
52
|
+
return result.stdout.replace(/\r?\n$/, '');
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
get,
|
|
56
|
+
async set(handle, secret) {
|
|
57
|
+
checkedHandle(handle); checkedSecret(secret);
|
|
58
|
+
if (platform === 'darwin') {
|
|
59
|
+
// Interactive security receives the hex password on stdin. Hex also avoids
|
|
60
|
+
// its command tokenizer interpreting quotes/backslashes in a vendor key.
|
|
61
|
+
const hex = Buffer.from(secret, 'utf8').toString('hex');
|
|
62
|
+
const result = await call('/usr/bin/security', ['-q', '-p', ''], `add-generic-password -U -s ${service} -a ${handle} -X ${hex}\n`);
|
|
63
|
+
if (result.code !== 0 || result.stderr.trim()) throw unavailable();
|
|
64
|
+
} else {
|
|
65
|
+
const result = await call('secret-tool', ['store', '--label=Run Edit Run Business', ...linuxArgs(handle)], secret);
|
|
66
|
+
if (result.code !== 0) throw unavailable();
|
|
67
|
+
}
|
|
68
|
+
// security's interactive exit status alone does not establish command success.
|
|
69
|
+
if (await get(handle) !== secret) throw unavailable();
|
|
70
|
+
return handle;
|
|
71
|
+
},
|
|
72
|
+
async delete(handle) {
|
|
73
|
+
checkedHandle(handle);
|
|
74
|
+
if (await get(handle) === null) return;
|
|
75
|
+
const result = platform === 'darwin'
|
|
76
|
+
? await call('/usr/bin/security', ['delete-generic-password', ...macArgs(handle)])
|
|
77
|
+
: await call('secret-tool', ['clear', ...linuxArgs(handle)]);
|
|
78
|
+
if (result.code !== 0 && !(platform === 'darwin' && result.code === 44)) throw unavailable();
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Credentials require a terminal that can hide input; keys are never echoed. */
|
|
84
|
+
export async function readSecret({ input = process.stdin, output = process.stderr } = {}) {
|
|
85
|
+
if (!input.isTTY || typeof input.setRawMode !== 'function') throw new Error('A terminal with hidden input is required.');
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
let secret = '', done = false; const wasRaw = input.isRaw, wasFlowing = input.readableFlowing === true;
|
|
88
|
+
function finish(error) {
|
|
89
|
+
if (done) return; done = true;
|
|
90
|
+
input.off('data', data); input.off('end', ended); input.off('error', ended);
|
|
91
|
+
process.off('SIGTERM', terminated); process.off('SIGINT', interrupted);
|
|
92
|
+
// A fresh stdin has readableFlowing === null, but isPaused() is false.
|
|
93
|
+
// Stop the read we started so the terminal does not keep the command alive.
|
|
94
|
+
input.setRawMode(Boolean(wasRaw)); if (!wasFlowing) input.pause(); output.write('\n');
|
|
95
|
+
if (error) reject(error); else { try { resolve(checkedSecret(secret)); } catch (e) { reject(e); } }
|
|
96
|
+
}
|
|
97
|
+
const interrupted = () => finish(new Error('Credential entry cancelled.'));
|
|
98
|
+
const terminated = () => finish(new Error('Credential entry interrupted.'));
|
|
99
|
+
const ended = () => finish(new Error('Credential input ended before confirmation.'));
|
|
100
|
+
function data(chunk) {
|
|
101
|
+
for (const character of chunk.toString('utf8')) {
|
|
102
|
+
if (character === '\x03' || character === '\x04') { interrupted(); return; }
|
|
103
|
+
if (character === '\r' || character === '\n') { finish(); return; }
|
|
104
|
+
if (character === '\x7f' || character === '\b') secret = Array.from(secret).slice(0, -1).join('');
|
|
105
|
+
else if (!/[\x00-\x1f]/.test(character)) secret += character;
|
|
106
|
+
if (Buffer.byteLength(secret) > 65536) { finish(new Error('Credential input is too long.')); return; }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
input.setRawMode(true); output.write('Credential (hidden): ');
|
|
110
|
+
input.on('data', data); input.once('end', ended); input.once('error', ended);
|
|
111
|
+
process.once('SIGTERM', terminated); process.once('SIGINT', interrupted); input.resume();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { ApiError, identifier, taskPath } from './api.mjs';
|
|
3
|
+
import { saveProgress } from './progress.mjs';
|
|
4
|
+
|
|
5
|
+
export class Lease {
|
|
6
|
+
constructor(api, claim, progress, outerSignal) {
|
|
7
|
+
identifier(claim.task.id); identifier(claim.grant?.id);
|
|
8
|
+
if (!Number.isSafeInteger(claim.fence) || claim.fence < 1 || claim.task.fence !== claim.fence
|
|
9
|
+
|| claim.grant.task_id !== claim.task.id || claim.grant.fence !== claim.fence || claim.heartbeat_interval_seconds !== 60) throw Error('Business server returned an invalid task grant.');
|
|
10
|
+
this.api = api; this.claim = claim; this.progress = progress;
|
|
11
|
+
this.checkpoint = claim.task.checkpoint ?? {}; this.cursor = 0;
|
|
12
|
+
this.controller = new AbortController(); this.signal = AbortSignal.any([outerSignal, this.controller.signal]);
|
|
13
|
+
this.tail = Promise.resolve(); this.expires = Date.parse(claim.lease_expires_at);
|
|
14
|
+
if (!Number.isFinite(this.expires) || this.expires <= Date.now()) throw new ApiError(409);
|
|
15
|
+
this.timer = setInterval(() => { void this.heartbeat().catch(error => this.controller.abort(error)); }, 60_000);
|
|
16
|
+
this.deadline = setInterval(() => { if (Date.now() >= this.expires) this.controller.abort(new ApiError(409)); }, 500);
|
|
17
|
+
}
|
|
18
|
+
serial(work) {
|
|
19
|
+
const operation = this.tail.then(work);
|
|
20
|
+
this.tail = operation.catch(() => {});
|
|
21
|
+
return operation;
|
|
22
|
+
}
|
|
23
|
+
async token() {
|
|
24
|
+
if (!this.bearer || Date.now() >= this.bearerUntil - 60_000) {
|
|
25
|
+
const minted = await this.api.mintToken('tasks', { taskId: this.claim.task.id, signal: this.signal });
|
|
26
|
+
this.bearer = minted.access_token; this.bearerUntil = Date.parse(minted.expires_at);
|
|
27
|
+
}
|
|
28
|
+
return this.bearer;
|
|
29
|
+
}
|
|
30
|
+
async post(destination, body, { releasing = false } = {}) {
|
|
31
|
+
if (!releasing) this.signal.throwIfAborted();
|
|
32
|
+
const token = releasing ? this.bearer : await this.token();
|
|
33
|
+
if (!token) throw Error('Business task bearer is unavailable.');
|
|
34
|
+
return this.api.post(destination, { ...body, client_event_id: body.client_event_id ?? randomUUID(), fence: this.claim.fence, grant_id: this.claim.grant.id },
|
|
35
|
+
{ token, ...(releasing ? { timeout: 5_000 } : { signal: this.signal }) });
|
|
36
|
+
}
|
|
37
|
+
send(destination, body) { return this.serial(() => this.post(destination, body)); }
|
|
38
|
+
heartbeat() {
|
|
39
|
+
return this.serial(async () => {
|
|
40
|
+
const result = await this.post(taskPath(this.claim.task.id, 'heartbeat'), { checkpoint: this.checkpoint, cursor: this.cursor });
|
|
41
|
+
const expires = Date.parse(result.lease_expires_at);
|
|
42
|
+
if (!Number.isFinite(expires) || expires <= Date.now()) throw new ApiError(409);
|
|
43
|
+
this.expires = expires;
|
|
44
|
+
this.cursor = Number.isSafeInteger(result.cursor) ? result.cursor : this.cursor;
|
|
45
|
+
if (result.cancel_requested || result.controls?.some(control => control.kind === 'cancel' || control.instruction === 'pause')) {
|
|
46
|
+
this.controller.abort(Error('Business task was paused or cancelled in the browser.'));
|
|
47
|
+
this.signal.throwIfAborted();
|
|
48
|
+
}
|
|
49
|
+
// Controls contain only closed enums. A requested checkpoint is already
|
|
50
|
+
// acknowledged by this heartbeat; no free-form instruction is executed.
|
|
51
|
+
return result;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async checkpointSaved(checkpoint) {
|
|
55
|
+
this.checkpoint = checkpoint;
|
|
56
|
+
this.progress.current = { kind: this.claim.task.kind, checkpoint, uploadedBytes: checkpoint.bytes_done ?? 0 };
|
|
57
|
+
await saveProgress(this.progress);
|
|
58
|
+
await this.heartbeat();
|
|
59
|
+
}
|
|
60
|
+
async complete() { clearInterval(this.timer); return this.serial(() => this.post(taskPath(this.claim.task.id, 'complete'), { outputs: {} })); }
|
|
61
|
+
async release(reason = 'handover') {
|
|
62
|
+
clearInterval(this.timer);
|
|
63
|
+
await this.tail;
|
|
64
|
+
if (!this.bearer) await this.token();
|
|
65
|
+
return this.post(taskPath(this.claim.task.id, 'release'), { reason, checkpoint: this.checkpoint }, { releasing: true });
|
|
66
|
+
}
|
|
67
|
+
async close() { clearInterval(this.timer); clearInterval(this.deadline); await this.tail; }
|
|
68
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { readFile, writeFile, unlink, rm, rmdir, lstat } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { loadState, saveState, stateDirectory, credentialHandle } from './state.mjs';
|
|
4
|
+
import { createCredentialStore, readSecret } from './keychain.mjs';
|
|
5
|
+
import { removeService, serviceStatus } from './service.mjs';
|
|
6
|
+
import { removePermissions } from './permissions.mjs';
|
|
7
|
+
import { pause } from './api.mjs';
|
|
8
|
+
import { loadProgress } from './progress.mjs';
|
|
9
|
+
import { VENDORS } from './vendors/index.mjs';
|
|
10
|
+
|
|
11
|
+
export async function paired() {
|
|
12
|
+
const state = await loadState();
|
|
13
|
+
if (!state?.origin || !state.businessId || !state.executorId) throw Error('This computer is not paired. Run rer business connect --code CODE.');
|
|
14
|
+
const credential = await createCredentialStore().get(credentialHandle(state.origin));
|
|
15
|
+
if (!credential) throw Error('Business device credential is missing. Reconnect in your browser.');
|
|
16
|
+
return { state, credential };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function vendorKey(action, vendor) {
|
|
20
|
+
if (!['add', 'remove'].includes(action) || !VENDORS.includes(vendor)) throw Error('Choose add or remove and a shipped vendor: sentry, uptimerobot, pagerduty, calendly.');
|
|
21
|
+
const { state } = await paired(), store = createCredentialStore(), handle = `vendor:${vendor}:read`;
|
|
22
|
+
if (action === 'add') {
|
|
23
|
+
let secret = await readSecret();
|
|
24
|
+
try { await store.set(handle, secret); } finally { secret = undefined; }
|
|
25
|
+
state.vendorHandles = [...new Set([...(state.vendorHandles ?? []), handle])];
|
|
26
|
+
} else {
|
|
27
|
+
await store.delete(handle);
|
|
28
|
+
state.vendorHandles = (state.vendorHandles ?? []).filter(item => item !== handle);
|
|
29
|
+
}
|
|
30
|
+
await saveState(state);
|
|
31
|
+
process.stdout.write(`${vendor}:read ${action === 'add' ? 'stored in OS keychain' : 'removed'}.\n`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function stopSupervisor(directory) {
|
|
35
|
+
const lock = join(directory, 'run.lock');
|
|
36
|
+
try { await lstat(lock); } catch (error) { if (error.code === 'ENOENT') return; throw error; }
|
|
37
|
+
await writeFile(join(directory, 'disconnect'), '', { mode: 0o600 });
|
|
38
|
+
for (let attempt = 0; attempt < 100; attempt++) {
|
|
39
|
+
try {
|
|
40
|
+
const pid = Number(await readFile(lock, 'utf8'));
|
|
41
|
+
if (Number.isSafeInteger(pid) && pid > 0) {
|
|
42
|
+
try { process.kill(pid, 0); }
|
|
43
|
+
catch (error) { if (error.code !== 'ESRCH') throw error; await unlink(lock); return; }
|
|
44
|
+
}
|
|
45
|
+
} catch (error) { if (error.code === 'ENOENT') return; throw error; }
|
|
46
|
+
await pause(100);
|
|
47
|
+
}
|
|
48
|
+
throw Error('Business supervisor is still stopping. Retry disconnect shortly.');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function disconnect() {
|
|
52
|
+
const state = await loadState(), directory = stateDirectory();
|
|
53
|
+
await removeService();
|
|
54
|
+
await stopSupervisor(directory);
|
|
55
|
+
await removePermissions();
|
|
56
|
+
if (state) {
|
|
57
|
+
const store = createCredentialStore();
|
|
58
|
+
for (const handle of state.vendorHandles ?? []) await store.delete(handle);
|
|
59
|
+
if (state.origin) await store.delete(credentialHandle(state.origin));
|
|
60
|
+
}
|
|
61
|
+
await rm(directory, { recursive: true, force: true });
|
|
62
|
+
// Remove only an empty parent; other rer commands may own it.
|
|
63
|
+
await rmdir(dirname(directory)).catch(error => { if (!['ENOENT', 'ENOTEMPTY', 'EEXIST'].includes(error.code)) throw error; });
|
|
64
|
+
process.stdout.write('Business disconnected. Local service, credentials and added permissions removed.\n');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function status({ json = false } = {}) {
|
|
68
|
+
const state = await loadState();
|
|
69
|
+
if (!state) {
|
|
70
|
+
process.stdout.write(json ? JSON.stringify({ paired: false, service: 'not_installed', current_task: null, checkpoint: null }) + '\n' : 'Business: not paired.\nService: not installed.\nTask: none.\nCheckpoint: none.\n'); return;
|
|
71
|
+
}
|
|
72
|
+
const stored = state.origin && await createCredentialStore().get(credentialHandle(state.origin));
|
|
73
|
+
const service = await serviceStatus();
|
|
74
|
+
const active = (await loadProgress()).current;
|
|
75
|
+
if (json) {
|
|
76
|
+
process.stdout.write(JSON.stringify({ paired: Boolean(stored), service: service.running ? 'running' : service.installed ? 'stopped' : 'not_installed', current_task: ['discover.local', 'export.vendor'].includes(active?.kind) ? active.kind : null, checkpoint: active?.checkpoint ? { saved: true, uploaded_bytes: Number.isSafeInteger(active.uploadedBytes) ? active.uploadedBytes : 0 } : null }) + '\n');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
process.stdout.write(`Business: ${stored ? 'paired' : 'credential missing'}.\nService: ${service.running ? 'running' : service.installed ? 'installed, stopped' : 'not installed'}.\n`);
|
|
80
|
+
process.stdout.write(`Task: ${['discover.local', 'export.vendor'].includes(active?.kind) ? active.kind : 'none'}.\n`);
|
|
81
|
+
process.stdout.write(`Checkpoint: ${active?.checkpoint ? 'saved' : 'none'}${Number.isSafeInteger(active?.uploadedBytes) ? `; ${active.uploadedBytes} bytes uploaded` : ''}.\n`);
|
|
82
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { sensitive, blockedSignal } from './detector.mjs';
|
|
2
|
+
|
|
3
|
+
export function assertOutbound(value, knownSecrets = []) {
|
|
4
|
+
function visit(item) {
|
|
5
|
+
if (typeof item === 'string') {
|
|
6
|
+
// Vendor records can contain ordinary line breaks. Inspect their text without
|
|
7
|
+
// changing the bytes that will be uploaded. All credential/entropy rules apply.
|
|
8
|
+
if (sensitive(item.replace(/[\r\n\t]/g, ' ')) || knownSecrets.some(secret => secret && item.includes(secret))) {
|
|
9
|
+
throw Error('Business outbound detector refused secret-shaped content.');
|
|
10
|
+
}
|
|
11
|
+
} else if (Array.isArray(item)) item.forEach(visit);
|
|
12
|
+
else if (item && typeof item === 'object') for (const [key, entry] of Object.entries(item)) { visit(key); visit(entry); }
|
|
13
|
+
}
|
|
14
|
+
visit(value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function assertChunk(bytes, knownSecrets) {
|
|
18
|
+
// Chunks may be fragments of a JSON document. The detector sees the complete
|
|
19
|
+
// UTF-8 text before any network write, including names and record values.
|
|
20
|
+
assertOutbound(Buffer.from(bytes).toString('utf8'), knownSecrets);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Names-only signals share the scanner's field-aware path policy. A locator
|
|
24
|
+
// joins ordinary directory names; credential shapes still apply across its
|
|
25
|
+
// entire spelling, and entropy is checked within each path segment.
|
|
26
|
+
export function assertSignals(document) {
|
|
27
|
+
assertOutbound({ schema: document.schema, source: document.source, withheld: document.withheld });
|
|
28
|
+
if (document.signals.some(blockedSignal)) throw Error('Business outbound detector refused secret-shaped content.');
|
|
29
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { flowEntries, keyParts, literal, splitOutside } from './parsers-syntax.mjs';
|
|
2
|
+
|
|
3
|
+
export function yamlEntries(source) {
|
|
4
|
+
const entries = [], stack = [];
|
|
5
|
+
let blockIndent, multilineQuote = '';
|
|
6
|
+
for (const line of source.split(/\r?\n/)) {
|
|
7
|
+
if (multilineQuote) { multilineQuote = remainingQuote(line, multilineQuote); continue; }
|
|
8
|
+
if (!line.trim() || /^\s*(?:---|\.\.\.)\s*$/.test(line)) continue;
|
|
9
|
+
const indent = /^ */.exec(line)[0].length;
|
|
10
|
+
if (blockIndent !== undefined) { if (indent > blockIndent) continue; blockIndent = undefined; }
|
|
11
|
+
while (stack.length && indent <= stack.at(-1).indent) stack.pop();
|
|
12
|
+
let raw = line.trim(), path = stack.at(-1)?.path ?? [], keyIndent = indent;
|
|
13
|
+
if (raw.startsWith('- ')) {
|
|
14
|
+
path = [...path, '[]']; raw = raw.slice(2).trim(); keyIndent += 2;
|
|
15
|
+
stack.push({ indent, path });
|
|
16
|
+
}
|
|
17
|
+
if (raw.startsWith('{') || raw.startsWith('[')) { flowEntries(raw, path, ':', entries); continue; }
|
|
18
|
+
const parts = splitOutside(raw, ':');
|
|
19
|
+
if (parts.length < 2 || !/^\s/.test(parts[1]) && parts[1] !== '') {
|
|
20
|
+
if (path.at(-1) === '[]') entries.push({ path, value: literal(raw) });
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const keys = keyParts(parts.shift()); if (!keys) continue;
|
|
24
|
+
const child = [...path, ...keys], value = parts.join(':').trim();
|
|
25
|
+
entries.push({ path: child, value: literal(value) });
|
|
26
|
+
if (/^["']/.test(value)) { multilineQuote = remainingQuote(value); if (multilineQuote) continue; }
|
|
27
|
+
if (/^[|>][+-]?[0-9]?$|^[|>][0-9][+-]?$/.test(value)) { blockIndent = keyIndent; continue; }
|
|
28
|
+
if (!value || /^(?:&[A-Za-z0-9_-]+|![^ ]+)\s*$/.test(value)) stack.push({ indent: keyIndent, path: child });
|
|
29
|
+
else flowEntries(value, child, ':', entries);
|
|
30
|
+
}
|
|
31
|
+
return entries;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function remainingQuote(source, initial = '') {
|
|
35
|
+
let quote = initial;
|
|
36
|
+
for (let i = 0; i < source.length; i++) {
|
|
37
|
+
const char = source[i];
|
|
38
|
+
if (quote) {
|
|
39
|
+
if (char === '\\' && quote === '"') i++;
|
|
40
|
+
else if (char === quote) {
|
|
41
|
+
if (quote === "'" && source[i + 1] === "'") i++;
|
|
42
|
+
else quote = '';
|
|
43
|
+
}
|
|
44
|
+
} else if (char === '"' || char === "'") quote = char;
|
|
45
|
+
}
|
|
46
|
+
return quote;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function statements(source) {
|
|
50
|
+
const result = []; let current = '', quote = '', depth = 0, triple = false;
|
|
51
|
+
for (let i = 0; i < source.length; i++) {
|
|
52
|
+
const char = source[i]; current += char;
|
|
53
|
+
if (quote) {
|
|
54
|
+
if (char === '\\' && quote === '"') { current += source[++i] ?? ''; }
|
|
55
|
+
else if (triple && source.slice(i, i + 3) === quote.repeat(3)) { current += source.slice(i + 1, i + 3); i += 2; quote = ''; triple = false; }
|
|
56
|
+
else if (!triple && char === quote) quote = '';
|
|
57
|
+
} else if (char === '"' || char === "'") {
|
|
58
|
+
quote = char;
|
|
59
|
+
if (source.slice(i, i + 3) === char.repeat(3)) { triple = true; current += source.slice(i + 1, i + 3); i += 2; }
|
|
60
|
+
} else if (char === '[' || char === '{') depth++;
|
|
61
|
+
else if (char === ']' || char === '}') depth--;
|
|
62
|
+
else if (char === '\n' && depth === 0) { result.push(current.trim()); current = ''; }
|
|
63
|
+
}
|
|
64
|
+
if (current.trim()) result.push(current.trim()); return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function tomlEntries(source) {
|
|
68
|
+
const entries = []; let table = [];
|
|
69
|
+
for (const statement of statements(source)) {
|
|
70
|
+
const header = /^(\[\[?)([\s\S]*?)(\]\]?)$/.exec(statement);
|
|
71
|
+
if (header && header[1].length === header[3].length) {
|
|
72
|
+
table = keyParts(header[2], true) ?? [];
|
|
73
|
+
if (table.length) {
|
|
74
|
+
entries.push({ path: table, value: undefined });
|
|
75
|
+
if (header[1] === '[[') table = [...table, '[]'];
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const parts = splitOutside(statement, '='); if (parts.length < 2) continue;
|
|
80
|
+
const keys = keyParts(parts.shift(), true); if (!keys) continue;
|
|
81
|
+
const path = [...table, ...keys], raw = parts.join('=').trim();
|
|
82
|
+
entries.push({ path, value: literal(raw) }); flowEntries(raw, path, '=', entries);
|
|
83
|
+
}
|
|
84
|
+
return entries;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function configNames(entries, add) {
|
|
88
|
+
for (const { path } of entries) {
|
|
89
|
+
if (path.at(-1) !== '[]') add('config-key', path.join('.'));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { identifier } from './parsers-syntax.mjs';
|
|
2
|
+
import { terraformNames } from './parsers-terraform.mjs';
|
|
3
|
+
|
|
4
|
+
function registryHost(image) {
|
|
5
|
+
if (typeof image !== 'string' || /[\s?#\\]|:\/\//.test(image)) return undefined;
|
|
6
|
+
const slash = image.indexOf('/'); if (slash < 1) return undefined;
|
|
7
|
+
const first = image.slice(0, slash); if (first.includes('@')) return undefined;
|
|
8
|
+
// Docker interprets a dotted first component, localhost or a host:port as
|
|
9
|
+
// an explicit registry. An unqualified image does not identify a registry.
|
|
10
|
+
if (!first.includes('.') && first !== 'localhost' && !first.includes(':')) return undefined;
|
|
11
|
+
const host = first.replace(/:[0-9]{1,5}$/, '');
|
|
12
|
+
if (first !== host && !/^\d{1,5}$/.test(first.slice(host.length + 1))) return undefined;
|
|
13
|
+
if (host === 'localhost' || (host.length <= 253 && host.split('.').every(label => /^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(label)))) return host.toLowerCase();
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function ciNames(source, entries, add) {
|
|
18
|
+
for (const match of source.matchAll(/\b(?:secrets|vars)\s*(?:\.\s*([A-Za-z_][A-Za-z0-9_]*)|\[\s*(["'])([A-Za-z_][A-Za-z0-9_]*)\2\s*\])/g)) add('ci-secret', match[1] ?? match[3]);
|
|
19
|
+
for (const { path, value } of entries) {
|
|
20
|
+
const parent = path.at(-2), key = path.at(-1);
|
|
21
|
+
if (['env', 'environment', 'variables', 'secrets'].includes(parent) && identifier.test(key)) add('ci-secret', key);
|
|
22
|
+
if (parent === '[]' && ['env', 'variables'].includes(path.at(-3))) {
|
|
23
|
+
if (key === 'name' && typeof value === 'string' && identifier.test(value)) add('ci-secret', value);
|
|
24
|
+
}
|
|
25
|
+
if (key === '[]' && path.some(part => ['env', 'environment', 'variables'].includes(part)) && typeof value === 'string') {
|
|
26
|
+
const match = /^([A-Za-z_][A-Za-z0-9_]*)=/.exec(value); if (match) add('ci-secret', match[1]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function infrastructureDocument(pathname, entries) {
|
|
32
|
+
return /\.(?:tf|hcl|tf\.json)$/i.test(pathname)
|
|
33
|
+
|| /(?:^|\/)(?:charts?|helm)\//i.test(pathname)
|
|
34
|
+
|| /(?:^|\/)Pulumi[^/]*\.(?:ya?ml|json)$/i.test(pathname)
|
|
35
|
+
|| entries.some(({ path }) => path.length === 1 && path[0] === 'Resources')
|
|
36
|
+
|| entries.some(({ path }) => path.at(-1) === 'apiVersion') && entries.some(({ path }) => path.at(-1) === 'kind');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function infrastructureNames(pathname, source, entries, ci, add) {
|
|
40
|
+
if (ci) ciNames(source, entries, add);
|
|
41
|
+
if (/\.(?:tf|hcl)$/i.test(pathname)) terraformNames(source, add);
|
|
42
|
+
const kubernetes = new Set(entries.filter(entry => entry.path.at(-1) === 'apiVersion').map(entry => entry.path.slice(0, -1).join('\0')));
|
|
43
|
+
const images = ci || infrastructureDocument(pathname, entries);
|
|
44
|
+
for (const { path, value } of entries) {
|
|
45
|
+
if (/\.tf\.json$/i.test(pathname)) {
|
|
46
|
+
if (path[0] === 'provider' && path.length === 2) add('iac-provider', path[1]);
|
|
47
|
+
if (['resource', 'data'].includes(path[0]) && path.length === 2) add('iac-resource', path[1]);
|
|
48
|
+
if (path.includes('required_providers') && path.at(-1) === 'source' && typeof value === 'string'
|
|
49
|
+
&& /^[A-Za-z0-9][A-Za-z0-9_.-]*(?:\/[A-Za-z0-9][A-Za-z0-9_.-]*){1,2}$/.test(value)) add('iac-provider', value);
|
|
50
|
+
}
|
|
51
|
+
if (typeof value !== 'string') continue;
|
|
52
|
+
const key = path.at(-1);
|
|
53
|
+
if (key === 'kind' && kubernetes.has(path.slice(0, -1).join('\0')) && /^[A-Za-z][A-Za-z0-9]*$/.test(value)) add('iac-resource', value);
|
|
54
|
+
if (/^(?:Type|type)$/.test(key)) {
|
|
55
|
+
if (path[0] === 'Resources' && path.length === 3 && /^[A-Za-z][A-Za-z0-9]*::[A-Za-z][A-Za-z0-9]*::[A-Za-z][A-Za-z0-9]*$/.test(value)) add('iac-resource', value);
|
|
56
|
+
if (path[0] === 'resources' && path.length === 3 && /(?:^|\/)Pulumi[^/]*\.(?:ya?ml|json)$/i.test(pathname) && /^[A-Za-z][A-Za-z0-9_-]*:[A-Za-z0-9_./-]*:[A-Za-z][A-Za-z0-9_]*$/.test(value)) {
|
|
57
|
+
const provider = /^pulumi:providers:([A-Za-z][A-Za-z0-9_-]*)$/.exec(value);
|
|
58
|
+
add(provider ? 'iac-provider' : 'iac-resource', provider?.[1] ?? value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (images && (key === 'image' || (key === 'repository' && path.includes('image')))) {
|
|
62
|
+
const host = registryHost(value); if (host) add('iac-provider', host);
|
|
63
|
+
}
|
|
64
|
+
if (images && key === 'registry' && path.includes('image')) {
|
|
65
|
+
const host = registryHost(`${value}/_`); if (host) add('iac-provider', host);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { identifier, literal, packageName, splitOutside } from './parsers-syntax.mjs';
|
|
2
|
+
|
|
3
|
+
function requirement(value) {
|
|
4
|
+
// In a direct reference, only the package before @ is a name. Bare URLs,
|
|
5
|
+
// editable paths, index options and includes are deliberately not followed.
|
|
6
|
+
const match = /^([A-Za-z0-9][A-Za-z0-9._-]*)(?=\s*(?:\[|[<>=!~;@]|\(|$))/.exec(value.trim());
|
|
7
|
+
return match?.[1];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function jsonDependencies(source, sections, add) {
|
|
11
|
+
let manifest;
|
|
12
|
+
try { manifest = JSON.parse(source); } catch { return; }
|
|
13
|
+
if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) return;
|
|
14
|
+
for (const section of sections) {
|
|
15
|
+
const dependencies = manifest[section];
|
|
16
|
+
if (!dependencies || typeof dependencies !== 'object' || Array.isArray(dependencies)) continue;
|
|
17
|
+
for (const name of Object.keys(dependencies)) if (packageName.test(name)) add('package', name);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function cargoDependencies(source, add) {
|
|
22
|
+
let dependencyTable = false;
|
|
23
|
+
for (const line of source.split(/\r?\n/)) {
|
|
24
|
+
const header = /^\s*\[([^\]]+)\]\s*$/.exec(line);
|
|
25
|
+
if (header) {
|
|
26
|
+
const table = header[1].trim();
|
|
27
|
+
dependencyTable = /(?:^|\.)(?:dependencies|dev-dependencies|build-dependencies)$/.test(table);
|
|
28
|
+
const detail = /(?:^|\.)(?:dependencies|dev-dependencies|build-dependencies)\.([A-Za-z0-9_-]+)$/.exec(table);
|
|
29
|
+
if (detail) add('package', detail[1]);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (!dependencyTable) continue;
|
|
33
|
+
const parts = splitOutside(line, '='); if (parts.length < 2) continue;
|
|
34
|
+
const name = literal(parts.shift()); if (!name || !packageName.test(name)) continue;
|
|
35
|
+
// Cargo renames name a different package explicitly inside an inline table.
|
|
36
|
+
const renamed = /(?:^|[,\s{])package\s*=\s*(["'])([A-Za-z0-9_-]+)\1/.exec(parts.join('='));
|
|
37
|
+
add('package', renamed?.[2] ?? name);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function goDependencies(source, add) {
|
|
42
|
+
let group = false;
|
|
43
|
+
const name = '[A-Za-z0-9][A-Za-z0-9._~-]*(?:/[A-Za-z0-9][A-Za-z0-9._~-]*)+';
|
|
44
|
+
for (const line of source.split(/\r?\n/)) {
|
|
45
|
+
if (/^\s*require\s*\(\s*$/.test(line)) { group = true; continue; }
|
|
46
|
+
if (group && /^\s*\)\s*$/.test(line)) { group = false; continue; }
|
|
47
|
+
const match = new RegExp(group ? `^\\s*(${name})\\s+v[^\\s]+\\s*$` : `^\\s*require\\s+(${name})\\s+v[^\\s]+\\s*$`).exec(line);
|
|
48
|
+
if (match) add('package', match[1]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function packageNames(filename, source, entries, add) {
|
|
53
|
+
if (filename === 'package.json') {
|
|
54
|
+
jsonDependencies(source, ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'], add);
|
|
55
|
+
} else if (filename === 'composer.json') {
|
|
56
|
+
jsonDependencies(source, ['require', 'require-dev'], add);
|
|
57
|
+
} else if (/^requirements[^/]*\.txt$/.test(filename)) {
|
|
58
|
+
for (const line of source.split(/\r?\n/)) { const name = requirement(line); if (name) add('package', name); }
|
|
59
|
+
} else if (filename === 'pyproject.toml') {
|
|
60
|
+
for (const { path, value } of entries) {
|
|
61
|
+
if (typeof value === 'string' && ((path[0] === 'project' && path[1] === 'dependencies' && path[2] === '[]')
|
|
62
|
+
|| (path[0] === 'project' && path[1] === 'optional-dependencies' && path[3] === '[]'))) {
|
|
63
|
+
const name = requirement(value); if (name) add('package', name);
|
|
64
|
+
}
|
|
65
|
+
const poetry = path[0] === 'tool' && path[1] === 'poetry';
|
|
66
|
+
const dependencyIndex = poetry && (path[2] === 'dependencies' || path[2] === 'dev-dependencies') ? 3
|
|
67
|
+
: poetry && path[2] === 'group' && path[4] === 'dependencies' ? 5 : -1;
|
|
68
|
+
if (dependencyIndex !== -1 && path.length === dependencyIndex + 1 && path[dependencyIndex] !== 'python' && packageName.test(path[dependencyIndex])) add('package', path[dependencyIndex]);
|
|
69
|
+
}
|
|
70
|
+
} else if (filename === 'gemfile') {
|
|
71
|
+
for (const line of source.split(/\r?\n/)) {
|
|
72
|
+
const match = /^\s*gem\s*(?:\(\s*)?(["'])([A-Za-z0-9][A-Za-z0-9_.-]*)\1(?=\s*[,)]|\s*$)/.exec(line);
|
|
73
|
+
if (match) add('package', match[2]);
|
|
74
|
+
}
|
|
75
|
+
} else if (filename === 'go.mod') goDependencies(source, add);
|
|
76
|
+
else if (filename === 'cargo.toml') cargoDependencies(source, add);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function environmentNames(source, add) {
|
|
80
|
+
for (const line of source.split(/\r?\n/)) {
|
|
81
|
+
const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(line);
|
|
82
|
+
if (match && identifier.test(match[1])) add('env-key', match[1]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Source support is deliberately limited to literal provider imports and calls
|
|
2
|
+
// through those imports. Nothing is imported, instantiated or executed.
|
|
3
|
+
export function pulumiNames(pathname, source, add) {
|
|
4
|
+
const aliases = new Map(), executable = maskStrings(source), maskedLines = executable.split(/\r?\n/), lines = source.split(/\r?\n/);
|
|
5
|
+
const register = (alias, provider) => {
|
|
6
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(alias) || !/^[a-z][a-z0-9_-]*$/.test(provider)) return;
|
|
7
|
+
if (provider === 'pulumi') return;
|
|
8
|
+
aliases.set(alias, provider); add('iac-provider', provider);
|
|
9
|
+
};
|
|
10
|
+
if (/\.[cm]?[jt]sx?$/i.test(pathname)) {
|
|
11
|
+
for (let index = 0; index < lines.length; index++) {
|
|
12
|
+
const line = lines[index]; if (!/^\s*(?:import|const|let|var)\b/.test(maskedLines[index])) continue;
|
|
13
|
+
const imported = /^\s*import\s+(?:\*\s+as\s+)?([A-Za-z_][A-Za-z0-9_]*)\s+from\s+(["'])@pulumi\/([a-z][a-z0-9_-]*)\2(?=\s*(?:;|$))/.exec(line);
|
|
14
|
+
if (imported) register(imported[1], imported[3]);
|
|
15
|
+
const required = /^\s*(?:const|let|var)\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*require\(\s*(["'])@pulumi\/([a-z][a-z0-9_-]*)\2\s*\)(?=\s*(?:;|$))/.exec(line);
|
|
16
|
+
if (required) register(required[1], required[3]);
|
|
17
|
+
}
|
|
18
|
+
} else if (/\.py$/i.test(pathname)) {
|
|
19
|
+
for (let index = 0; index < lines.length; index++) {
|
|
20
|
+
const line = lines[index]; if (!/^\s*(?:import|from)\b/.test(maskedLines[index])) continue;
|
|
21
|
+
const imported = /^\s*import\s+pulumi_([a-z][a-z0-9_]*)(?:\s+as\s+([A-Za-z_][A-Za-z0-9_]*))?\s*$/.exec(line);
|
|
22
|
+
if (imported) register(imported[2] ?? `pulumi_${imported[1]}`, imported[1]);
|
|
23
|
+
const from = /^\s*from\s+pulumi_([a-z][a-z0-9_]*)\s+import\s+([a-z][a-z0-9_]*)(?:\s+as\s+([A-Za-z_][A-Za-z0-9_]*))?\s*$/.exec(line);
|
|
24
|
+
if (from) register(from[3] ?? from[2], from[1]);
|
|
25
|
+
}
|
|
26
|
+
} else if (/\.go$/i.test(pathname)) {
|
|
27
|
+
let imports = false;
|
|
28
|
+
for (const line of source.split(/\r?\n/)) {
|
|
29
|
+
if (/^\s*import\s*\(\s*$/.test(line)) { imports = true; continue; }
|
|
30
|
+
if (/^\s*\)\s*$/.test(line)) imports = false;
|
|
31
|
+
const imported = new RegExp(`^\\s*${imports ? '' : 'import\\s+'}(?:([A-Za-z_][A-Za-z0-9_]*)\\s+)?"github\\.com/pulumi/pulumi-([a-z][a-z0-9_-]*)/sdk/(?:v[0-9]+/)?go/([A-Za-z0-9_/]+)"\\s*$`).exec(line);
|
|
32
|
+
if (imported) register(imported[1] ?? imported[3].split('/').at(-1), imported[2]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Mask all strings and heredocs before looking for constructor expressions.
|
|
36
|
+
// Otherwise a code example embedded in a description could become live use.
|
|
37
|
+
for (const match of executable.matchAll(/\b(?:new\s+)?([A-Za-z_][A-Za-z0-9_]*)((?:\.[A-Za-z_][A-Za-z0-9_]*)+)\s*\(/g)) {
|
|
38
|
+
if (!aliases.has(match[1])) continue;
|
|
39
|
+
const type = match[2].slice(1).split('.').at(-1);
|
|
40
|
+
if (/^[A-Z]/.test(type) && type !== 'Provider') add('iac-resource', `${match[1]}${match[2]}`);
|
|
41
|
+
}
|
|
42
|
+
if (/\.cs$/i.test(pathname)) {
|
|
43
|
+
for (const match of executable.matchAll(/\bnew\s+(Pulumi\.([A-Za-z][A-Za-z0-9_]*)(?:\.[A-Za-z][A-Za-z0-9_]*)+)\s*\(/g)) {
|
|
44
|
+
add('iac-provider', match[2]); if (!match[1].endsWith('.Provider')) add('iac-resource', match[1]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function maskStrings(source) {
|
|
50
|
+
let result = '', quote = '', triple = false;
|
|
51
|
+
for (let i = 0; i < source.length; i++) {
|
|
52
|
+
const char = source[i];
|
|
53
|
+
if (quote) {
|
|
54
|
+
result += char === '\n' ? '\n' : ' ';
|
|
55
|
+
if (char === '\\' && quote !== '`') { const next = source[++i]; result += next === '\n' ? '\n' : ' '; }
|
|
56
|
+
else if (triple && source.slice(i, i + 3) === quote.repeat(3)) { result += ' '; i += 2; quote = ''; triple = false; }
|
|
57
|
+
else if (!triple && char === quote) quote = '';
|
|
58
|
+
} else if (['"', "'", '`'].includes(char)) {
|
|
59
|
+
quote = char; result += ' ';
|
|
60
|
+
if (source.slice(i, i + 3) === char.repeat(3)) { triple = true; result += ' '; i += 2; }
|
|
61
|
+
} else result += char;
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|