Skip to content

Commit ddbe643

Browse files
committed
Better formatting for output
1 parent ffaf8c0 commit ddbe643

File tree

7 files changed

+53
-20
lines changed

7 files changed

+53
-20
lines changed

Dockerfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ RUN apt-get update && \
2828
apt-utils \
2929
rsync \
3030
file \
31+
dos2unix \
3132
gettext && \
3233
apt-get clean && \
3334
ln -s /usr/bin/python3.8 /usr/bin/python && \
@@ -60,20 +61,22 @@ RUN mkdir -p ${CODEQL_HOME} \
6061
${CODEQL_HOME}/codeql-go-repo \
6162
/opt/codeql
6263

63-
RUN CODEQL_VERSION=$(cat /tmp/codeql_version) && \
64-
wget -q https://github.com/github/codeql-cli-binaries/releases/download/${CODEQL_VERSION}/codeql-linux64.zip -O /tmp/codeql_linux.zip && \
65-
unzip /tmp/codeql_linux.zip -d ${CODEQL_HOME} && \
66-
rm /tmp/codeql_linux.zip
67-
6864
# get the latest codeql queries and record the HEAD
6965
RUN git clone https://github.com/github/codeql ${CODEQL_HOME}/codeql-repo && \
7066
git --git-dir ${CODEQL_HOME}/codeql-repo/.git log --pretty=reference -1 > /opt/codeql/codeql-repo-last-commit
7167
RUN git clone https://github.com/github/codeql-go ${CODEQL_HOME}/codeql-go-repo && \
7268
git --git-dir ${CODEQL_HOME}/codeql-go-repo/.git log --pretty=reference -1 > /opt/codeql/codeql-go-repo-last-commit
7369

70+
RUN CODEQL_VERSION=$(cat /tmp/codeql_version) && \
71+
wget -q https://github.com/github/codeql-cli-binaries/releases/download/${CODEQL_VERSION}/codeql-linux64.zip -O /tmp/codeql_linux.zip && \
72+
unzip /tmp/codeql_linux.zip -d ${CODEQL_HOME} && \
73+
rm /tmp/codeql_linux.zip
74+
7475
ENV PATH="${CODEQL_HOME}/codeql:${PATH}"
7576

7677
# Pre-compile our queries to save time later
77-
#RUN codeql query compile --threads=0 ${CODEQL_HOME}/codelq-repo/*/ql/src/codeql-suites/*-.qls
78-
#RUN codeql query compile --threads=0 ${CODEQL_HOME}/codelq-go-repo/ql/src/codeql-suites/*-.qls
78+
RUN codeql query compile --threads=0 ${CODEQL_HOME}/codeql-repo/*/ql/src/codeql-suites/*.qls
79+
RUN codeql query compile --threads=0 ${CODEQL_HOME}/codeql-go-repo/ql/src/codeql-suites/*.qls
80+
81+
ENV PYTHONIOENCODING=utf-8
7982
ENTRYPOINT ["python3", "/usr/local/startup_scripts/startup.py"]

container/libs/codeql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class CodeQL:
2424
ERROR_UNKNOWN_OS = 3
2525
ERROR_GIT_COMMAND = 4
2626

27-
def __init__(self, codeql_base_dir):
28-
self.CODEQL_HOME = codeql_base_dir
27+
def __init__(self, codeql_base_dir):
28+
self.CODEQL_HOME = codeql_base_dir
2929

3030
def download_and_install_latest_codeql(self, github_version):
3131
"""

container/libs/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ def check_output_wrapper(*args, **kwargs):
3131
try:
3232
return check_output(*args, **kwargs)
3333
except CalledProcessError as msg:
34-
logger.warning('Error %s,%s,%s from command.', msg.returncode, msg.output, msg.stderr)
35-
logger.debug('Output: %s', msg.output)
34+
logger.error(f"Error {msg.returncode} executing from command.")
35+
if msg.stderr != None:
36+
print("Command Error Output:\n" + msg.stderr.decode('utf-8'))
37+
if msg.output != None:
38+
print("Command Output: \n" + msg.output.decode('utf-8'))
39+
logger.error("Exiting...")
3640
sys.exit(ERROR_EXECUTING_COMMAND);
3741

3842
def wipe_and_create_dir(dirname):

container/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ def setup():
3333
Download and install the latest codeql cli
3434
Download and install the latest codeql queries
3535
"""
36+
logger.info("Starting setup...")
3637
args = parse_arguments()
3738
# check version and download the latest version
3839
get_latest_codeql(args)
39-
40+
logger.info("End setup...")
4041
def get_latest_codeql(args):
4142
# what version do we have?
4243
codeql = CodeQL(CODEQL_HOME)

container/startup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ def main():
4141
# what command did the user ask to run?
4242
if CODEQL_CLI_ARGS == False or CODEQL_CLI_ARGS == None or CODEQL_CLI_ARGS == ' ':
4343
# 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...")
44+
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...")
4545
else:
4646
codeql = CodeQL(CODEQL_HOME)
4747
run_result = codeql.execute_codeql_command(CODEQL_CLI_ARGS)
48-
print(run_result)
49-
48+
5049
if WAIT_AFTER_EXEC:
5150
logger.info("Wait forever specified, waiting...")
5251
while True:

scripts/unix/analyze_security.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ if [ "$#" -ne 2 ]; then
99
exit 1
1010
fi
1111

12-
#docker pull codeql/codeql-container
12+
RED=''
13+
RESET=''
14+
#docker pull sargemonkey/codeql-container
15+
#[ $? -eq 0 ] && echo "Pulled the container" || echo -e "failed to pull container";exit 1
1316
docker run --rm --name codeql-container -v "${inputfile}:/opt/src" -v "${outputfile}:/opt/results" -e CODEQL_CLI_ARGS=database\ create\ --language=python\ /opt/src/source_db csteosstools.azurecr.io/codeql/codeql-container
17+
[ $? -eq 0 ] && echo "Created the database" || echo -e "\n${RED}Failed to create the database${RESET}\n";exit 1
1418
docker run --rm --name codeql-container -v "${inputfile}:/opt/src" -v "${outputfile}:/opt/results" -e CODEQL_CLI_ARGS=database\ upgrade\ /opt/src/source_db csteosstools.azurecr.io/codeql/codeql-container
19+
[ $? -eq 0 ] && echo "Upgraded the database" || echo -e "\n${RED}failed to upgrade the database${RESET}\n";exit 2
1520
docker run --rm --name codeql-container -v ${inputfile}:/opt/src -v ${outputfile}:/opt/results -e CODEQL_CLI_ARGS=database\ analyze\ /opt/src/source_db\ --format=sarifv2\ --output=/opt/results/issues.sarif\ python-security-and-quality.qls csteosstools.azurecr.io/codeql/codeql-container
21+
[ $? -eq 0 ] && echo "Query execution successful" || echo -e "\n${RED}Query execution failed${RESET}\n"; exit 3
1622

17-
echo "If there were no errors in the execution, the results file should be located at ${2}/issues.sarif"
23+
echo "The results file should be located at ${2}/issues.sarif"

scripts/windows/analyze_security.bat

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,27 @@ exit /b 1
2020
rem docker pull codeql/codeql-container
2121
echo docker run --rm --name codeql-container -v "%inputfile%:/opt/src" -v "%outputfile%:/opt/results" -e CODEQL_CLI_ARGS="database create --language=python /opt/src/source_db" csteosstools.azurecr.io/codeql/codeql-container
2222
start /W /B docker run --rm --name codeql-container -v "%inputfile%:/opt/src" -v "%outputfile%:/opt/results" -e CODEQL_CLI_ARGS="database create --language=python /opt/src/source_db" csteosstools.azurecr.io/codeql/codeql-container
23-
echo docker run --rm --name codeql-container -v "%inputfile%:/opt/src" -v "%outputfile%:/opt/results" -e CODEQL_CLI_ARGS="database upgrade /opt/src/source_db" csteosstools.azurecr.io/codeql/codeql-container
24-
echo docker run --rm --name codeql-container -v "%inputfile%:/opt/src" -v "%outputfile%:/opt/results" -e CODEQL_CLI_ARGS="database analyze /opt/src/source_db --format=sarifv2 --output=/opt/results/issues.sarif python-security-and-quality.qls" csteosstools.azurecr.io/codeql/codeql-container
2523

26-
echo "If there were no errors in the execution, the results file should be located at %2/issues.sarif"
24+
call :print_status "Failed creating the database" , %errorlevel%
25+
if %errorlevel% GTR 0 (
26+
call :print_exit_error "Failed creating the database"
27+
exit /b %errorlevel%
28+
)
29+
start /W /B docker run --rm --name codeql-container -v "%inputfile%:/opt/src" -v "%outputfile%:/opt/results" -e CODEQL_CLI_ARGS="database upgrade /opt/src/source_db" csteosstools.azurecr.io/codeql/codeql-container
30+
if %errorlevel% GTR 0 (
31+
call :print_exit_error "Failed upgrading the database"
32+
exit /b %errorlevel%
33+
)
34+
start /W /B docker run --rm --name codeql-container -v "%inputfile%:/opt/src" -v "%outputfile%:/opt/results" -e CODEQL_CLI_ARGS="database analyze /opt/src/source_db --format=sarifv2 --output=/opt/results/issues.sarif python-security-and-quality.qls" csteosstools.azurecr.io/codeql/codeql-container
35+
if %errorlevel% GTR 0 (
36+
call :print_exit_error "Failed to run the query on the database"
37+
exit /b %errorlevel%
38+
)
39+
echo "The results file should be located at %2\issues.sarif"
40+
41+
42+
:print_exit_error
43+
echo.
44+
echo %~1
45+
echo.
46+
echo Exiting...

0 commit comments

Comments
 (0)