forked from mtusi2026/mtusi2026lab7
Prepare verified laboratory 7 implementation and evidence
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import {
|
||||
mkdtemp,
|
||||
readdir,
|
||||
copyFile,
|
||||
mkdir,
|
||||
rm,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { root, local, run, safeFailure } from "./runtime";
|
||||
// Public check recursively treats every *.json path as a JSON file. RustFS legitimately stores
|
||||
// policy.json as an object directory. Run the unchanged checker against source bytes, not a live data store.
|
||||
export async function checkSource(
|
||||
scope: "security" | "openobserve" | "grafana" = "security",
|
||||
) {
|
||||
await mkdir(local, { recursive: true, mode: 0o700 });
|
||||
const scratch = await mkdtemp(resolve(local, "source-check-"));
|
||||
async function copy(source: string, destination: string) {
|
||||
await mkdir(destination, { recursive: true });
|
||||
for (const entry of await readdir(source, { withFileTypes: true })) {
|
||||
if (
|
||||
[
|
||||
".git",
|
||||
"node_modules",
|
||||
".venv",
|
||||
".env",
|
||||
"dist",
|
||||
"build",
|
||||
"target",
|
||||
"bin",
|
||||
"obj",
|
||||
].includes(entry.name) ||
|
||||
entry.name.startsWith(".local") ||
|
||||
entry.name.endsWith(".zip")
|
||||
)
|
||||
continue;
|
||||
const from = resolve(source, entry.name),
|
||||
to = resolve(destination, entry.name);
|
||||
if (entry.isDirectory()) await copy(from, to);
|
||||
else if (entry.isFile()) await copyFile(from, to);
|
||||
}
|
||||
}
|
||||
try {
|
||||
await copy(root, scratch);
|
||||
const result = await run(["make", "check"], { cwd: scratch });
|
||||
await writeFile(
|
||||
resolve(root, `evidence/${scope}/public-source-check.txt`),
|
||||
result.out + result.err,
|
||||
);
|
||||
console.log("PASS_UNCHANGED_PUBLIC_CHECK_IN_SOURCE_ONLY_SNAPSHOT");
|
||||
return result;
|
||||
} finally {
|
||||
await rm(scratch, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
if (import.meta.main) {
|
||||
try {
|
||||
await checkSource(
|
||||
Bun.argv.includes("--grafana")
|
||||
? "grafana"
|
||||
: Bun.argv.includes("--openobserve")
|
||||
? "openobserve"
|
||||
: "security",
|
||||
);
|
||||
} catch (error) {
|
||||
safeFailure(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user