wss_agent 18.10.2 → 18.10.3

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -15
  3. data/.rspec +2 -2
  4. data/.travis.yml +6 -6
  5. data/Gemfile +4 -4
  6. data/LICENSE.txt +201 -201
  7. data/README.md +88 -88
  8. data/Rakefile +8 -8
  9. data/bin/wss_agent +13 -13
  10. data/lib/config/custom_default.yml +5 -5
  11. data/lib/config/default.yml +14 -14
  12. data/lib/data/ca-certificates.crt +4049 -4049
  13. data/lib/wss_agent.rb +50 -50
  14. data/lib/wss_agent/cli.rb +56 -56
  15. data/lib/wss_agent/client.rb +108 -108
  16. data/lib/wss_agent/configure.rb +115 -115
  17. data/lib/wss_agent/gem_sha1.rb +73 -73
  18. data/lib/wss_agent/project.rb +39 -39
  19. data/lib/wss_agent/response.rb +57 -57
  20. data/lib/wss_agent/response_inventory.rb +28 -28
  21. data/lib/wss_agent/response_policies.rb +77 -77
  22. data/lib/wss_agent/specifications.rb +202 -202
  23. data/lib/wss_agent/version.rb +4 -4
  24. data/spec/fixtures/vcr_cassettes/WssAgent_CLI/update/when_not_found_token/should_display_error_message.yml +2984 -2984
  25. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/response_should_be_success.yml +2984 -2984
  26. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/should_response_json_data.yml +2984 -2984
  27. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/should_return_message_response.yml +2984 -2984
  28. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_error/should_return_status_of_response.yml +2984 -2984
  29. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/response_should_be_success.yml +2984 -2984
  30. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/should_response_json_data.yml +2984 -2984
  31. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/should_return_message_response.yml +2984 -2984
  32. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/server_timeout/should_return_status_of_response.yml +2984 -2984
  33. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/response_should_be_success.yml +2984 -2984
  34. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/should_response_json_data.yml +2984 -2984
  35. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/should_return_message_response.yml +2984 -2984
  36. data/spec/fixtures/vcr_cassettes/WssAgent_Client/_update/success/should_return_status_of_response.yml +2984 -2984
  37. data/spec/fixtures/vcr_cassettes/WssAgent_Specifications/_check_policies/should_check_policies.yml +50 -50
  38. data/spec/fixtures/vcr_cassettes/WssAgent_Specifications/_update/should_update_list_gems_on_server.yml +50 -50
  39. data/spec/fixtures/vcr_cassettes/WssAgent_Specifications/_update/when_check_policies_is_true/and_check_policies_return_a_violation/should_not_update_inventory.yml +2984 -2984
  40. data/spec/fixtures/vcr_cassettes/WssAgent_Specifications/_update/when_check_policies_is_true/and_check_policies_returns_without_a_violation/should_update_inventory.yml +2984 -2984
  41. data/spec/spec_helper.rb +36 -36
  42. data/spec/support/exit_code_matches.rb +37 -37
  43. data/spec/wss_agent/cli_spec.rb +58 -58
  44. data/spec/wss_agent/client_spec.rb +151 -151
  45. data/spec/wss_agent/configure_spec.rb +180 -180
  46. data/spec/wss_agent/specifications_spec.rb +162 -162
  47. data/wss_agent.gemspec +38 -38
  48. metadata +3 -3
@@ -1,73 +1,73 @@
1
- require 'digest'
2
-
3
- module WssAgent
4
- class GemSha1
5
- attr_reader :spec
6
-
7
- def initialize(spec)
8
- @spec = spec
9
- check_version! unless @spec.version > Gem::Version.new('0')
10
- end
11
-
12
- # check version
13
- # if version isn't found get latest version
14
- #
15
- def check_version!
16
- conn = Faraday.new(url: 'https://rubygems.org') do |h|
17
- h.headers[:content_type] = 'application/x-www-form-urlencoded'
18
- h.request :url_encoded
19
- h.adapter :excon
20
- end
21
- response = conn.get("/api/v1/versions/#{spec.name}.json")
22
- versions = MultiJson.load(response.body)
23
- unless versions.detect { |j| j['number'] == spec.version }
24
- spec.version = versions.first['number']
25
- end
26
- rescue
27
-
28
- end
29
-
30
- def sha1
31
- case
32
- when spec.source.is_a?(Bundler::Source::Rubygems)
33
- path = spec.source.send(:cached_gem, spec).to_s
34
- Digest::SHA1.hexdigest(File.binread(path))
35
- when spec.source.is_a?(Bundler::Source::Git)
36
- # ???
37
- when spec.source.is_a?(Bundler::Source::Path)
38
- # ????
39
- when spec.source.nil?
40
- remote_file
41
- end
42
-
43
- rescue => ex
44
- WssAgent.logger.debug "#{ex.message}"
45
- WssAgent.logger.debug "#{spec}"
46
- remote_file
47
- end
48
-
49
- def remote_file_url
50
- URI("http://rubygems.org/gems/#{spec.file_name}")
51
- end
52
-
53
- # download gem from rubygems
54
- #
55
- def remote_file(retry_request = false)
56
- response = Net::HTTP.get_response(remote_file_url)
57
-
58
- case response.code
59
- when '200' # ok
60
- Digest::SHA1.hexdigest(response.body)
61
-
62
- when '302' # redirect
63
- response = Net::HTTP.get_response(URI(response['location']))
64
- return Digest::SHA1.hexdigest(response.body) if response.code == '200'
65
- else # gem isn't found
66
- ''
67
- end
68
-
69
- rescue Timeout::Error
70
- retry_request ? nil : remote_file(true)
71
- end
72
- end
73
- end
1
+ require 'digest'
2
+
3
+ module WssAgent
4
+ class GemSha1
5
+ attr_reader :spec
6
+
7
+ def initialize(spec)
8
+ @spec = spec
9
+ check_version! unless @spec.version > Gem::Version.new('0')
10
+ end
11
+
12
+ # check version
13
+ # if version isn't found get latest version
14
+ #
15
+ def check_version!
16
+ conn = Faraday.new(url: 'https://rubygems.org') do |h|
17
+ h.headers[:content_type] = 'application/x-www-form-urlencoded'
18
+ h.request :url_encoded
19
+ h.adapter :excon
20
+ end
21
+ response = conn.get("/api/v1/versions/#{spec.name}.json")
22
+ versions = MultiJson.load(response.body)
23
+ unless versions.detect { |j| j['number'] == spec.version }
24
+ spec.version = versions.first['number']
25
+ end
26
+ rescue
27
+
28
+ end
29
+
30
+ def sha1
31
+ case
32
+ when spec.source.is_a?(Bundler::Source::Rubygems)
33
+ path = spec.source.send(:cached_gem, spec).to_s
34
+ Digest::SHA1.hexdigest(File.binread(path))
35
+ when spec.source.is_a?(Bundler::Source::Git)
36
+ # ???
37
+ when spec.source.is_a?(Bundler::Source::Path)
38
+ # ????
39
+ when spec.source.nil?
40
+ remote_file
41
+ end
42
+
43
+ rescue => ex
44
+ WssAgent.logger.debug "#{ex.message}"
45
+ WssAgent.logger.debug "#{spec}"
46
+ remote_file
47
+ end
48
+
49
+ def remote_file_url
50
+ URI("http://rubygems.org/gems/#{spec.file_name}")
51
+ end
52
+
53
+ # download gem from rubygems
54
+ #
55
+ def remote_file(retry_request = false)
56
+ response = Net::HTTP.get_response(remote_file_url)
57
+
58
+ case response.code
59
+ when '200' # ok
60
+ Digest::SHA1.hexdigest(response.body)
61
+
62
+ when '302' # redirect
63
+ response = Net::HTTP.get_response(URI(response['location']))
64
+ return Digest::SHA1.hexdigest(response.body) if response.code == '200'
65
+ else # gem isn't found
66
+ ''
67
+ end
68
+
69
+ rescue Timeout::Error
70
+ retry_request ? nil : remote_file(true)
71
+ end
72
+ end
73
+ end
@@ -1,39 +1,39 @@
1
- module WssAgent
2
- class Project
3
- def project_name
4
- return gem.name if gem?
5
- return rails_app_name if rails?
6
- folder_name
7
- end
8
-
9
- def project_version
10
- gem? ? gem.version.to_s : ''
11
- end
12
-
13
- def folder_name
14
- Bundler.root.split.last.to_s
15
- end
16
-
17
- def gem?
18
- !Dir.glob(Bundler.root.join('*.gemspec')).last.nil?
19
- end
20
-
21
- def gem
22
- @gem ||= Gem::Specification.load(
23
- Dir.glob(Bundler.root.join('*.gemspec')).last
24
- )
25
- end
26
-
27
- def rails?
28
- File.exist?(rails_app_path)
29
- end
30
-
31
- def rails_app_name
32
- File.read(rails_app_path).match(/module (\w*)/)[1]
33
- end
34
-
35
- def rails_app_path
36
- Bundler.root.join('config', 'application.rb')
37
- end
38
- end
39
- end
1
+ module WssAgent
2
+ class Project
3
+ def project_name
4
+ return gem.name if gem?
5
+ return rails_app_name if rails?
6
+ folder_name
7
+ end
8
+
9
+ def project_version
10
+ gem? ? gem.version.to_s : ''
11
+ end
12
+
13
+ def folder_name
14
+ Bundler.root.split.last.to_s
15
+ end
16
+
17
+ def gem?
18
+ !Dir.glob(Bundler.root.join('*.gemspec')).last.nil?
19
+ end
20
+
21
+ def gem
22
+ @gem ||= Gem::Specification.load(
23
+ Dir.glob(Bundler.root.join('*.gemspec')).last
24
+ )
25
+ end
26
+
27
+ def rails?
28
+ File.exist?(rails_app_path)
29
+ end
30
+
31
+ def rails_app_name
32
+ File.read(rails_app_path).match(/module (\w*)/)[1]
33
+ end
34
+
35
+ def rails_app_path
36
+ Bundler.root.join('config', 'application.rb')
37
+ end
38
+ end
39
+ end
@@ -1,57 +1,57 @@
1
- module WssAgent
2
- class Response
3
- SUCCESS_STATUS = 1
4
- BAD_REQUEST_STATUS = 2
5
- SERVER_ERROR_STATUS = 3
6
-
7
- attr_reader :response, :status, :message, :response_data, :data
8
-
9
- def initialize(response)
10
- @response = response
11
- if response.is_a?(Faraday::Error::ClientError)
12
- parse_error
13
- else
14
- parse_response
15
- end
16
- end
17
-
18
- def parse_error
19
- @status = SERVER_ERROR_STATUS
20
- @message = response.message
21
- end
22
-
23
- def parse_response
24
- if response.success?
25
- begin
26
- @response_data = MultiJson.load(response.body)
27
- @status = @response_data['status'].to_i
28
- @message = @response_data['message']
29
- rescue
30
- @status = SERVER_ERROR_STATUS
31
- @message = response.body
32
- end
33
- else
34
- @status = SERVER_ERROR_STATUS
35
- @message = response.body
36
- end
37
- end
38
-
39
- def response_success?
40
- if response.is_a?(Faraday::Error::ClientError)
41
- false
42
- else
43
- response.success?
44
- end
45
- end
46
-
47
- def success?
48
- response_success? && status == SUCCESS_STATUS
49
- end
50
-
51
- def data
52
- @data ||= MultiJson.load(response_data['data'])
53
- rescue
54
- response_data && response_data.key?('data') ? response_data['data'] : nil
55
- end
56
- end
57
- end
1
+ module WssAgent
2
+ class Response
3
+ SUCCESS_STATUS = 1
4
+ BAD_REQUEST_STATUS = 2
5
+ SERVER_ERROR_STATUS = 3
6
+
7
+ attr_reader :response, :status, :message, :response_data, :data
8
+
9
+ def initialize(response)
10
+ @response = response
11
+ if response.is_a?(Faraday::Error::ClientError)
12
+ parse_error
13
+ else
14
+ parse_response
15
+ end
16
+ end
17
+
18
+ def parse_error
19
+ @status = SERVER_ERROR_STATUS
20
+ @message = response.message
21
+ end
22
+
23
+ def parse_response
24
+ if response.success?
25
+ begin
26
+ @response_data = MultiJson.load(response.body)
27
+ @status = @response_data['status'].to_i
28
+ @message = @response_data['message']
29
+ rescue
30
+ @status = SERVER_ERROR_STATUS
31
+ @message = response.body
32
+ end
33
+ else
34
+ @status = SERVER_ERROR_STATUS
35
+ @message = response.body
36
+ end
37
+ end
38
+
39
+ def response_success?
40
+ if response.is_a?(Faraday::Error::ClientError)
41
+ false
42
+ else
43
+ response.success?
44
+ end
45
+ end
46
+
47
+ def success?
48
+ response_success? && status == SUCCESS_STATUS
49
+ end
50
+
51
+ def data
52
+ @data ||= MultiJson.load(response_data['data'])
53
+ rescue
54
+ response_data && response_data.key?('data') ? response_data['data'] : nil
55
+ end
56
+ end
57
+ end
@@ -1,28 +1,28 @@
1
- module WssAgent
2
- class ResponseInventory < Response
3
- def message
4
- if success?
5
- @message = "White Source update results: \n"
6
- @message << " White Source organization: #{data['organization']} \n"
7
-
8
- if data['createdProjects'].empty?
9
- @message << " No new projects found \n"
10
- else
11
- @message << " #{data['createdProjects'].size} newly created projects: "
12
- @message << data['createdProjects'].join(' ')
13
- end
14
-
15
- if data['updatedProjects'].empty?
16
- @message << "\n No projects were updated \n"
17
- else
18
- @message << " #{data['updatedProjects'].size} existing projects were updated: "
19
- @message << data['updatedProjects'].join(' ')
20
- end
21
-
22
- @message
23
- else
24
- super
25
- end
26
- end
27
- end
28
- end
1
+ module WssAgent
2
+ class ResponseInventory < Response
3
+ def message
4
+ if success?
5
+ @message = "White Source update results: \n"
6
+ @message << " White Source organization: #{data['organization']} \n"
7
+
8
+ if data['createdProjects'].empty?
9
+ @message << " No new projects found \n"
10
+ else
11
+ @message << " #{data['createdProjects'].size} newly created projects: "
12
+ @message << data['createdProjects'].join(' ')
13
+ end
14
+
15
+ if data['updatedProjects'].empty?
16
+ @message << "\n No projects were updated \n"
17
+ else
18
+ @message << " #{data['updatedProjects'].size} existing projects were updated: "
19
+ @message << data['updatedProjects'].join(' ')
20
+ end
21
+
22
+ @message
23
+ else
24
+ super
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,77 +1,77 @@
1
- module WssAgent
2
- class ResponsePolicies < Response
3
- REJECT_ACTION = 'Reject'.freeze
4
-
5
- def parse_response
6
- if response.success?
7
- begin
8
- @response_data = MultiJson.load(response.body)
9
- @status = @response_data['status'].to_i
10
- @message = @response_data['message']
11
- check_new_projects
12
- check_existing_projects
13
- rescue
14
- @status = SERVER_ERROR_STATUS
15
- @message = response.body
16
- end
17
- else
18
- @status = SERVER_ERROR_STATUS
19
- @message = response.body
20
- end
21
- end
22
-
23
- def message
24
- if success?
25
- if policy_violations?
26
- @message = [
27
- 'Some dependencies do not conform with open source policies',
28
- 'List of violations:'
29
- ]
30
- @message << policy_violations.each_with_index.map { |j, i|
31
- "#{i + 1}. Package: #{j['resource']['displayName']} - #{j['policy']['displayName']}"
32
- }.join("\n")
33
- @message.join("\n")
34
- else
35
- 'All dependencies conform with open source policies'
36
- end
37
- end
38
- end
39
-
40
- def policy_violations
41
- @policy_violations || []
42
- end
43
-
44
- def policy_violations?
45
- !policy_violations.nil? &&
46
- !policy_violations.empty? &&
47
- policy_violations.size > 0
48
- end
49
-
50
- def check_existing_projects
51
- data['existingProjects'].each { |_proj_name, resource| check(resource) }
52
- end
53
-
54
- def check_new_projects
55
- data['newProjects'].each { |_proj_name, resource| check(resource) }
56
- end
57
-
58
- def add_resource(resource)
59
- @policy_violations ||= []
60
- @policy_violations << resource
61
- end
62
-
63
- def check(resource)
64
- if resource.key?('resource') && resource.key?('policy') &&
65
- (resource['policy']['actionType'] == REJECT_ACTION)
66
- add_resource(
67
- 'resource' => resource['resource'],
68
- 'policy' => resource['policy']
69
- )
70
- end
71
-
72
- if resource.key?('children') && resource['children'].is_a?(Array)
73
- resource['children'].each { |j| check(j) }
74
- end
75
- end
76
- end
77
- end
1
+ module WssAgent
2
+ class ResponsePolicies < Response
3
+ REJECT_ACTION = 'Reject'.freeze
4
+
5
+ def parse_response
6
+ if response.success?
7
+ begin
8
+ @response_data = MultiJson.load(response.body)
9
+ @status = @response_data['status'].to_i
10
+ @message = @response_data['message']
11
+ check_new_projects
12
+ check_existing_projects
13
+ rescue
14
+ @status = SERVER_ERROR_STATUS
15
+ @message = response.body
16
+ end
17
+ else
18
+ @status = SERVER_ERROR_STATUS
19
+ @message = response.body
20
+ end
21
+ end
22
+
23
+ def message
24
+ if success?
25
+ if policy_violations?
26
+ @message = [
27
+ 'Some dependencies do not conform with open source policies',
28
+ 'List of violations:'
29
+ ]
30
+ @message << policy_violations.each_with_index.map { |j, i|
31
+ "#{i + 1}. Package: #{j['resource']['displayName']} - #{j['policy']['displayName']}"
32
+ }.join("\n")
33
+ @message.join("\n")
34
+ else
35
+ 'All dependencies conform with open source policies'
36
+ end
37
+ end
38
+ end
39
+
40
+ def policy_violations
41
+ @policy_violations || []
42
+ end
43
+
44
+ def policy_violations?
45
+ !policy_violations.nil? &&
46
+ !policy_violations.empty? &&
47
+ policy_violations.size > 0
48
+ end
49
+
50
+ def check_existing_projects
51
+ data['existingProjects'].each { |_proj_name, resource| check(resource) }
52
+ end
53
+
54
+ def check_new_projects
55
+ data['newProjects'].each { |_proj_name, resource| check(resource) }
56
+ end
57
+
58
+ def add_resource(resource)
59
+ @policy_violations ||= []
60
+ @policy_violations << resource
61
+ end
62
+
63
+ def check(resource)
64
+ if resource.key?('resource') && resource.key?('policy') &&
65
+ (resource['policy']['actionType'] == REJECT_ACTION)
66
+ add_resource(
67
+ 'resource' => resource['resource'],
68
+ 'policy' => resource['policy']
69
+ )
70
+ end
71
+
72
+ if resource.key?('children') && resource['children'].is_a?(Array)
73
+ resource['children'].each { |j| check(j) }
74
+ end
75
+ end
76
+ end
77
+ end