Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
Signed-off-by: Lance <lance.byrd@rootsid.com>
  • Loading branch information
2byrds committed Feb 11, 2025
1 parent b223f65 commit 5648b8b
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 186 deletions.
89 changes: 45 additions & 44 deletions signify-ts-test/src/utils/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ export async function generate_reports(
keeper: signify.Keeper,
unsignedReports: string[],
reportTypes: string[],
copyFolder?: string
copyFolder?: string,
) {
let zipsProcessed = 0;
const signedReports = [] as string[];
console.log(
`Generating ${reportTypes} signed reports from orig reports: ${unsignedReports}`
`Generating ${reportTypes} signed reports from orig reports: ${unsignedReports}`,
);

for (const unsignedReport of unsignedReports) {
Expand All @@ -118,7 +118,7 @@ export async function generate_reports(
reportTypes,
keeper,
ecrAid,
signedDirPrefixed
signedDirPrefixed,
);

assert.equal(signedReports.length > 0, true);
Expand All @@ -128,21 +128,21 @@ export async function generate_reports(
fs.mkdirSync(tempDir, { recursive: true });
assert.equal(
await createFailReports(failDirPrefixed, signedDirPrefixed),
true
true,
);
}

if (copyFolder) {
fs.cpSync(
signedDirPrefixed,
path.join(dataDir, copyFolder, "signed_reports", ecrAid),
{ recursive: true }
{ recursive: true },
);
if (reportTypes.includes(FAIL_TYPE)) {
fs.cpSync(
failDirPrefixed,
path.join(dataDir, copyFolder, "fail_reports", ecrAid),
{ recursive: true }
{ recursive: true },
);
}
}
Expand All @@ -164,7 +164,7 @@ export async function createSignedReports(
reportTypes: string[] = [SIMPLE_TYPE],
keeper: signify.Keeper,
ecrAid: string,
signedDirPrefixed: string
signedDirPrefixed: string,
): Promise<string[]> {
const fileName = path.basename(filePath, path.extname(filePath));
const signedReports = [] as string[];
Expand All @@ -184,14 +184,14 @@ export async function createSignedReports(
const foundPath = findReportsDir(testPaths.tmpReportsDir);
if (!foundPath) {
throw new Error(
`No reports directory found in ${testPaths.tmpReportsDir}`
`No reports directory found in ${testPaths.tmpReportsDir}`,
);
}
const complexManifest = await buildManifest(
foundPath,
false,
keeper,
ecrAid
ecrAid,
);
const complexManJson = JSON.stringify(complexManifest, null, 2);
if (reportTypes.includes(EXTERNAL_MAN_TYPE)) {
Expand All @@ -202,34 +202,34 @@ export async function createSignedReports(
const signedRepPath = path.join(signedDirPrefixed, shortFileName);
console.log(
`Creating ${EXTERNAL_MAN_TYPE} packaged signed report ` +
signedRepPath
signedRepPath,
);
await createExternalManifestZip(
signedRepPath,
filePath,
complexManJson
complexManJson,
);
signedReports.push(signedRepPath);
}
if (reportTypes.includes(UNZIPPED_TYPE)) {
const manPath = await writeReportsJson(
testPaths.tmpReportsDir,
complexManJson
complexManJson,
);
if (reportTypes.includes(UNFOLDERED_TYPE)) {
//generate unfoldered zip, like older xbrl spec
const unfolderedShortFileName = `${UNFOLDERED_TYPE}_${UNZIPPED_TYPE}_${fileName}_signed${fileExtension}`;
const unfolderedRepPath = path.join(
signedDirPrefixed,
unfolderedShortFileName
unfolderedShortFileName,
);
console.log(
"Creating unfoldered+unzipped signed report " + unfolderedRepPath
"Creating unfoldered+unzipped signed report " + unfolderedRepPath,
);
const sufZip = await transferTempToZip(
testPaths.tmpReportsDir,
unfolderedRepPath,
false
false,
);
validateReport(new AdmZip(sufZip));
signedReports.push(unfolderedRepPath);
Expand All @@ -249,7 +249,7 @@ export async function createSignedReports(
// just copy the zip file here for a single digest/signature
fsExtra.copySync(
filePath,
path.join(testPaths.tmpReportsDir, path.basename(filePath))
path.join(testPaths.tmpReportsDir, path.basename(filePath)),
);
console.log(`Copied ${filePath} to ${testPaths.tmpReportsDir}`);
// }
Expand All @@ -258,14 +258,14 @@ export async function createSignedReports(
testPaths.tmpReportsDir,
true,
keeper,
ecrAid
ecrAid,
);
const simpleManJson = JSON.stringify(simpleManifest, null, 2);

const manifestPath = path.join(
testPaths.tmpReportsDir,
"META-INF",
"reports.json"
"reports.json",
);
console.log(`Writing manifest with digests/signatures ${manifestPath}`);

Expand All @@ -280,7 +280,7 @@ export async function createSignedReports(
console.log(`Creating simple packaged signed report ${signedRepPath}`);
const sfZip = await transferTempToZip(
testPaths.tmpReportsDir,
signedRepPath
signedRepPath,
);
validateReport(new AdmZip(sfZip));
signedReports.push(signedRepPath);
Expand All @@ -293,14 +293,14 @@ export async function getEbaSignedReport(
filePath: string,
signedDirPath: string,
aid: string,
keeper: signify.Keeper
keeper: signify.Keeper,
): Promise<string> {
const signedZips = await createSignedReports(
filePath,
[SIMPLE_TYPE],
keeper,
aid,
path.join(signedDirPath, aid)
path.join(signedDirPath, aid),
);
return signedZips[0];
}
Expand All @@ -309,7 +309,7 @@ async function buildManifest(
repDirPath: string,
simple: boolean,
keeper: signify.Keeper,
ecrAid: string
ecrAid: string,
): Promise<Manifest> {
const reportEntries = await fs.promises.readdir(repDirPath, {
withFileTypes: true,
Expand Down Expand Up @@ -344,7 +344,7 @@ async function buildManifest(

async function createFailReports(
failDirPrefixed: string,
signedDirPrefixed: string
signedDirPrefixed: string,
): Promise<boolean> {
const failFuncs: Array<(manifestPath: string) => Promise<boolean>> = [
genMissingSignature,
Expand Down Expand Up @@ -504,13 +504,14 @@ async function listReportZips(dir: string): Promise<string[]> {
const zipEntries = zip.getEntries();
if (
zipEntries.some(
(entry) => entry.isDirectory && entry.entryName.endsWith("reports/")
(entry) =>
entry.isDirectory && entry.entryName.endsWith("reports/"),
)
) {
if (reportZips.length > 0) {
throw new Error(
"Multiple report zips found in but we dont handle that case currnetly " +
dir
dir,
);
}
reportZips.push(zipFile);
Expand All @@ -522,7 +523,7 @@ async function listReportZips(dir: string): Promise<string[]> {
}

async function removeMetaInfReportsJson(
manifestPath: string
manifestPath: string,
): Promise<boolean> {
if (fs.existsSync(manifestPath)) {
console.log(`Removing ${manifestPath}`);
Expand All @@ -536,7 +537,7 @@ async function removeMetaInfReportsJson(
async function addSignatureToReport(
signatureBlock: Signature,
keeper: signify.Keeper,
ecrAid: string
ecrAid: string,
): Promise<boolean> {
const sigs = [] as string[];
for (const signer of keeper.signers as Signer[]) {
Expand All @@ -550,7 +551,7 @@ async function addSignatureToReport(
}
assert(
sigs.length > 0,
`No signatures added to signature block ${signatureBlock}`
`No signatures added to signature block ${signatureBlock}`,
);
signatureBlock.sigs = sigs;
signatureBlock.aid = ecrAid;
Expand All @@ -561,7 +562,7 @@ async function addSignatureToReport(
async function addDigestToReport(
reportPath: string,
signatureBlock: Signature,
simple = false
simple = false,
): Promise<boolean> {
const reportName = path.basename(reportPath);
const buffer = await fs.promises.readFile(reportPath);
Expand All @@ -583,7 +584,7 @@ async function addDigestToReport(
async function transferTempToZip(
tempDir: string,
filePath: string,
allowSubDir: boolean = true
allowSubDir: boolean = true,
): Promise<string> {
const zip = new AdmZip();
if (allowSubDir) {
Expand Down Expand Up @@ -611,7 +612,7 @@ async function transferTempToZip(
} else {
console.log(`Zip file created at ${filePath}`);
console.log(
`Zip file contains: ${zip.getEntries().map((entry) => entry.entryName)}`
`Zip file contains: ${zip.getEntries().map((entry) => entry.entryName)}`,
);
}

Expand Down Expand Up @@ -643,15 +644,15 @@ async function getRepPath(fullTemp: string): Promise<string> {
if (dirs.includes("META-INF")) {
if (dirs.includes("reports")) {
console.log(
"Non-foldered report, found META-INF and reports directories"
"Non-foldered report, found META-INF and reports directories",
);
} else if (repZip.length > 0) {
console.log(
"Packaged report, found META-INF and zip with reports directories"
"Packaged report, found META-INF and zip with reports directories",
);
} else {
throw new Error(
"Report has META-INF but no reports directory or zip " + fullTemp
"Report has META-INF but no reports directory or zip " + fullTemp,
);
}
} else {
Expand All @@ -668,7 +669,7 @@ async function getRepPath(fullTemp: string): Promise<string> {
assert(
found,
"Report is missing dir with META-INF and/or reports directory in " +
fullTemp
fullTemp,
);
}
return repDirPath;
Expand All @@ -677,7 +678,7 @@ async function getRepPath(fullTemp: string): Promise<string> {
async function createExternalManifestZip(
signedRepPath: string,
origZipFilePath: string,
manJson: string
manJson: string,
): Promise<void> {
// Create a temporary directory
const tempDir = path.join(process.cwd(), "tempZipDir");
Expand Down Expand Up @@ -706,43 +707,43 @@ async function createExternalManifestZip(
fsExtra.removeSync(tempDir);

console.log(
`${EXTERNAL_MAN_TYPE} zip package file created at: ${signedRepPath}`
`${EXTERNAL_MAN_TYPE} zip package file created at: ${signedRepPath}`,
);
}

function validateReport(zip: AdmZip) {
const zipEntries = zip.getEntries();
// Check for META-INF directory and report.json
const metaInfEntry = zipEntries.find((entry) =>
entry.entryName.endsWith("META-INF/")
entry.entryName.endsWith("META-INF/"),
);
if (!metaInfEntry) {
throw new Error("META-INF directory not found in the zip file");
}

const reportJsonEntry = zipEntries.find((entry) =>
entry.entryName.endsWith("META-INF/reports.json")
entry.entryName.endsWith("META-INF/reports.json"),
);
if (!reportJsonEntry) {
throw new Error("report.json not found in META-INF directory");
}

// Check for reports directory or zip file
const reportsEntry = zipEntries.find(
(entry) => entry.entryName.endsWith("reports/") && entry.isDirectory
(entry) => entry.entryName.endsWith("reports/") && entry.isDirectory,
);
const reportsZipEntry = zipEntries.find((entry) =>
entry.entryName.endsWith(".zip")
entry.entryName.endsWith(".zip"),
);

if (!reportsEntry && !reportsZipEntry) {
throw new Error(
"Neither reports directory nor zip file found in the zip file"
"Neither reports directory nor zip file found in the zip file",
);
}

console.log(
"Validation passed: META-INF directory with report.json and either reports directory or zip file found."
"Validation passed: META-INF directory with report.json and either reports directory or zip file found.",
);
}

Expand All @@ -768,7 +769,7 @@ function findReportsDir(dirPath: string): string | null {

async function writeReportsJson(
fullTemp: string,
manJson: string
manJson: string,
): Promise<string> {
const dirPath = await getRepPath(fullTemp);
const manifestPath = path.join(dirPath, "META-INF", "reports.json");
Expand Down
13 changes: 8 additions & 5 deletions signify-ts-test/src/utils/resolve-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,15 @@ export class TestKeria {
`Container State: ${portInUse.State}\n` +
`Container Status: ${portInUse.Status}`,
);
if (pullImage) {
console.log(`Existing container running on ${portInUse}, stopping that one`)
if (pullImage) {
console.log(
`Existing container running on ${portInUse}, stopping that one`,
);
await pContainer.stop();
}
else {
console.log(`Existing container running on ${portInUse}, using that one`)
} else {
console.log(
`Existing container running on ${portInUse}, using that one`,
);
container = pContainer;
}
}
Expand Down
Loading

0 comments on commit 5648b8b

Please sign in to comment.