Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/artifact-preservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
export function preserveIptablesAudit(workDir: string, auditDir?: string): void {
const iptablesAuditSrc = path.join(workDir, 'init-signal', 'iptables-audit.txt');
const targetAuditDir = auditDir || path.join(workDir, 'audit');
if (fs.existsSync(iptablesAuditSrc) && fs.existsSync(targetAuditDir)) {

Check warning on line 16 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / ESLint

Found existsSync from package "fs" with non literal argument at index 0

Check warning on line 16 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / ESLint

Found existsSync from package "fs" with non literal argument at index 0

Check warning on line 16 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 22)

Found existsSync from package "fs" with non literal argument at index 0

Check warning on line 16 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 22)

Found existsSync from package "fs" with non literal argument at index 0

Check warning on line 16 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 20)

Found existsSync from package "fs" with non literal argument at index 0

Check warning on line 16 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 20)

Found existsSync from package "fs" with non literal argument at index 0
try {
fs.copyFileSync(iptablesAuditSrc, path.join(targetAuditDir, 'iptables-audit.txt'));
fs.chmodSync(path.join(targetAuditDir, 'iptables-audit.txt'), 0o644);

Check warning on line 19 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / ESLint

Found chmodSync from package "fs" with non literal argument at index 0

Check warning on line 19 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 22)

Found chmodSync from package "fs" with non literal argument at index 0

Check warning on line 19 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 20)

Found chmodSync from package "fs" with non literal argument at index 0
logger.debug('Copied iptables audit state to audit directory');
} catch (error) {
logger.debug('Could not copy iptables audit file:', error);
Expand All @@ -36,7 +36,6 @@
permissionErrorMessage: string;
preserveErrorMessage: string;
chmodPreservedDir?: boolean;
runtimeDirMustExist?: boolean;
};

function preserveDirectory({
Expand All @@ -51,11 +50,10 @@
permissionErrorMessage,
preserveErrorMessage,
chmodPreservedDir = false,
runtimeDirMustExist = true,
}: PreserveDirectoryOptions): void {
if (runtimeDir) {
const targetDir = runtimeSubdir ? path.join(runtimeDir, runtimeSubdir) : runtimeDir;
if (!runtimeDirMustExist || fs.existsSync(targetDir)) {
if (fs.existsSync(targetDir)) {

Check warning on line 56 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / ESLint

Found existsSync from package "fs" with non literal argument at index 0

Check warning on line 56 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 22)

Found existsSync from package "fs" with non literal argument at index 0

Check warning on line 56 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 20)

Found existsSync from package "fs" with non literal argument at index 0
try {
execa.sync('chmod', ['-R', 'a+rX', targetDir]);
logger.info(`${availableLabel} available at: ${targetDir}`);
Expand All @@ -68,9 +66,9 @@

const sourceDir = path.join(workDir, workSubdir);
const destinationDir = path.join(os.tmpdir(), `${destinationBaseName}-${timestamp}`);
if (fs.existsSync(sourceDir) && fs.readdirSync(sourceDir).length > 0) {

Check warning on line 69 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / ESLint

Found readdirSync from package "fs" with non literal argument at index 0

Check warning on line 69 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / ESLint

Found existsSync from package "fs" with non literal argument at index 0

Check warning on line 69 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 22)

Found readdirSync from package "fs" with non literal argument at index 0

Check warning on line 69 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 22)

Found existsSync from package "fs" with non literal argument at index 0

Check warning on line 69 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 20)

Found readdirSync from package "fs" with non literal argument at index 0

Check warning on line 69 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 20)

Found existsSync from package "fs" with non literal argument at index 0
try {
fs.renameSync(sourceDir, destinationDir);

Check warning on line 71 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / ESLint

Found renameSync from package "fs" with non literal argument at index 0,1

Check warning on line 71 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 22)

Found renameSync from package "fs" with non literal argument at index 0,1

Check warning on line 71 in src/artifact-preservation.ts

View workflow job for this annotation

GitHub Actions / Build and Lint (Node 20)

Found renameSync from package "fs" with non literal argument at index 0,1
if (chmodPreservedDir) {
execa.sync('chmod', ['-R', 'a+rX', destinationDir]);
}
Expand Down Expand Up @@ -156,7 +154,6 @@
permissionErrorMessage: 'Could not fix squid log permissions:',
preserveErrorMessage: 'Could not preserve squid logs:',
chmodPreservedDir: true,
runtimeDirMustExist: false,
});

if (auditDir) {
Expand Down
8 changes: 8 additions & 0 deletions src/docker-manager-cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ describe('docker-manager cleanup', () => {
}
});

it('should skip squid log chmod when proxyLogsDir does not exist', async () => {
const proxyLogsDir = path.join(os.tmpdir(), `awf-missing-proxy-logs-${Date.now()}`);

await cleanup(getDir(), false, proxyLogsDir);

expect(mockExecaSync).not.toHaveBeenCalledWith('chmod', ['-R', 'a+rX', proxyLogsDir]);
});

it('should chmod api-proxy-logs subdirectory when proxyLogsDir is specified', async () => {
// proxyLogsDir must be OUTSIDE workDir since cleanup deletes workDir
const externalDir = fs.mkdtempSync(path.join(os.tmpdir(), 'awf-proxy-logs-test-'));
Expand Down
Loading