21
21
22
22
set -e
23
23
24
- java -version
25
- if [ " $? " != 0 ]
26
- then
27
- echo " Java has not been setup"
28
- exit 1
29
- fi
24
+ # Generate temporary `settings.gradle` file based on the name in `build.gradle`
25
+ function generate_settings_gradle() {
26
+ settings_gradle_content=` cat build.gradle | grep name | grep -i $repo | head -n 1 | sed ' s/name/rootProject.name =/g' | awk ' {$1=$1};1' `
27
+ echo $settings_gradle_content > settings.gradle
28
+ cat settings.gradle
29
+ }
30
+
31
+ java -version; gradle -v; mvn -v; node -v; npm -v; yarn -v
30
32
31
33
if [ ! -f " wss-unified-agent.jar" ]
32
34
then
33
35
# Download the WhiteSource Agent
34
- curl https://unified-agent.s3.amazonaws.com/wss-unified-agent-21.11.1.jar --output wss-unified-agent.jar
36
+ curl https://unified-agent.s3.amazonaws.com/wss-unified-agent-21.11.2. 1.jar --output wss-unified-agent.jar
35
37
fi
36
38
37
39
# scan the config file for the user configurations
@@ -47,33 +49,67 @@ basepath=$baseDirPath"/repos"
47
49
48
50
echo " Cleaning up scan directories if already present"
49
51
rm -rf $basepath
52
+ echo " Cleaning up temp file that will affect scan"
53
+ rm -rf /tmp/ws*
50
54
51
55
mkdir -p $basepath
52
56
53
57
# clone the desired Repos for scanning
54
58
for repo in $gitRepos
55
59
do
56
60
echo " Cloning repo " $gitBasePath$repo
57
- git clone " $gitBasePath$repo " .git $basepath " /" $repo
61
+ if [ ${repo} == " OpenSearch" ]
62
+ then
63
+ echo " Cloning " $repo " at branch 1.x"
64
+ git clone -b 1.x " $gitBasePath$repo " .git ${basepath} /${repo}
65
+ # /qa/ in OpenSearch repo contains all files related to the previous version of ODFE.
66
+ # WhiteSource will attept to download them and take hours to build or timeout error.
67
+ # Remove /qa/ because it's irrelevant to OpenSearch.
68
+ rm -rf ${basepath} /${repo} /qa
69
+ else
70
+ echo " Cloning " $repo " at main branch"
71
+ git clone " $gitBasePath$repo " .git ${basepath} /${repo}
72
+ fi
58
73
done
59
74
60
75
echo -n > info.txt
61
76
target=' OpenSearch'
62
- mvn -v; node -v; npm -v; yarn -v
63
77
64
78
# scan the Repos using the WhiteSource Unified Agent
65
79
for repo in $gitRepos
66
80
do
67
81
repo_path=$basepath " /" $repo
68
82
if [ -d " $repo_path " ]
69
83
then
84
+ cd $repo_path
70
85
echo " Scanning repo: " $gitBasePath$repo " Project: " $repo
71
- java -jar wss-unified-agent.jar -c wss-unified-agent.config -d $repo_path -apiKey $wss_apikey -product " $target " -project $repo
86
+ if [ -e " build.gradle" ]
87
+ then
88
+ echo " build.gradle for $repo exist in root"
89
+ if [ ! -e " settings.gradle" ]
90
+ then
91
+ echo " settings.gradle not exist in $repo , create one based on build.gradle name"
92
+ generate_settings_gradle
93
+ else
94
+ echo " settings.gradle exist $repo "
95
+ fi
96
+ else
97
+ # Exceptions for some repos that have `build.gradle` in sub-folder
98
+ if [ ${repo} == " observability" ]
99
+ then
100
+ cd $repo_path /opensearch-observability
101
+ generate_settings_gradle
102
+ else
103
+ echo " build.gradle for $repo not exist, either dashboards repo or missing necessary files"
104
+ fi
105
+ fi
106
+ java -jar $baseDirPath /wss-unified-agent.jar -c $baseDirPath /wss-unified-agent.config -d $repo_path -apiKey $wss_apikey -product " $target " -project $repo
107
+ cd $baseDirPath && pwd
72
108
else
73
109
echo " Scanning failed for repo: " $gitBasePath$repo " Project: " $repo
74
110
fi
75
111
done
76
112
77
113
# remove the WhiteSource unified Jar
78
- rm " wss-unified-agent.jar"
79
- echo " WhiteSource vulnerability scan completed"
114
+ rm $baseDirPath / wss-unified-agent.jar
115
+ echo " WhiteSource vulnerability scan completed"
0 commit comments