wss_agent 0.0.25 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8191195b5796d173199be590828ba7dce4855b46
4
- data.tar.gz: dc035cfa389f3822c3b6b02ad83c7ad7a7a3e3e1
3
+ metadata.gz: 37746ad31b6f21f4c7f708caa09fa025c3c7dfc2
4
+ data.tar.gz: 7296602265f771c66dfbda7d779609b28d8c0cbe
5
5
  SHA512:
6
- metadata.gz: 191ca92f09a3b21a36d80d5a8f01f7c07a325c4b9941883b0b4434e4b8771ea9d5d5a62b90a061b77ba9e923390db40ceab70838b0e9d9ad56053fa8db500020
7
- data.tar.gz: 90fa398623cddb7e79e6d1034e0478f06787ca8211e3604fd42a2ad3663233e411e08c4d340c871c7d2fc52696adf7007eeebd50f9395250aa57404169fdb575
6
+ metadata.gz: affacdbb4903237066485beed2500020fa2861196425ea2e79a19e8f1bcaab29842910b8e3530f8d06af24ae804de2896e0fee0fa778784b5f5e33385f484499
7
+ data.tar.gz: 393b302d06d46a81947a4c389896cb0414352c8d04742969ab245aeda6cc7f91c6edae2834cd3a0482830c033f0cf61f3e59033d95d0c75ee1484181d615168e
data/README.md CHANGED
@@ -47,6 +47,13 @@ Commands:
47
47
  ```bash
48
48
  $ wss_agent update
49
49
  ```
50
+
51
+ ###### force update
52
+ ```bash
53
+ $ wss_agent update --force-update
54
+ ```
55
+ or add 'force_update: true' to 'wss_agent.yml'
56
+
50
57
  ### 5) checking dependencies that they conforms with company policy.
51
58
  ```bash
52
59
  $ wss_agent check_policies
@@ -1,7 +1,7 @@
1
1
  require 'thor'
2
2
  require 'net/http'
3
3
  require 'awesome_print'
4
- require 'yaml'
4
+ require 'psych'
5
5
  require 'multi_json'
6
6
  require 'faraday'
7
7
  require 'faraday_middleware'
@@ -21,6 +21,12 @@ module WssAgent
21
21
  DEFAULT_CA_BUNDLE_PATH = File.dirname(__FILE__) + '/data/ca-certificates.crt'
22
22
 
23
23
  class WssAgentError < StandardError
24
+ URL_INVALID = 'Api url is invalid. Could you please check url in wss_agent.yml'.freeze
25
+ CANNOT_FIND_TOKEN = "Can't find Token, please add your Whitesource API token in the wss_agent.yml file".freeze
26
+ CANNOT_FIND_URL = "Can't find the url, please add your Whitesource url destination in the wss_agent.yml file.".freeze
27
+ INVALID_CONFIG_FORMAT = 'Problem reading wss_agent.yml, please check the file is a valid YAML'.freeze
28
+ NOT_FOUND_CONFIGFILE = "Config file isn't exist. Could you please run 'wss_agent config' before.".freeze
29
+
24
30
  def self.status_code(code)
25
31
  define_method(:status_code) { code }
26
32
  end
@@ -37,6 +43,8 @@ module WssAgent
37
43
  end
38
44
 
39
45
  def self.enable_debug!
40
- @logger ||= Yell.new STDOUT, level: [:debug, :info, :warn, :error, :fatal, :unknown]
46
+ @logger ||= Yell.new(
47
+ STDOUT, level: [:debug, :info, :warn, :error, :fatal, :unknown]
48
+ )
41
49
  end
42
50
  end
@@ -29,6 +29,7 @@ module WssAgent
29
29
  method_option :excludes, type: :string
30
30
  method_option :verbose, aliases: '-v', desc: 'Be verbose'
31
31
  method_option :force, type: :boolean, aliases: '-f', desc: 'Force Check All Dependencies'
32
+ method_option :'force-update', type: :boolean, desc: 'Force Update'
32
33
  def update
33
34
  WssAgent.enable_debug! if options['verbose']
34
35
  result = Specifications.update(options)
@@ -1,4 +1,6 @@
1
1
  module WssAgent
2
+ # Client class
3
+ #
2
4
  class Client
3
5
  attr_accessor :connection
4
6
  POLICY_TYPES = {
@@ -16,10 +18,8 @@ module WssAgent
16
18
  h.request :url_encoded
17
19
  h.adapter :excon
18
20
  end
21
+ Excon.defaults[:ciphers] = 'DEFAULT' if defined?(JRuby)
19
22
 
20
- if defined?(JRuby)
21
- Excon.defaults[:ciphers] = 'DEFAULT'
22
- end
23
23
  @connection
24
24
  end
25
25
 
@@ -52,7 +52,7 @@ module WssAgent
52
52
 
53
53
  def check_policies(gem_list, options = {})
54
54
  request_options =
55
- if WssAgent::Configure['force_check_all_dependencies'] || options['force']
55
+ if Configure['force_check_all_dependencies'] || options['force']
56
56
  { type: POLICY_TYPES[:compliance], forceCheckAllDependencies: true }
57
57
  else
58
58
  { type: POLICY_TYPES[:basic], forceCheckAllDependencies: false }
@@ -64,7 +64,7 @@ module WssAgent
64
64
  def request(gem_list, options = {})
65
65
  WssAgent.logger.debug "request params: #{payload(gem_list, options)}"
66
66
 
67
- connection.post(WssAgent::Configure.api_path, payload(gem_list, options))
67
+ connection.post(Configure.api_path, payload(gem_list, options))
68
68
  rescue Faraday::Error::ClientError => ex
69
69
  ex
70
70
  end
@@ -74,18 +74,16 @@ module WssAgent
74
74
  def connection_options
75
75
  @connection_options ||
76
76
  begin
77
-
78
77
  @connection_options = {
79
- url: Configure.url,
80
- request: { timeout: REQUEST_TIMEOUT }
78
+ url: Configure.url, request: { timeout: REQUEST_TIMEOUT }
81
79
  }
82
- if Configure.ssl?
83
- @connection_options[:ssl] = {
84
- ca_file: WssAgent::DEFAULT_CA_BUNDLE_PATH
85
- }
86
- end
80
+ @connection_options[:ssl] = ssl_options if Configure.ssl?
87
81
  end
88
82
  @connection_options
89
83
  end
84
+
85
+ def ssl_options
86
+ { ca_file: WssAgent::DEFAULT_CA_BUNDLE_PATH }
87
+ end
90
88
  end
91
89
  end
@@ -10,11 +10,16 @@ module WssAgent
10
10
 
11
11
  class << self
12
12
  def default_path
13
- File.join(File.expand_path('../..', __FILE__), 'config', DEFAULT_CONFIG_FILE)
13
+ File.join(
14
+ File.expand_path('../..', __FILE__), 'config', DEFAULT_CONFIG_FILE
15
+ )
14
16
  end
15
17
 
16
18
  def custom_default_path
17
- File.join(File.expand_path('../..', __FILE__), 'config', CUSTOM_DEFAULT_CONFIG_FILE)
19
+ File.join(
20
+ File.expand_path('../..', __FILE__), 'config',
21
+ CUSTOM_DEFAULT_CONFIG_FILE
22
+ )
18
23
  end
19
24
 
20
25
  def exist_default_config?
@@ -22,7 +27,7 @@ module WssAgent
22
27
  end
23
28
 
24
29
  def default
25
- exist_default_config? ? YAML.load(File.read(default_path)) : {}
30
+ exist_default_config? ? Psych.safe_load(File.read(default_path)) : {}
26
31
  end
27
32
 
28
33
  def current_path
@@ -31,13 +36,13 @@ module WssAgent
31
36
 
32
37
  def current
33
38
  unless File.exist?(current_path)
34
- return raise NotFoundConfigFile, "Config file isn't exist. Could you please run 'wss_agent config' before."
39
+ return raise NotFoundConfigFile, WssAgentError::NOT_FOUND_CONFIGFILE
35
40
  end
36
41
 
37
- @current_config = YAML.load(File.read(current_path))
42
+ @current_config = Psych.safe_load(File.read(current_path))
38
43
 
39
- unless !!@current_config
40
- return raise InvalidConfigFile, 'Problem reading wss_agent.yml, please check the file is a valid YAML'
44
+ unless @current_config
45
+ return raise InvalidConfigFile, WssAgentError::INVALID_CONFIG_FORMAT
41
46
  end
42
47
 
43
48
  default.merge(@current_config)
@@ -46,12 +51,12 @@ module WssAgent
46
51
  def uri
47
52
  @url = current['url']
48
53
  if @url.nil? || @url == ''
49
- raise ApiUrlNotFound, "Can't find the url, please add your Whitesource url destination in the wss_agent.yml file."
54
+ raise ApiUrlNotFound, WssAgentError::CANNOT_FIND_URL
50
55
  end
51
56
  URI(@url)
52
57
 
53
58
  rescue URI::Error
54
- raise ApiUrlInvalid, 'Api url is invalid. Could you please check url in wss_agent.yml'
59
+ raise ApiUrlInvalid, WssAgentError::URL_INVALID
55
60
  end
56
61
 
57
62
  def port
@@ -74,31 +79,29 @@ module WssAgent
74
79
  end
75
80
 
76
81
  def token
77
- if current['token'].nil? || (current['token'] == '') || (current['token'] == default['token'])
78
- raise TokenNotFound, "Can't find Token, please add your Whitesource API token in the wss_agent.yml file"
82
+ if current['token'].nil? || (current['token'] == '') ||
83
+ (current['token'] == default['token'])
84
+ raise TokenNotFound, WssAgentError::CANNOT_FIND_TOKEN
79
85
  else
80
86
  current['token']
81
87
  end
82
88
  end
83
89
 
90
+ def project_meta
91
+ @project_meta ||= WssAgent::Project.new
92
+ end
93
+
84
94
  def coordinates
85
95
  return {} unless current['project_token'].to_s.strip.empty?
86
-
87
- project_meta = WssAgent::Project.new
88
-
89
96
  coordinates_config = current['coordinates']
90
97
  coordinates_artifact_id = coordinates_config['artifact_id']
91
98
  coordinates_version = coordinates_config['version']
92
-
93
99
  if coordinates_artifact_id.to_s.strip.empty?
94
100
  coordinates_artifact_id = project_meta.project_name
95
101
  coordinates_version = project_meta.project_version
96
102
  end
97
-
98
- {
99
- 'artifactId' => coordinates_artifact_id,
100
- 'version' => coordinates_version
101
- }
103
+ { 'artifactId' => coordinates_artifact_id,
104
+ 'version' => coordinates_version }
102
105
  end
103
106
  end
104
107
  end
@@ -1,6 +1,5 @@
1
1
  module WssAgent
2
2
  class Project
3
-
4
3
  def project_name
5
4
  return gem.name if gem?
6
5
  return rails_app_name if rails?
@@ -16,7 +16,7 @@ module WssAgent
16
16
  if data['updatedProjects'].empty?
17
17
  @message << "\n No projects were updated \n"
18
18
  else
19
- @message << " #{data['updatedProjects'].size} existing projects were updated: "
19
+ @message << " #{data['updatedProjects'].size} existing projects were updated: "
20
20
  @message << data['updatedProjects'].join(' ')
21
21
  end
22
22
 
@@ -28,7 +28,7 @@ module WssAgent
28
28
  'List of violations:'
29
29
  ]
30
30
  @message << policy_violations.each_with_index.map { |j, i|
31
- "#{i+1}. Package: #{j['resource']['displayName']} - #{j['policy']['displayName']}"
31
+ "#{i + 1}. Package: #{j['resource']['displayName']} - #{j['policy']['displayName']}"
32
32
  }.join("\n")
33
33
  @message.join("\n")
34
34
  else
@@ -42,24 +42,25 @@ module WssAgent
42
42
  end
43
43
  private :check_policy?
44
44
 
45
+ def force_update?(options = {})
46
+ options['force-update'] ||
47
+ WssAgent::Configure['force_update']
48
+ end
49
+
50
+ private :force_update?
51
+
45
52
  # Send gem list to server
46
53
  #
47
54
  # @param (see Specifications#specs)
48
55
  def update(options = {})
49
- wss_client = WssAgent::Client.new
50
-
51
- if check_policy?(options)
52
- policy_results = wss_client.check_policies(
53
- WssAgent::Specifications.list(options),
54
- options
55
- )
56
- if policy_results.success? && policy_results.policy_violations?
57
- puts policy_results.message
58
- return Struct.new(:status) { def success?; status; end; }.new(false)
59
- end
56
+ result = check_policies_for_update(options)
57
+ if !force_update?(options) && (result.status == :reject)
58
+ return Struct.new(:status) do
59
+ alias_method :success?, :status
60
+ end.new(false)
60
61
  end
61
62
 
62
-
63
+ wss_client = WssAgent::Client.new
63
64
  result = wss_client.update(WssAgent::Specifications.list(options))
64
65
  if result.success?
65
66
  WssAgent.logger.debug result.data
@@ -72,6 +73,22 @@ module WssAgent
72
73
  result
73
74
  end
74
75
 
76
+ # Check policies before update
77
+ #
78
+ # @param (see Specifications#specs)
79
+ def check_policies_for_update(options = {})
80
+ return Struct.new(:status).new(:ok) unless check_policy?(options)
81
+ wss_client = WssAgent::Client.new
82
+ policy_results = wss_client.check_policies(
83
+ WssAgent::Specifications.list(options), options
84
+ )
85
+ if policy_results.success? && policy_results.policy_violations?
86
+ puts policy_results.message
87
+ return Struct.new(:status, :msg).new(:reject, policy_results.message)
88
+ end
89
+ Struct.new(:status).new(:ok)
90
+ end
91
+
75
92
  # checking dependencies that they conforms with company policy.
76
93
  #
77
94
  # @param (see Specifications#specs)
@@ -1,4 +1,4 @@
1
1
  module WssAgent
2
- VERSION = '0.0.25'.freeze
2
+ VERSION = '0.0.26'.freeze
3
3
  NAME = 'wss_agent'.freeze
4
4
  end
@@ -67,6 +67,24 @@ describe WssAgent::Configure do
67
67
  end
68
68
  end
69
69
 
70
+ describe '.force_update' do
71
+ it 'set value to false' do
72
+ expect(WssAgent::Configure['force_update']).to be_falsey
73
+ end
74
+ it 'set value to true' do
75
+ allow(
76
+ WssAgent::Configure
77
+ ).to receive_messages(current: { 'force_update' => true })
78
+ expect(WssAgent::Configure['force_update']).to be_truthy
79
+ end
80
+
81
+ context 'default value' do
82
+ it 'should be false' do
83
+ expect(WssAgent::Configure['force_update']).to be_falsey
84
+ end
85
+ end
86
+ end
87
+
70
88
  describe '.url' do
71
89
  context 'when url is empty' do
72
90
  before do
@@ -18,6 +18,7 @@ describe WssAgent::Specifications, vcr: true do
18
18
  }
19
19
  ]
20
20
  }
21
+ let(:default_config) { WssAgent::Configure.default }
21
22
 
22
23
  describe '.check_policies' do
23
24
  let(:success_response) {
@@ -67,12 +68,10 @@ describe WssAgent::Specifications, vcr: true do
67
68
  end
68
69
 
69
70
  context 'when check_policies is true' do
70
-
71
- before {
71
+ before do
72
72
  allow(WssAgent::Client).to receive(:new).and_return(wss_client)
73
- allow(WssAgent::Configure).to receive(:current)
74
- .and_return(WssAgent::Configure.default.merge({'check_policies' => true}))
75
- }
73
+ allow(WssAgent::Configure).to receive(:current).and_return(default_config.merge('check_policies' => true))
74
+ end
76
75
  context 'and check policies return a violation' do
77
76
  it 'should not update inventory' do
78
77
  allow(policy_success_response).to receive(:policy_violations?).and_return(true)
@@ -81,6 +80,25 @@ describe WssAgent::Specifications, vcr: true do
81
80
  res = WssAgent::Specifications.update
82
81
  expect(res.success?).to be false
83
82
  end
83
+ context 'and force_update set true' do
84
+ before do
85
+ allow(WssAgent::Client).to receive(:new).and_return(wss_client)
86
+ allow(WssAgent::Configure).to receive(:current).and_return(
87
+ default_config.merge(
88
+ 'check_policies' => true,
89
+ 'force_update' => true
90
+ )
91
+ )
92
+ end
93
+ it 'should be update if update_force is true' do
94
+ allow(WssAgent::Specifications).to receive(:list).and_return(gem_list)
95
+ allow(policy_success_response).to receive(:policy_violations?).and_return(true)
96
+ expect(wss_client).to receive(:check_policies).and_return(policy_success_response)
97
+ expect(wss_client).to receive(:update).and_return(success_response)
98
+ res = WssAgent::Specifications.update
99
+ expect(res.success?).to be_truthy
100
+ end
101
+ end
84
102
  end
85
103
 
86
104
  context 'and check policies returns without a violation' do
@@ -100,7 +118,7 @@ describe WssAgent::Specifications, vcr: true do
100
118
  before {
101
119
  allow(WssAgent::Client).to receive(:new).and_return(wss_client)
102
120
  allow(WssAgent::Configure).to receive(:current)
103
- .and_return(WssAgent::Configure.default.merge({'check_policies' => false}))
121
+ .and_return(default_config.merge({'check_policies' => false}))
104
122
  }
105
123
  it 'should update inventory' do
106
124
  allow(WssAgent::Specifications).to receive(:list).and_return(gem_list)
@@ -31,8 +31,9 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency 'thor', '~> 0.19', '>= 0.19.1'
32
32
  spec.add_dependency 'yell', '~> 2.0', '>= 2.0.5'
33
33
  spec.add_dependency 'excon', '~> 0.45'
34
- spec.add_dependency 'faraday', '~> 0.9', '>= 0.9.1'
35
- spec.add_dependency 'faraday_middleware', '~> 0.10'
34
+ spec.add_dependency 'faraday', '~> 0.12'
35
+ spec.add_dependency 'faraday_middleware', '~> 0.11.0.1'
36
36
  spec.add_dependency 'awesome_print', '~> 1.6', '>= 1.6.1'
37
37
  spec.add_dependency 'multi_json', '~> 1.12', '>= 1.12.1'
38
+ spec.add_dependency 'psych', '~> 2.2', '>= 2.2.4'
38
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wss_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim Pechnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-09 00:00:00.000000000 Z
11
+ date: 2017-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -188,34 +188,28 @@ dependencies:
188
188
  requirements:
189
189
  - - "~>"
190
190
  - !ruby/object:Gem::Version
191
- version: '0.9'
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: 0.9.1
191
+ version: '0.12'
195
192
  type: :runtime
196
193
  prerelease: false
197
194
  version_requirements: !ruby/object:Gem::Requirement
198
195
  requirements:
199
196
  - - "~>"
200
197
  - !ruby/object:Gem::Version
201
- version: '0.9'
202
- - - ">="
203
- - !ruby/object:Gem::Version
204
- version: 0.9.1
198
+ version: '0.12'
205
199
  - !ruby/object:Gem::Dependency
206
200
  name: faraday_middleware
207
201
  requirement: !ruby/object:Gem::Requirement
208
202
  requirements:
209
203
  - - "~>"
210
204
  - !ruby/object:Gem::Version
211
- version: '0.10'
205
+ version: 0.11.0.1
212
206
  type: :runtime
213
207
  prerelease: false
214
208
  version_requirements: !ruby/object:Gem::Requirement
215
209
  requirements:
216
210
  - - "~>"
217
211
  - !ruby/object:Gem::Version
218
- version: '0.10'
212
+ version: 0.11.0.1
219
213
  - !ruby/object:Gem::Dependency
220
214
  name: awesome_print
221
215
  requirement: !ruby/object:Gem::Requirement
@@ -256,6 +250,26 @@ dependencies:
256
250
  - - ">="
257
251
  - !ruby/object:Gem::Version
258
252
  version: 1.12.1
253
+ - !ruby/object:Gem::Dependency
254
+ name: psych
255
+ requirement: !ruby/object:Gem::Requirement
256
+ requirements:
257
+ - - "~>"
258
+ - !ruby/object:Gem::Version
259
+ version: '2.2'
260
+ - - ">="
261
+ - !ruby/object:Gem::Version
262
+ version: 2.2.4
263
+ type: :runtime
264
+ prerelease: false
265
+ version_requirements: !ruby/object:Gem::Requirement
266
+ requirements:
267
+ - - "~>"
268
+ - !ruby/object:Gem::Version
269
+ version: '2.2'
270
+ - - ">="
271
+ - !ruby/object:Gem::Version
272
+ version: 2.2.4
259
273
  description: White Source agent to sync gems
260
274
  email:
261
275
  - parallel588@gmail.com