veracodecli 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/veracodecli +21 -9
- data/lib/veracodecli/api.rb +38 -24
- data/test/test_veracodecli.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38a85c2a0d02935e016488510c19cfe2d3d34fcc
|
4
|
+
data.tar.gz: e46ceafd154bfb498b2f20dcb0c629ffb77f811b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f6b49907d5d2920f734c8dcf1c34dab1332ef24a4c578377152f1fa7011bc1456419cd00052839acd13646c8711b99ad6b26552f573659a7269219dab264c86
|
7
|
+
data.tar.gz: 7164c3bea8001f0c235c5cb852c9c488248c47868f6e55241af8314132de12e9a5f0db015038bc896093e95adff7309b1c05dc816313cf8396acf9c5d5ddefbe
|
data/bin/veracodecli
CHANGED
@@ -5,20 +5,31 @@ require 'veracodecli'
|
|
5
5
|
include VeracodeApiResults
|
6
6
|
include VeracodeApiScan
|
7
7
|
include VeracodeApiBase
|
8
|
+
include VeracodeApiMacros
|
8
9
|
|
9
10
|
Commander.configure do
|
10
11
|
program :name, 'veracodecli'
|
11
|
-
program :version, '0.1.
|
12
|
+
program :version, '0.1.2'
|
12
13
|
program :description, 'CLI for automating veracode api requests'
|
13
14
|
program :help, 'Author', 'Isaiah Thiessen <isaiah.thiessen@telus.com>'
|
14
15
|
|
15
16
|
command :scan do |c|
|
16
|
-
c.syntax = 'veracodecli scan [app_name] [
|
17
|
-
c.description = 'Submits a scan
|
18
|
-
c.
|
17
|
+
c.syntax = 'veracodecli scan [app_name] [repo] --option [option]'
|
18
|
+
c.description = 'Submits a scan to Veracode.'
|
19
|
+
c.option '--business_unit NAME', String, 'Business Unit Name'
|
20
|
+
c.option '--team NAME', String, 'Team Name'
|
21
|
+
c.option '--business_criticality', String, 'Application business criticality'
|
22
|
+
c.action do |args,options|
|
19
23
|
fail 'Specify application Name.' if args.first.nil?
|
20
|
-
fail 'Specify
|
21
|
-
VeracodeApiScan.submit_scan args[0], args[1]
|
24
|
+
fail 'Specify repo location.' if args[1].nil?
|
25
|
+
# VeracodeApiScan.submit_scan args[0], args[1]
|
26
|
+
options.default :business_criticality => 'High'
|
27
|
+
options.default :business_unit => 'TELUS Digital'
|
28
|
+
dir = "/home/#{ENV['USER']}/veracodecli_data/sast_clone"
|
29
|
+
if !Dir.exists?(dir) then `git clone #{args[1]} #{dir}` end
|
30
|
+
if Dir.exists?(dir) then `cd #{dir}; git pull; git archive --format=tar -o sast_upload.tar master` else fail 'Repository not found' end
|
31
|
+
VeracodeApiMacros.submit_scan_macro args[0], options.business_criticality, options.business_unit, options.team, 'sast_clone/sast_upload.tar'
|
32
|
+
`cd #{dir}; rm -r sast_upload.tar`
|
22
33
|
end
|
23
34
|
end
|
24
35
|
|
@@ -41,11 +52,12 @@ Commander.configure do
|
|
41
52
|
end
|
42
53
|
|
43
54
|
command :get_report do |c|
|
44
|
-
c.syntax = 'veracodecli get-report [
|
55
|
+
c.syntax = 'veracodecli get-report [app_name]'
|
45
56
|
c.description = 'Downloads the final scan report from Veracode.'
|
46
57
|
c.action do |args|
|
47
|
-
fail 'Specify
|
48
|
-
VeracodeApiResults.get_scan_report args.first
|
58
|
+
fail 'Specify app_name.' if args.first.nil?
|
59
|
+
#VeracodeApiResults.get_scan_report args.first
|
60
|
+
VeracodeApiMacros.get_scan_report args.first
|
49
61
|
end
|
50
62
|
end
|
51
63
|
|
data/lib/veracodecli/api.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rest-client'
|
|
4
4
|
|
5
5
|
module VeracodeApiBase
|
6
6
|
def check_environment_login_variables
|
7
|
-
fail 'EnvironmentError: VERACODE_USERNAME
|
7
|
+
fail 'EnvironmentError: VERACODE_USERNAME or VERACODE_PASSWORD not set.' unless !ENV['VERACODE_USERNAME'].nil? || !ENV['VERACODE_PASSWORD'].nil?
|
8
8
|
end
|
9
9
|
|
10
10
|
def veracode_api_request(api_call, api_version: '4.0', **params)
|
@@ -17,38 +17,33 @@ end
|
|
17
17
|
module VeracodeApiScan
|
18
18
|
include VeracodeApiBase
|
19
19
|
|
20
|
-
def
|
21
|
-
puts "Validating records for #{of}"
|
20
|
+
def get_app_id(app_name)
|
22
21
|
app_list = veracode_api_request 'getapplist.do', include_user_info: 'true'
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
puts "Record successfully created, app_id is #{app_id}"
|
31
|
-
return app_id
|
32
|
-
end
|
22
|
+
scan = app_list.scan(/app_id=\"(.+)\" app_name=\"#{app_name}\"/)
|
23
|
+
if !scan.nil? then app_id = scan[0][0] else app_id = nil end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_app_profile(app_name, business_criticality, business_unit, teams)
|
27
|
+
create_app_response = veracode_api_request 'createapp.do', app_name: app_name, business_criticality: business_criticality, business_unit: business_unit, teams: teams
|
28
|
+
app_id = create_app_response.scan(/app_id=\"(.+)\" app_name=\"#{of}\"/)[0][0]
|
33
29
|
end
|
34
30
|
|
35
|
-
def
|
36
|
-
app_id = validate_existance of: app_name
|
31
|
+
def upload_file(app_id, archive_path)
|
37
32
|
# NOTE: curl must be used here because of a bug in the Veracode api. rest-client cannot be used while this bug is present.
|
38
33
|
# NOTE: preferred code: upload_result = veracode_api_request 'uploadfile.do', app_id: app_id, file: "#{archive_path}"
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
upload_file_response = `curl --url "https://#{ENV['VERACODE_USERNAME']}:#{ENV['VERACODE_PASSWORD']}@analysiscenter.veracode.com/api/4.0/uploadfile.do" -F 'app_id=#{app_id}' -F 'file=@#{archive_path}'`
|
35
|
+
end
|
36
|
+
|
37
|
+
def submit_prescan(app_id)
|
38
|
+
submit_prescan_response = veracode_api_request 'beginprescan.do', app_id: app_id, auto_scan: 'true'
|
44
39
|
end
|
45
40
|
end
|
46
41
|
|
47
42
|
module VeracodeApiResults
|
48
43
|
include VeracodeApiBase
|
49
44
|
|
50
|
-
def get_most_recent_build_id(
|
51
|
-
build_list = veracode_api_request 'getbuildlist.do', app_id:
|
45
|
+
def get_most_recent_build_id(app_id)
|
46
|
+
build_list = veracode_api_request 'getbuildlist.do', app_id: app_id
|
52
47
|
build_list.scan(/build_id="(.*?)"/).last[0]
|
53
48
|
end
|
54
49
|
|
@@ -66,8 +61,27 @@ module VeracodeApiResults
|
|
66
61
|
end
|
67
62
|
|
68
63
|
def get_scan_report(app_id)
|
69
|
-
build_id = get_most_recent_build_id using: app_id
|
70
64
|
report = veracode_api_request 'detailedreport.do', api_version: '3.0', build_id: build_id
|
71
|
-
puts report
|
72
65
|
end
|
73
66
|
end
|
67
|
+
|
68
|
+
module VeracodeApiMacros
|
69
|
+
include VeracodeApiScan
|
70
|
+
include VeracodeApiResults
|
71
|
+
|
72
|
+
def submit_scan_macro(app_name, business_criticality, business_unit, teams, archive_path)
|
73
|
+
app_id = get_app_id(app_name)
|
74
|
+
if app_id.nil?
|
75
|
+
app_id = create_app_profile(app_name, business_criticality, business_unit, teams)
|
76
|
+
end
|
77
|
+
upload_file app_id, archive_path
|
78
|
+
submit_prescan app_id
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_report_macro(app_name)
|
82
|
+
app_id = get_app_id app_name
|
83
|
+
build_id = get_most_recent_build_id app_id
|
84
|
+
report = get_scan_report app_id
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/test/test_veracodecli.rb
CHANGED