Skip to content

Commit 4ae4efc

Browse files
author
=
committed
ciscript
1 parent 2d2dddf commit 4ae4efc

File tree

2 files changed

+83
-39
lines changed

2 files changed

+83
-39
lines changed

MixewayBackend

Submodule MixewayBackend updated 25 files

scripts/CIScripts/mixeway-ci

Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#!/bin/bash
22

33
print_help() {
4-
pritnf "Mixeway Request script, is contacting with Mixeway REST API in order to request SAST scan and later it verify results found during scanning of source code and OpenSource
5-
Libraries\n\n\n"
6-
printf "Example usage:\nmixeway-ci --appname=projectName --groupname=groupName --mixewayurl=http://mixeway.io --mixewayapikey=123 --mixewayprojectid=1 --skipsast --skipopensource"
4+
printf "Mixeway-CI script is automation for executing SAST scans. By enabling proper options You are able to run OpenSource and SAST scans.
5+
Requirements: Mixeway avaliable and at least one OpenSource or SAST scanners registered \n\n"
6+
printf "Example usage:\nmixeway-ci --branch=master --tech=java_mvn --skipsast --skipopensource"
77
printf "\nRequired:\n"
8-
printf " --appname - Subject application name\n"
9-
printf " --groupname - Mixeway Group name build name\n"
10-
printf " --mixewayurl - URL for Mixeway API\n"
11-
printf " --mixewayapikey - API key generated on Mixeway to authenticate call\n"
12-
printf " --mixewayprojectid - ID of project on Mixeway\n"
8+
printf " --branch - branch name\n"
9+
printf " --tech - project technology, possible options: java_mvn, java_gradle, php_composer, javascript_npm, python_pip\n"
10+
printf "\nOptional:\n"
11+
printf " --mixewayurl - URL for mixeway, by default environment variable MIXEWAY_URL is taken\n"
12+
printf " --mixewayapikey - Master API get which can be generated in admin zone, be default environment variable MIXEWAY_API_KEY is taken\n"
1313
printf " --skipsast - to skip SAST scan\n"
1414
printf " --skipopensource - to skip OpenSource Vulnerability scan\n"
15+
1516
}
1617
if ! type jq > /dev/null; then
1718
echo "JQ has to be installed in order to run this script. Please install jq and try again."
@@ -25,32 +26,35 @@ if ! type git > /dev/null; then
2526
echo "Git has to be installed in order to run this script. Please install curl and try again."
2627
exit 2
2728
fi
29+
if [ ! -d .git ]; then
30+
pwd
31+
echo "Not a GIT repository"
32+
exit 2
33+
fi;
2834
skip_sast="false"
2935
skip_os="false"
3036
COMMITID=""
37+
CODE_PROJECT_ID=""
3138
while [ $# -gt 0 ]; do
3239
case "$1" in
33-
--appname=*)
34-
app_name="${1#*=}"
35-
;;
36-
--groupname=*)
37-
group_name="${1#*=}"
38-
;;
3940
--mixewayapikey=*)
4041
mixeway_api_key="${1#*=}"
4142
;;
4243
--mixewayurl=*)
4344
mixeway_url="${1#*=}"
4445
;;
45-
--mixewayprojectid=*)
46-
mixeway_project_id="${1#*=}"
47-
;;
4846
--skipsast*)
4947
skip_sast="true"
5048
;;
5149
--skipopensource*)
5250
skip_os="true"
5351
;;
52+
--branch*)
53+
branch="${1#*=}"
54+
;;
55+
--tech*)
56+
TECH="${1#*=}"
57+
;;
5458
--help=*)
5559
help_=1
5660
;;
@@ -62,11 +66,13 @@ while [ $# -gt 0 ]; do
6266
done
6367
get_commit_id() {
6468
COMMITID=$(git rev-parse HEAD)
69+
echo "CommitID: $COMMITID"
6570
}
66-
init_ci_job() {
67-
echo "Initializing CI job"
68-
curl -k -s --request GET --url $mixeway_url/v2/api/cicd/project/$mixeway_project_id/code/init/$group_name/$app_name/$COMMITID --header 'apikey: '"$mixeway_api_key"'' --output /dev/null
71+
get_repo_url() {
72+
REPO_URL=$(cat .git/config | grep "url = " | sed -E 's/\/\/(.*:.*@)/\/\//g' | gsed -E 's\url = \\g' |xargs)
73+
echo "REPO_URL: $REPO_URL"
6974
}
75+
#CHANGEIT
7076
run_sast() {
7177
echo "Request for a SAST"
7278
curl -k -s --request PUT --url $mixeway_url/v2/api/cicd/project/$mixeway_project_id/code/scan/$group_name/$app_name/$COMMITID --header 'apikey: '"$mixeway_api_key"'' --output /dev/null
@@ -82,58 +88,83 @@ send_bom() {
8288
$POSTDATA
8389
CURL_DATA
8490
}
91+
verify_mixeway_data() {
92+
if [ ! -z "$mixeway_url" ] && [ ! -z "$MIXEWAY_URL" ];
93+
then
94+
mixeway_url=$mixeway_url
95+
elif [ -z "$mixeway_url" ] && [ ! -z "$MIXEWAY_URL" ];
96+
then
97+
mixeway_url=$MIXEWAY_URL
98+
elif [ ! -z "$mixeway_url" ] && [ -z "$MIXEWAY_URL" ];
99+
then
100+
mixeway_url=$mixeway_url
101+
else
102+
echo "No Mixeway URL specified. Provide --mixewayurl or set MIXEWAY_URL env variable."
103+
exit 2
104+
fi
105+
if [ ! -z "$mixeway_api_key" ] && [ ! -z "$MIXEWAY_API_KEY" ];
106+
then
107+
mixeway_api_key=$mixeway_api_key
108+
elif [ -z "$mixeway_api_key" ] && [ ! -z "$MIXEWAY_API_KEY" ];
109+
then
110+
mixeway_api_key=$MIXEWAY_API_KEY
111+
elif [ ! -z "$mixeway_api_key" ] && [ -z "$MIXEWAY_API_KEY" ];
112+
then
113+
mixeway_api_key=$mixeway_api_key
114+
else
115+
echo "No Mixeway APIKEY specified. Provide --mixewayapikey or set MIXEWAY_API_KEY env variable."
116+
exit 2
117+
fi
118+
}
119+
send_info_about_opensource_scan() {
120+
REQUEST_BODY='{"scope":"opensource","codeProjectId":'$CODE_PROJECT_ID',"branch":"'branch'","commitId":"'COMMITID'"}'
121+
curl -k -s --request POST --url $mixeway_url/v2/api/cicd/infoscanperformed --header 'apikey: '"$mixeway_api_key"'' --data "$REQUEST_BODY"
122+
}
85123
run_opensource() {
86124
echo "Getting OpenSource Vulnerability scanner integration info"
87-
OS_RESPONSE=$(curl -k -s --request GET --url $mixeway_url/v2/api/show/project/$mixeway_project_id/opensource/$group_name/$app_name --header 'apikey: '"$mixeway_api_key"'')
125+
INFO_REQUEST_BODY='{"scope":"opensource","repoUrl":"'$REPO_URL'","branch":"'$branch'"}'
126+
OS_RESPONSE=$(curl -k -s --request POST --url $mixeway_url/v2/api/cicd/getscannerinfo --header 'apikey: '"$mixeway_api_key"'' --data "$INFO_REQUEST_BODY")
88127
INTEGRATION=$(echo $OS_RESPONSE | jq -r '.openSourceScannerIntegration')
89128
if [ "$INTEGRATION" = "true" ]; then
90129
echo "OpenSource scanner is avaliable proceeding..."
91130
OS_URL=$(echo $OS_RESPONSE | jq -r '.openSourceScannerApiUrl')
92131
OS_ID=$(echo $OS_RESPONSE | jq -r '.openSourceScannerProjectId')
93132
OS_APIKEY=$(echo $OS_RESPONSE | jq -r '.openSourceScannerCredentials')
133+
CODE_PROJECT_ID=$(echo $OS_RESPONSE | jq -r '.projectId')
94134
TECH=$(echo $OS_RESPONSE | jq -r '.tech')
95135
SCANNER_TYPE=$(echo $OS_RESPONSE | jq -r '.scannerType')
96136
TECH=$(echo "$TECH" | awk '{print tolower($0)}')
97137
if [ "$SCANNER_TYPE" = "OWASP Dependency Track" ]; then
98-
if [ "$TECH" = "mvn" ]; then
138+
if [ "$TECH" = "java_mvn" ]; then
99139
mvn org.cyclonedx:cyclonedx-maven-plugin:makeAggregateBom > /dev/null
100140
BOM=$(base64 target/bom.xml |tr -d \\n)
101141
send_bom
102-
elif [ "$TECH" = "js" ]; then
142+
elif [ "$TECH" = "javascript_npm" ]; then
103143
npm install --save ignore-errors
104144
cyclonedx-bom -o bom.xml
105145
BOM=$(base64 bom.xml |tr -d \\n)
106146
send_bom
107-
elif [ "$TECH" = "php" ]; then
147+
elif [ "$TECH" = "php_composer" ]; then
108148
composer require --dev cyclonedx/cyclonedx-php-composer --ignore-platform-reqs
109149
composer make-bom
110150
BOM=$(base64 bom.xml |tr -d \\n)
111151
send_bom
112-
elif [ "$TECH" = "python" ] ; then
152+
elif [ "$TECH" = "python_pip" ] ; then
113153
pip freeze > requirements.txt
114154
cyclonedx-py -i requirements.txt -o bom.xml
115155
BOM=$(base64 bom.xml |tr -d \\n)
116156
send_bom
157+
send_info_about_opensource_scan
117158
else
118-
echo "Unknown project tech. Supported: MVN, JS, Python, PHP"
159+
echo "Unknown project tech. Supported: java_mvn, javascript_npm, python_pip, php_composer"
119160
fi
120161
fi
121162
else
122163
echo "OpenSource Vulnerability Scan was requested but there no integration between given project and OpenSource scanner"
123164
fi
124165
}
125-
if [ ! -z "$app_name" ] && [ ! -z "$group_name" ] && [ ! -z "$mixeway_api_key" ] && [ ! -z "$mixeway_url" ] && [ ! -z "$mixeway_project_id" ]; then
126-
get_commit_id
127-
init_ci_job
128-
if [ $skip_sast = "false" ]; then
129-
run_sast
130-
fi
131-
if [ $skip_os = "false" ]; then
132-
run_opensource
133-
fi
134-
echo "Starting to verify of $app_name ..."
135-
136-
TIMEOUT=0
166+
verify() {
167+
TIMEOUT=0
137168
while true
138169
do
139170
MIXEWAY_RESPONSE=$(curl --request GET --url $mixeway_url/v2/api/cicd/project/$mixeway_project_id/code/verify/$group_name/$app_name/$COMMITID --header 'apikey: '"$mixeway_api_key"'' -k -s)
@@ -157,6 +188,19 @@ if [ ! -z "$app_name" ] && [ ! -z "$group_name" ] && [ ! -z "$mixeway_api_key" ]
157188
fi
158189
sleep 30
159190
done
191+
}
192+
if [ ! -z "$branch" ] && [ ! -z "$TECH" ] && [ -d .git ]; then
193+
verify_mixeway_data
194+
get_commit_id
195+
get_repo_url
196+
if [ $skip_sast = "false" ]; then
197+
run_sast
198+
fi
199+
if [ $skip_os = "false" ]; then
200+
run_opensource
201+
fi
202+
#echo "Starting to verify of $app_name ..."
160203
else
204+
printf "Not sufficient data or directory is not GIT repository check possible options: \n\n"
161205
print_help
162206
fi

0 commit comments

Comments
 (0)