Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Kc committed Jul 26, 2023
1 parent 630de32 commit 49402ea
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
38 changes: 0 additions & 38 deletions src/runOSQuery.ts

This file was deleted.

38 changes: 38 additions & 0 deletions src/runOsquery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { exec } from 'child_process';
import * as os from 'os';

export enum OsType {
LINUX = 'linux',
DARWIN = 'darwin',
WINDOWS_NT = 'windows_nt',
}

/**
* Executes an osquery command and returns the output.
* @param query The osquery command to be executed.
* @param osTypes The list of operating systems on which the command can be executed.
* @return A Promise that resolves with the command output, or rejects with an error message.
*/
export function runOsquery(query: string, osTypes: OsType[]): Promise<string> {
return new Promise((resolve, reject) => {
const currentOsType = os.type().toLowerCase();

if (!osTypes.includes(currentOsType as OsType)) {
reject(`Unsupported operating system: ${currentOsType}`);
return;
}

exec(
`osqueryi --json "${query}"`,
(error: Error | null, stdout: string, stderr: string) => {
if (error) {
reject(`Execution error: ${error.message}`);
} else if (stderr) {
reject(`Command error: ${stderr}`);
} else {
resolve(stdout);
}
},
);
});
}

0 comments on commit 49402ea

Please sign in to comment.