|
1 | | -import os |
2 | | -import sys |
3 | | -from time import sleep |
4 | | -from libs.utils import get_env_variable, check_output_wrapper, get_logger |
5 | | -from libs.codeql import * |
6 | | - |
7 | | -CODEQL_HOME = get_env_variable('CODEQL_HOME') |
8 | | - |
9 | | -# should we update the local copy of codeql-cli if a new version is available? |
10 | | -CHECK_LATEST_CODEQL_CLI = get_env_variable('CHECK_LATEST_CODEQL_CLI', True) |
11 | | - |
12 | | -# should we update the local copy of codeql queries if a new version is available? |
13 | | -CHECK_LATEST_QUERIES = get_env_variable('CHECK_LATEST_QUERIES', True) |
14 | | - |
15 | | -# if we are downloading new queries, should we precompile them |
16 | | -#(makes query execution faster, but building the container build slower). |
17 | | -PRECOMPILE_QUERIES = get_env_variable('PRECOMPILE_QUERIES', True) |
18 | | - |
19 | | -# ql packs, requested to run, if any |
20 | | -CODEQL_CLI_ARGS = get_env_variable('CODEQL_CLI_ARGS', True) |
21 | | - |
22 | | -# should we just exit after execution, or should we wait for user to stop container? |
23 | | -WAIT_AFTER_EXEC = get_env_variable('WAIT_AFTER_EXEC', True) |
24 | | - |
25 | | -def main(): |
26 | | - # do the setup, if requested |
27 | | - scripts_dir = os.path.dirname(os.path.realpath(__file__)) # get the parent directory of the script |
28 | | - setup_script_args = '' |
29 | | - if CHECK_LATEST_CODEQL_CLI: |
30 | | - setup_script_args += ' --check-latest-cli' |
31 | | - if CHECK_LATEST_QUERIES: |
32 | | - setup_script_args += ' --check-latest-queries' |
33 | | - if PRECOMPILE_QUERIES: |
34 | | - setup_script_args += ' --precompile-latest-queries' |
35 | | - |
36 | | - run_result = check_output_wrapper( |
37 | | - f"{scripts_dir}/setup.py {setup_script_args}", |
38 | | - shell=True).decode("utf-8") |
39 | | - |
40 | | - # what command did the user ask to run? |
41 | | - if CODEQL_CLI_ARGS == False or CODEQL_CLI_ARGS == None or CODEQL_CLI_ARGS == ' ': |
42 | | - # nothing to do |
43 | | - logger.info("No argument passed in for codeql-cli, nothing to do. To perform some task, please set the CODEQL_CLI_ARGS environment variable to a valid argument..") |
44 | | - else: |
45 | | - codeql = CodeQL(CODEQL_HOME) |
46 | | - run_result = codeql.execute_codeql_command(CODEQL_CLI_ARGS) |
47 | | - print(run_result) |
48 | | - |
49 | | - if WAIT_AFTER_EXEC: |
50 | | - logger.info("Wait forever specified, waiting...") |
51 | | - while True: |
52 | | - sleep(10) |
53 | | - |
54 | | -logger = get_logger() |
55 | | -main() |
| 1 | +#!/usr/bin/env python3 |
| 2 | +import os |
| 3 | +import sys |
| 4 | +from time import sleep |
| 5 | +from libs.utils import get_env_variable, check_output_wrapper, get_logger |
| 6 | +from libs.codeql import * |
| 7 | + |
| 8 | +CODEQL_HOME = get_env_variable('CODEQL_HOME') |
| 9 | + |
| 10 | +# should we update the local copy of codeql-cli if a new version is available? |
| 11 | +CHECK_LATEST_CODEQL_CLI = get_env_variable('CHECK_LATEST_CODEQL_CLI', True) |
| 12 | + |
| 13 | +# should we update the local copy of codeql queries if a new version is available? |
| 14 | +CHECK_LATEST_QUERIES = get_env_variable('CHECK_LATEST_QUERIES', True) |
| 15 | + |
| 16 | +# if we are downloading new queries, should we precompile them |
| 17 | +#(makes query execution faster, but building the container build slower). |
| 18 | +PRECOMPILE_QUERIES = get_env_variable('PRECOMPILE_QUERIES', True) |
| 19 | + |
| 20 | +# ql packs, requested to run, if any |
| 21 | +CODEQL_CLI_ARGS = get_env_variable('CODEQL_CLI_ARGS', True) |
| 22 | + |
| 23 | +# should we just exit after execution, or should we wait for user to stop container? |
| 24 | +WAIT_AFTER_EXEC = get_env_variable('WAIT_AFTER_EXEC', True) |
| 25 | + |
| 26 | +def main(): |
| 27 | + # do the setup, if requested |
| 28 | + scripts_dir = os.path.dirname(os.path.realpath(__file__)) # get the parent directory of the script |
| 29 | + setup_script_args = '' |
| 30 | + if CHECK_LATEST_CODEQL_CLI: |
| 31 | + setup_script_args += ' --check-latest-cli' |
| 32 | + if CHECK_LATEST_QUERIES: |
| 33 | + setup_script_args += ' --check-latest-queries' |
| 34 | + if PRECOMPILE_QUERIES: |
| 35 | + setup_script_args += ' --precompile-latest-queries' |
| 36 | + |
| 37 | + run_result = check_output_wrapper( |
| 38 | + f"{scripts_dir}/setup.py {setup_script_args}", |
| 39 | + shell=True).decode("utf-8") |
| 40 | + |
| 41 | + # what command did the user ask to run? |
| 42 | + if CODEQL_CLI_ARGS == False or CODEQL_CLI_ARGS == None or CODEQL_CLI_ARGS == ' ': |
| 43 | + # nothing to do |
| 44 | + logger.info("No valid argument passed in for codeql-cli, nothing to do. To perform some task, please set the CODEQL_CLI_ARGS environment variable to a valid argument...") |
| 45 | + else: |
| 46 | + codeql = CodeQL(CODEQL_HOME) |
| 47 | + run_result = codeql.execute_codeql_command(CODEQL_CLI_ARGS) |
| 48 | + print(run_result) |
| 49 | + |
| 50 | + if WAIT_AFTER_EXEC: |
| 51 | + logger.info("Wait forever specified, waiting...") |
| 52 | + while True: |
| 53 | + sleep(10) |
| 54 | + |
| 55 | +logger = get_logger() |
| 56 | +main() |
0 commit comments