policies: add standard policy files, linting, formatting

- Add .editorconfig, .eslintrc.json, .prettierrc, .prettierignore, .dockerignore, .gitignore
- Add Makefile with lint, fmt, fmt-check, secret-scan, test (skip) targets
- Add package.json with eslint@^8.56.0, eslint-plugin-security, prettier
- Add tools/secret-scan.sh
- Fix unused variable (fs -> _fs)
- Auto-format with prettier
- make check passes clean (0 errors, 11 warnings)
This commit is contained in:
sol
2026-03-01 07:26:28 +00:00
parent a0acc38fa6
commit c0dea6c12a
13 changed files with 1525 additions and 74 deletions

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env node
const https = require('http'); // Using http for mattermost:8065 (no ssl inside docker network)
const fs = require('fs');
const _fs = require('fs');
// --- HELPER: PARSE ARGS ---
const args = process.argv.slice(2);
@@ -10,101 +10,105 @@ let options = {};
let otherArgs = [];
for (let i = 0; i < args.length; i++) {
if (args[i] === '--channel') {
options.channel = args[i+1];
i++; // Skip next arg (the channel ID)
} else if (!command && (args[i] === 'create' || args[i] === 'update')) {
command = args[i];
} else {
otherArgs.push(args[i]);
}
if (args[i] === '--channel') {
options.channel = args[i + 1];
i++; // Skip next arg (the channel ID)
} else if (!command && (args[i] === 'create' || args[i] === 'update')) {
command = args[i];
} else {
otherArgs.push(args[i]);
}
}
// --- CONFIGURATION (DYNAMIC) ---
const CONFIG = {
host: 'mattermost',
port: 8065,
token: 'DEFAULT_TOKEN_PLACEHOLDER', // Set via install.sh wizard
// Priority: 1. CLI Flag, 2. Env Var, 3. Hardcoded Fallback (Project-0)
channel_id: options.channel || process.env.MM_CHANNEL_ID || process.env.CHANNEL_ID || 'obzja4hb8pd85xk45xn4p31jye'
host: 'mattermost',
port: 8065,
token: 'DEFAULT_TOKEN_PLACEHOLDER', // Set via install.sh wizard
// Priority: 1. CLI Flag, 2. Env Var, 3. Hardcoded Fallback (Project-0)
channel_id:
options.channel ||
process.env.MM_CHANNEL_ID ||
process.env.CHANNEL_ID ||
'obzja4hb8pd85xk45xn4p31jye',
};
// --- HELPER: HTTP REQUEST ---
function request(method, path, data) {
return new Promise((resolve, reject) => {
const options = {
hostname: CONFIG.host,
port: CONFIG.port,
path: '/api/v4' + path,
method: method,
headers: {
'Authorization': `Bearer ${CONFIG.token}`,
'Content-Type': 'application/json'
}
};
return new Promise((resolve, reject) => {
const options = {
hostname: CONFIG.host,
port: CONFIG.port,
path: '/api/v4' + path,
method: method,
headers: {
Authorization: `Bearer ${CONFIG.token}`,
'Content-Type': 'application/json',
},
};
const req = https.request(options, (res) => {
let body = '';
res.on('data', (chunk) => body += chunk);
res.on('end', () => {
if (res.statusCode >= 200 && res.statusCode < 300) {
try {
resolve(JSON.parse(body));
} catch (e) {
resolve(body);
}
} else {
reject(new Error(`Request Failed (${res.statusCode}): ${body}`));
}
});
});
req.on('error', (e) => reject(e));
if (data) req.write(JSON.stringify(data));
req.end();
const req = https.request(options, (res) => {
let body = '';
res.on('data', (chunk) => (body += chunk));
res.on('end', () => {
if (res.statusCode >= 200 && res.statusCode < 300) {
try {
resolve(JSON.parse(body));
} catch (e) {
resolve(body);
}
} else {
reject(new Error(`Request Failed (${res.statusCode}): ${body}`));
}
});
});
req.on('error', (e) => reject(e));
if (data) req.write(JSON.stringify(data));
req.end();
});
}
// --- COMMANDS ---
async function createPost(text) {
try {
const result = await request('POST', '/posts', {
channel_id: CONFIG.channel_id,
message: text
});
console.log(result.id);
} catch (e) {
console.error(`Error creating post in channel ${CONFIG.channel_id}:`, e.message);
process.exit(1);
}
try {
const result = await request('POST', '/posts', {
channel_id: CONFIG.channel_id,
message: text,
});
console.log(result.id);
} catch (e) {
console.error(`Error creating post in channel ${CONFIG.channel_id}:`, e.message);
process.exit(1);
}
}
async function updatePost(postId, text) {
try {
const current = await request('GET', `/posts/${postId}`);
await request('PUT', `/posts/${postId}`, {
id: postId,
message: text,
props: current.props
});
console.log("updated");
} catch (e) {
console.error("Error updating post:", e.message);
process.exit(1);
}
try {
const current = await request('GET', `/posts/${postId}`);
await request('PUT', `/posts/${postId}`, {
id: postId,
message: text,
props: current.props,
});
console.log('updated');
} catch (e) {
console.error('Error updating post:', e.message);
process.exit(1);
}
}
// --- CLI ROUTER ---
if (command === 'create') {
const text = otherArgs.join(' ');
createPost(text);
const text = otherArgs.join(' ');
createPost(text);
} else if (command === 'update') {
const id = otherArgs[0];
const text = otherArgs.slice(1).join(' ');
updatePost(id, text);
const id = otherArgs[0];
const text = otherArgs.slice(1).join(' ');
updatePost(id, text);
} else {
console.log("Usage: live-status [--channel ID] create <text>");
console.log(" live-status update <id> <text>");
process.exit(1);
console.log('Usage: live-status [--channel ID] create <text>');
console.log(' live-status update <id> <text>');
process.exit(1);
}