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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74b3b2fddb38344c96cd938c9f27ec1ba5642125
4
- data.tar.gz: 3d2934ffea90f22732d1be2d5861e3e371d41993
3
+ metadata.gz: 38a85c2a0d02935e016488510c19cfe2d3d34fcc
4
+ data.tar.gz: e46ceafd154bfb498b2f20dcb0c629ffb77f811b
5
5
  SHA512:
6
- metadata.gz: 4a97bfed947f96df61ca3f142243fc7861ffbcdd248e846d3832c08ee7903a2314052d81df6880b4a20a23696c700be9ce4738fde91c995f2cb81688179104ce
7
- data.tar.gz: fe856103bdbd2a8946710fec5ecb6209146de7770f3fe68bae41f7fb7b0fcfb6ee9d7f92f53196018a3421eb82792fa1cdf3b5eb4244b262a19b3793faea405a
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.0'
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] [archive_path]'
17
- c.description = 'Submits a scan request to Veracode.'
18
- c.action do |args|
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 path to code archive.' if args[1].nil?
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 [app_id]'
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 app_id.' if args.first.nil?
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
 
@@ -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, VERACODE_PASSWORD, or VERACODE_TEAM not set.' unless !ENV['VERACODE_USERNAME'].nil? || !ENV['VERACODE_PASSWORD'].nil? || !ENV['VERACODE_TEAM'].nil?
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 validate_existance(of:)
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
- if app_list.include? "#{of}"
24
- puts 'Record found, submitting'
25
- return app_list.scan(/app_id=\"(.+)\" app_name=\"#{of}\"/)[0][0]
26
- else
27
- puts 'Record not found, creating one'
28
- create_app_result = veracode_api_request 'createapp.do', app_name: of, description: "Static Scanning profile for #{of}.", business_criticality: 'High', business_unit: "#{ENV['VERACODE_TEAM']}", web_application: 'true', teams: "#{ENV['VERACODE_TEAM']}"
29
- app_id = create_app_result.scan(/app_id=\"(.+)\" app_name=\"#{of}\"/)[0][0]
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 submit_scan(app_name, archive_path)
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
- upload_result = `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}'`
40
- puts upload_result
41
- prescan_submission_result = veracode_api_request 'beginprescan.do', app_id: app_id, auto_scan: 'true'
42
- puts prescan_submission_result
43
- puts "Submit complete for #{app_id}"
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(using:)
51
- build_list = veracode_api_request 'getbuildlist.do', app_id: using
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
@@ -13,7 +13,7 @@ class TestVeracodecli < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  should 'Return HTTP 401' do
16
- assert_equal response.code, veracode_api_request('getapplist.do', '')
16
+ assert_kind_of String, veracode_api_request('getapplist.do')
17
17
  end
18
18
 
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: veracodecli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - isaiah thiessen