wazuh-ruby-client 0.2.9 → 0.3.0

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
  SHA256:
3
- metadata.gz: d112a0cd50547b2e1884a85c76754903fe0e425b1eea395a88d2073ef940e484
4
- data.tar.gz: 875c1f5079579d1a29b9a34bff59a721c614447770696d8a7e50fd9efbf82383
3
+ metadata.gz: adc2a9b5045731781148915105090a022f56f6a0b9e5f829edbd858ba719cf35
4
+ data.tar.gz: 4737d13698d4983280f452d099285c4b5be49d5ee2a8e1e174c260b50ab44327
5
5
  SHA512:
6
- metadata.gz: cfe8b91a45b82511920cd43eb8ed477b2694560ef8d5215f93c4dc4d04792295336e9051d90d99c87d17d5e4611b7a2c52677670ef40da7358cd204af6a17582
7
- data.tar.gz: 112107a8acdc5f84714932e84c207d95c1b07a685a91ae83cabb5cbbdf5849f088e6e0d9cdb0c1fca9a1c96ad24b37abe1db26a0e67bfdc224783de9ce1390c6
6
+ metadata.gz: 9a2797197ba7db64967a51bfb4993ff42f4928cfd452a73b7629bd7c64e3c1d35f61157eb8191433fd7f21ddde6eefcecead1fd30e95109ac47423439fffd212
7
+ data.tar.gz: 12bdc3ff57b5f77b602d87889881f7d46868cf49cdeaa4ef92a0d408ddb8ca90b3a2f06bfed5707bbd8b70c6536db21ed617d1cfe36b6abd37a702d325344917
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  /.bundle/
2
+ /vendor
2
3
  /.yardoc
3
4
  /_yardoc/
4
5
  /coverage/
@@ -0,0 +1,19 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module ActiveResponse
6
+ include ::Wazuh::Api::Endpoints::ActiveResponse
7
+ def run_active_response_command(options = {})
8
+ query_options = {}
9
+ %w(agents_list pretty wait_for_complete).each do |c|
10
+ query_options[c.to_sym] = options.delete(c.to_sym)
11
+ end
12
+ put "/active-response", options, query_options
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,82 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Agents
6
+ include ::Wazuh::Api::Endpoints::Agents
7
+ def delete_agent(agent_ids, options = {})
8
+ delete "/agents", options.merge({ agents_list: agent_ids })
9
+ end
10
+
11
+ def remove_agents_of_group(ids, group)
12
+ delete "/agents/group", {group_id: group, agents_list: ids }
13
+ end
14
+
15
+ def delete_agent_by_group(ids)
16
+ delete '/agents/groups', {groups_list: ids}
17
+ end
18
+
19
+ def remove_group(group_id)
20
+ delete "/agents/groups", { groups_list: group_id }
21
+ end
22
+
23
+ def agent(agent_id, options = {})
24
+ get "/agents", options.merge({ agents_list: agent_id})
25
+ end
26
+
27
+ def upgrade_result_from_agent(agent_id, options = {})
28
+ get "/agents/upgrade_result", options.merge({ agents_list: agent_id})
29
+ end
30
+
31
+ def groups(options = {})
32
+ get '/groups', options
33
+ end
34
+
35
+ def agents_by_group(group_id, options = {})
36
+ offset_request('get', "/groups", options.merge({groups_list: group_id}))
37
+ end
38
+
39
+ def group_configuration(group_id, options = {})
40
+ get "/groups/#{group_id}/configuration", options
41
+ end
42
+
43
+ def group_files(group_id, options = {})
44
+ get "/groups/#{group_id}/files", options
45
+ end
46
+
47
+ def get_file_in_group(group_id, filename, options = {})
48
+ get "groups/#{group_id}/files/#{filename}", options
49
+ end
50
+
51
+ def agent_by_name(agent_name, options = {})
52
+ get "/agents", options.merge({name: agent_name})
53
+ end
54
+
55
+ def agent_summary
56
+ get "/agents/summary/status"
57
+ end
58
+
59
+ def add_agents_to_group(ids, group_id)
60
+ put "/agents/group", {group_id: group_id, agents_list: ids}
61
+ end
62
+
63
+ def agent_upgrade(agent_id, options = {})
64
+ put "/agents/upgrade", options.merge({agents_list: agent_id})
65
+ end
66
+
67
+ def agent_upgrade_custom(agent_id, options = {})
68
+ put "/agents/upgrade_custom", options.merge({agents_list: agent_id})
69
+ end
70
+
71
+ def add_agent_quick(agent_name)
72
+ post "/agents/insert/quick/", {}, {agent_name: agent_name}
73
+ end
74
+
75
+ def create_group(group_id)
76
+ post "/agents/groups", {group_id: group_id}
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,14 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Cache
6
+ include ::Wazuh::Api::Endpoints::Cache
7
+ def cache_config
8
+ get "/cluster/api/config"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Ciscat
6
+ include ::Wazuh::Api::Endpoints::Ciscat
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Cluster
6
+ include ::Wazuh::Api::Endpoints::Cluster
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Decoders
6
+ include ::Wazuh::Api::Endpoints::Decoders
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Experimental
6
+ include ::Wazuh::Api::Endpoints::Experimental
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Lists
6
+ include ::Wazuh::Api::Endpoints::Lists
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Manager
6
+ include ::Wazuh::Api::Endpoints::Manager
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Rootcheck
6
+ include ::Wazuh::Api::Endpoints::Rootcheck
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Rules
6
+ include ::Wazuh::Api::Endpoints::Rules
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module SecurityConfigurationAssessment
6
+ include ::Wazuh::Api::Endpoints::SecurityConfigurationAssessment
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Summary
6
+ include ::Wazuh::Api::Endpoints::Summary
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Syscheck
6
+ include ::Wazuh::Api::Endpoints::Syscheck
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Wazuh
2
+ module Api
3
+ module Endpoints
4
+ module V4
5
+ module Syscollector
6
+ include ::Wazuh::Api::Endpoints::Syscollector
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ require_relative 'v4/active_response'
2
+ require_relative 'v4/agents'
3
+ require_relative 'v4/cache'
4
+ require_relative 'v4/ciscat'
5
+ require_relative 'v4/cluster'
6
+ require_relative 'v4/decoders'
7
+ require_relative 'v4/experimental'
8
+ require_relative 'v4/lists'
9
+ require_relative 'v4/manager'
10
+ require_relative 'v4/rootcheck'
11
+ require_relative 'v4/rules'
12
+ require_relative 'v4/security_configuration_assessment'
13
+ require_relative 'v4/summary'
14
+ require_relative 'v4/syscheck'
15
+ require_relative 'v4/syscollector'
16
+
17
+
18
+ module Wazuh
19
+ module Api
20
+ module Endpoints
21
+ module V4
22
+ include ActiveResponse
23
+ include Agents
24
+ include Cache
25
+ include Ciscat
26
+ include Cluster
27
+ include Decoders
28
+ include Experimental
29
+ include Lists
30
+ include Manager
31
+ include Rootcheck
32
+ include Rules
33
+ include Summary
34
+ include Syscheck
35
+ include Syscollector
36
+ include SecurityConfigurationAssessment
37
+ end
38
+ end
39
+ end
40
+ end
@@ -13,6 +13,7 @@ require_relative 'endpoints/security_configuration_assessment'
13
13
  require_relative 'endpoints/summary'
14
14
  require_relative 'endpoints/syscheck'
15
15
  require_relative 'endpoints/syscollector'
16
+ require_relative 'endpoints/v4'
16
17
 
17
18
  module Wazuh
18
19
  module Api
data/lib/wazuh/client.rb CHANGED
@@ -2,7 +2,6 @@ module Wazuh
2
2
  class Client
3
3
  include Sawyer::Connection
4
4
  include Sawyer::Request
5
- include Api::Endpoints
6
5
 
7
6
  attr_accessor(*Config::ATTRIBUTES)
8
7
 
@@ -11,6 +10,14 @@ module Wazuh
11
10
  send("#{key}=", options[key] || Wazuh.config.send(key))
12
11
  end
13
12
  @logger ||= Wazuh::Config.logger || Wazuh::Logger.default
13
+ case api_version
14
+ when 3
15
+ extend Api::Endpoints
16
+ when 4
17
+ extend Api::Endpoints::V4
18
+ else
19
+ raise "unsupported api version #{api_version}"
20
+ end
14
21
  end
15
22
 
16
23
  class << self
data/lib/wazuh/config.rb CHANGED
@@ -14,6 +14,7 @@ module Wazuh
14
14
  logger
15
15
  endpoint
16
16
  ignore_env_proxy
17
+ api_version
17
18
  ].freeze
18
19
 
19
20
  attr_accessor(*Config::ATTRIBUTES)
@@ -29,6 +30,7 @@ module Wazuh
29
30
  self.verify_ssl = true
30
31
  self.logger = nil
31
32
  self.ignore_env_proxy = false
33
+ self.api_version = 3
32
34
  end
33
35
  end
34
36
 
@@ -2,7 +2,6 @@ module Wazuh
2
2
  module Sawyer
3
3
  module Connection
4
4
  private
5
-
6
5
  def connection
7
6
  options = {
8
7
  headers: {
@@ -16,21 +15,27 @@ module Wazuh
16
15
  options[:ssl].merge!({ client_cert: client_cert, client_key: client_key }) if client_cert || client_key
17
16
  options[:ssl][:ca_file] = ca_file if ca_file
18
17
 
19
- if basic_user || basic_password
20
- authorization_header = "Basic " + Base64.encode64(basic_user + ':' + basic_password).strip
21
- options[:headers].merge!({'Authorization' => authorization_header})
22
- end
23
-
24
18
  options[:ssl].merge!({ verify: false }) unless verify_ssl
25
19
 
26
20
  opts = {
27
21
  :links_parser => ::Sawyer::LinkParsers::Simple.new
28
22
  }
29
23
 
30
- opts[:faraday] = ::Faraday.new(options)
24
+ case api_version
25
+ when 3
26
+ if basic_user || basic_password
27
+ options[:headers].merge!({'Authorization' => "Basic " + Base64.encode64(basic_user + ':' + basic_password).strip})
28
+ end
29
+ when 4
30
+ raise "user and password is required on v4 api" if !basic_user || !basic_password
31
+ opts[:faraday] = ::Faraday.new(options) do |conn|
32
+ conn.request :authorization, 'Bearer', -> { Token.jwt(endpoint, options, basic_user, basic_password) }
33
+ end
34
+ end
35
+
31
36
  opts[:faraday].proxy = nil if ignore_env_proxy
32
37
 
33
- ::Sawyer::Agent.new(endpoint, opts)
38
+ conn = ::Sawyer::Agent.new(endpoint, opts)
34
39
  end
35
40
  end
36
41
  end
@@ -32,13 +32,13 @@ module Wazuh
32
32
 
33
33
  private
34
34
 
35
- def request(method, path, options)
35
+ def request(method, path, options, query_options={})
36
36
  response = case method
37
37
  when :get, :delete
38
38
  connection.call(method, URI::Parser.new.escape(path), nil, {query: options})
39
39
  when :post, :put
40
40
  data = options unless options.empty?
41
- connection.call(method, URI::Parser.new.escape(path), data)
41
+ connection.call(method, URI::Parser.new.escape(path), data, {query: query_options})
42
42
  end
43
43
 
44
44
  return response.data.data if response.status == 200
@@ -0,0 +1,20 @@
1
+ module Wazuh
2
+ module Sawyer
3
+ module Connection
4
+ class Token
5
+ def self.jwt(endpoint, options, basic_user, basic_password)
6
+ if !@_token || (@_exp && @_exp -3 <= Time.now.to_i)
7
+ options[:url] = endpoint
8
+ options[:headers].merge!({'Authorization' => "Basic " + Base64.encode64(basic_user + ':' + basic_password).strip})
9
+
10
+ token = ::Faraday.new(options) {|f| f.response :json }.get('/security/user/authenticate').body['data']['token']
11
+ @_exp = ::JWT.decode(token, nil, false).first['exp'].to_i
12
+ ::JWT.decode(token, nil, false).first
13
+ @_token = token
14
+ end
15
+ @_token
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
data/lib/wazuh/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Wazuh
3
- VERSION = '0.2.9'
3
+ VERSION = '0.3.0'
4
4
  end
@@ -1,3 +1,3 @@
1
1
  module WazuhRubyClient
2
- VERSION = "0.2.9"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -6,8 +6,11 @@ require 'logger'
6
6
  require 'base64'
7
7
  require 'faraday'
8
8
  require 'sawyer'
9
+ require 'jwt'
10
+ require 'faraday_middleware'
9
11
 
10
12
  require_relative 'wazuh/config'
13
+ require_relative 'wazuh/sawyer/token'
11
14
  require_relative 'wazuh/sawyer/connection'
12
15
  require_relative 'wazuh/sawyer/request'
13
16
  require_relative 'wazuh/api/endpoints'
@@ -34,14 +34,17 @@ Gem::Specification.new do |spec|
34
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
35
  spec.require_paths = ["lib"]
36
36
 
37
- spec.add_development_dependency "bundler", "~> 2.1.4"
37
+ spec.add_development_dependency "bundler", "~> 2.2"
38
38
  spec.add_development_dependency "rake", ">= 12.3.3"
39
39
  spec.add_development_dependency "rspec", "~> 3.0"
40
40
  spec.add_development_dependency "vcr"
41
41
  spec.add_development_dependency "webmock"
42
42
  spec.add_development_dependency "pry"
43
43
  spec.add_development_dependency "pry-byebug"
44
+ spec.add_development_dependency "timecop"
44
45
 
45
46
  spec.add_dependency 'faraday'
47
+ spec.add_dependency 'faraday_middleware'
46
48
  spec.add_dependency 'sawyer'
49
+ spec.add_dependency 'jwt'
47
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wazuh-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mrtc0
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-23 00:00:00.000000000 Z
11
+ date: 2021-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.4
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.4
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: timecop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: faraday
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,20 @@ dependencies:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: faraday_middleware
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: sawyer
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +164,20 @@ dependencies:
136
164
  - - ">="
137
165
  - !ruby/object:Gem::Version
138
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: jwt
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
139
181
  description: Wazuh API client for Ruby
140
182
  email:
141
183
  - mrtc0@ssrf.in
@@ -211,6 +253,22 @@ files:
211
253
  - lib/wazuh/api/endpoints/summary.rb
212
254
  - lib/wazuh/api/endpoints/syscheck.rb
213
255
  - lib/wazuh/api/endpoints/syscollector.rb
256
+ - lib/wazuh/api/endpoints/v4.rb
257
+ - lib/wazuh/api/endpoints/v4/active_response.rb
258
+ - lib/wazuh/api/endpoints/v4/agents.rb
259
+ - lib/wazuh/api/endpoints/v4/cache.rb
260
+ - lib/wazuh/api/endpoints/v4/ciscat.rb
261
+ - lib/wazuh/api/endpoints/v4/cluster.rb
262
+ - lib/wazuh/api/endpoints/v4/decoders.rb
263
+ - lib/wazuh/api/endpoints/v4/experimental.rb
264
+ - lib/wazuh/api/endpoints/v4/lists.rb
265
+ - lib/wazuh/api/endpoints/v4/manager.rb
266
+ - lib/wazuh/api/endpoints/v4/rootcheck.rb
267
+ - lib/wazuh/api/endpoints/v4/rules.rb
268
+ - lib/wazuh/api/endpoints/v4/security_configuration_assessment.rb
269
+ - lib/wazuh/api/endpoints/v4/summary.rb
270
+ - lib/wazuh/api/endpoints/v4/syscheck.rb
271
+ - lib/wazuh/api/endpoints/v4/syscollector.rb
214
272
  - lib/wazuh/api/error.rb
215
273
  - lib/wazuh/api/errors/wazuh_error.rb
216
274
  - lib/wazuh/client.rb
@@ -218,6 +276,7 @@ files:
218
276
  - lib/wazuh/logger.rb
219
277
  - lib/wazuh/sawyer/connection.rb
220
278
  - lib/wazuh/sawyer/request.rb
279
+ - lib/wazuh/sawyer/token.rb
221
280
  - lib/wazuh/version.rb
222
281
  - lib/wazuh_ruby_client.rb
223
282
  - wazuh-ruby-client.gemspec
@@ -227,7 +286,7 @@ metadata:
227
286
  homepage_uri: https://github.com/mrtc0/wazuh-ruby-client
228
287
  source_code_uri: https://github.com/mrtc0/wazuh-ruby-client
229
288
  changelog_uri: https://github.com/mrtc0/wazuh-ruby-client/blob/master/CHANGELOG.md
230
- post_install_message:
289
+ post_install_message:
231
290
  rdoc_options: []
232
291
  require_paths:
233
292
  - lib
@@ -242,8 +301,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
301
  - !ruby/object:Gem::Version
243
302
  version: '0'
244
303
  requirements: []
245
- rubygems_version: 3.0.3
246
- signing_key:
304
+ rubygems_version: 3.1.4
305
+ signing_key:
247
306
  specification_version: 4
248
307
  summary: Wazuh API client for Ruby
249
308
  test_files: []