Class: WssAgent::Client
- Inherits:
-
Object
- Object
- WssAgent::Client
- Defined in:
- lib/wss_agent/client.rb
Overview
Client class
Constant Summary collapse
- POLICY_TYPES =
{ basic: 'CHECK_POLICIES', compliance: 'CHECK_POLICY_COMPLIANCE' }.freeze
- UPDATE_TYPE =
'UPDATE'.freeze
- REQUEST_TIMEOUT =
120
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
- #check_policies(gem_list, options = {}) ⇒ Object
- #diff(gem_list) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #payload(gem_list, options = {}) ⇒ Object
- #request(gem_list, options = {}) ⇒ Object
- #update(gem_list) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wss_agent/client.rb', line 14 def initialize @connection ||= Faraday.new() do |h| h.port = Configure.port h.headers[:content_type] = 'application/x-www-form-urlencoded' h.request :url_encoded h.adapter :excon end Excon.defaults[:ciphers] = 'DEFAULT' if defined?(JRuby) @connection end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/wss_agent/client.rb', line 5 def connection @connection end |
Instance Method Details
#check_policies(gem_list, options = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/wss_agent/client.rb', line 55 def check_policies(gem_list, = {}) = if Configure['force_check_all_dependencies'] || ['force'] { type: POLICY_TYPES[:compliance], forceCheckAllDependencies: true } else { type: POLICY_TYPES[:basic], forceCheckAllDependencies: false } end ResponsePolicies.new(request(gem_list, )) end |
#diff(gem_list) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/wss_agent/client.rb', line 26 def diff(gem_list) diff_data = { 'coordinates' => Configure.coordinates, 'dependencies' => gem_list } if Configure['project_token'] diff_data['projectToken'] = Configure['project_token'] end MultiJson.dump([diff_data]) end |
#payload(gem_list, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/wss_agent/client.rb', line 37 def payload(gem_list, = {}) = { agent: Configure['agent'], agentVersion: Configure['agent_version'], token: Configure.token, product: Configure['product'].to_s, productVersion: Configure['product_version'].to_s, timeStamp: Time.now.to_i, diff: diff(gem_list) } [:userKey] = Configure.user_key if Configure.user_key? .merge() end |
#request(gem_list, options = {}) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/wss_agent/client.rb', line 66 def request(gem_list, = {}) WssAgent.logger.debug "request params: #{payload(gem_list, )}" connection.post(Configure.api_path, payload(gem_list, )) rescue Faraday::Error::ClientError => ex ex end |
#update(gem_list) ⇒ Object
51 52 53 |
# File 'lib/wss_agent/client.rb', line 51 def update(gem_list) ResponseInventory.new(request(gem_list, type: UPDATE_TYPE)) end |