-
Notifications
You must be signed in to change notification settings - Fork 6
/
inspector
executable file
·178 lines (139 loc) · 4.82 KB
/
inspector
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env ruby
=begin
Copyright 2016 SourceClear Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end
require 'optparse'
require_relative 'lib/build_inspector'
require_relative 'lib/configuration'
require_relative 'lib/evidence_collector'
require_relative 'lib/evidence_processor'
require_relative 'lib/printer'
require_relative 'lib/vagrant_whisperer'
require_relative 'lib/report_builder'
require_relative 'inspector_lib'
# Don't buffer output; flush it immediately.
$stdout.sync = true
options = {
rollback: true,
config: 'config.yml',
branch: 'master',
s3: false,
script: nil,
only_process: nil,
is_url: false,
verbose: false,
repo: nil,
results: nil
}
optparse = OptionParser.new do |opts|
opts.banner = "Usage #{File.basename($0)} [options] <git repo path>"
opts.on('-h', '--help', 'Display this screen') do
puts opts
exit
end
opts.on('-n', '--no-rollback',
'Do not roll back the virtual machine state after running') do
options[:rollback] = false
end
opts.on('-v', '--verbose', 'Be verbose') do
options[:verbose] = true
end
opts.on('-c', '--config <PATH>', String,
"Use configuration file at <PATH>, default=#{options[:config]}") do |config|
options[:config] = config
end
opts.on('-p', '--process <PATH>', String,
'Only process evidence at <PATH>') do |evidence_path|
options[:only_process] = evidence_path
end
opts.on('-r', '--results <PATH>', String,
'Load previously analyzed results at <PATH>') do |results_path|
options[:results] = results_path
end
opts.on('-s', '--script <PATH>', String,
'Run script at <PATH> against evidence.') do |script|
options[:script] = script
end
opts.on('-b', '--branch <BRANCH>', String,
"Clone <BRANCH> from repository URL") do |branch|
options[:branch] = branch
end
opts.on('-P', '--package <PACKAGE>', String, 'Install specified <PACKAGE>') do |package|
options[:package] = package
end
opts.on('--url', String, "Git repo path is a URL") do
options[:is_url] = true
end
opts.on('--gem', String, "Perform a GEM based build") do |type|
options[:package_manager] = 'gem'
if options[:package]
options[:config] = 'configs/gem.yml'
else
options[:config] = 'configs/bundler.yml'
end
end
opts.on('--gradle', String, "Perform a Gradle based build") do |type|
options[:package_manager] = 'gradle'
options[:config] = 'configs/gradle.yml'
if options[:package]
options[:package] = nil
end
end
opts.on('--maven', String, "Perform a Maven based build") do |type|
options[:package_manager] = 'maven'
options[:config] = 'configs/maven.yml'
if options[:package]
options[:package] = nil
end
end
opts.on('--npm', String, "Perform a NPM based build") do |type|
options[:package_manager] = 'npm'
options[:config] = 'configs/npm.yml'
end
end
optparse.parse!
no_package_to_analyze = ARGV.size < 1 && options[:package].nil?
no_evidence_to_process = options[:only_process].nil?
no_script_to_run = (ARGV.size < 1 && options[:script].nil?) || (options[:only_process].nil? && options[:script].nil?)
if no_package_to_analyze && no_evidence_to_process && no_script_to_run
puts 'Please specify a repository URL or Path; Or an evidence to process; Or a script to run on a/an repo/evidence'
puts optparse.help
exit -1
elsif no_package_to_analyze && no_evidence_to_process && !no_script_to_run
puts 'Please specify an/a evidence/package/repo to be processed with --process, --package, --url, or <REPO PATH>'
exit -1
end
if ARGV.size >= 1 && !options[:package].nil?
puts "Package detected, Repo path #{ARGV.first} will be ignored"
elsif ARGV.size >= 1
options[:repo] = ARGV.first
end
if !no_evidence_to_process
process_script_text = "with script at #{options[:script]}" if options[:script]
if options[:only_process] == 's3'
puts "Processing evidence stored in S3 #{process_script_text}"
options[:s3] = true
else
puts "Processing evidence at #{options[:only_process]} #{process_script_text}"
end
if !no_package_to_analyze
if options[:repo]
puts "Ignoring repo #{options[:repo]} to analyze"
options[:repo] = nil
end
if options[:package]
puts "Ignoring package #{options[:package]} to analyze"
options[:package] = nil
end
end
end
run_inspector(options, options[:repo])