wazuh-rb 0.2.0
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 +7 -0
- data/.gitignore +3 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +62 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/lib/wazuh/client/agent.rb +10 -0
- data/lib/wazuh/client.rb +13 -0
- data/lib/wazuh/configuration.rb +36 -0
- data/lib/wazuh/connection.rb +51 -0
- data/lib/wazuh/error.rb +52 -0
- data/lib/wazuh/response/raise_error.rb +15 -0
- data/lib/wazuh/version.rb +3 -0
- data/lib/wazuh.rb +24 -0
- data/wazuh-rb.gemspec +27 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 020ae6347449308a9a65fdbcc3430aad7de6d61f90965638140a32b7a20472ca
|
4
|
+
data.tar.gz: 341a7b23c03bf367197e7ec90273c981a0f4de5131b48dd38af188f32e655774
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f89e90e0f8fc6b6802967d7dbe6b6b0e53d9dbb362b6b2130ba68b79e2c8b9c3efaa28d867b82b0f2a297eeb2217cf9ce94338ff8b75dbc9fc4e803938ac7cd
|
7
|
+
data.tar.gz: ef16883389552af02bd29de7123ab408df9732e7241d334a790855e211f033b9f89b6ec0ce16087266e8f7a2e661c113e4247d708969bd6247b89da1865e6ef3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wazuh-rb (0.1.0)
|
5
|
+
faraday
|
6
|
+
faraday_middleware
|
7
|
+
thor
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.7.0)
|
13
|
+
public_suffix (>= 2.0.2, < 5.0)
|
14
|
+
coderay (1.1.2)
|
15
|
+
crack (0.4.3)
|
16
|
+
safe_yaml (~> 1.0.0)
|
17
|
+
diff-lcs (1.3)
|
18
|
+
faraday (0.17.1)
|
19
|
+
multipart-post (>= 1.2, < 3)
|
20
|
+
faraday_middleware (0.13.1)
|
21
|
+
faraday (>= 0.7.4, < 1.0)
|
22
|
+
hashdiff (1.0.0)
|
23
|
+
method_source (0.9.2)
|
24
|
+
multipart-post (2.1.1)
|
25
|
+
pry (0.12.2)
|
26
|
+
coderay (~> 1.1.0)
|
27
|
+
method_source (~> 0.9.0)
|
28
|
+
public_suffix (4.0.1)
|
29
|
+
rake (13.0.1)
|
30
|
+
rspec (3.9.0)
|
31
|
+
rspec-core (~> 3.9.0)
|
32
|
+
rspec-expectations (~> 3.9.0)
|
33
|
+
rspec-mocks (~> 3.9.0)
|
34
|
+
rspec-core (3.9.0)
|
35
|
+
rspec-support (~> 3.9.0)
|
36
|
+
rspec-expectations (3.9.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.9.0)
|
39
|
+
rspec-mocks (3.9.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.9.0)
|
42
|
+
rspec-support (3.9.0)
|
43
|
+
safe_yaml (1.0.5)
|
44
|
+
thor (0.20.3)
|
45
|
+
webmock (3.7.6)
|
46
|
+
addressable (>= 2.3.6)
|
47
|
+
crack (>= 0.3.2)
|
48
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
bundler
|
55
|
+
pry
|
56
|
+
rake
|
57
|
+
rspec
|
58
|
+
wazuh-rb!
|
59
|
+
webmock
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
2.0.2
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# wazuh-rb
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'wazuh.rb'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install wazuh.rb
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```rb
|
20
|
+
Wazuh.configure do |config|
|
21
|
+
config.api_endpoint = "your endpoint"
|
22
|
+
end
|
23
|
+
|
24
|
+
agents = Wazuh.agents
|
25
|
+
```
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/pyama86/wazuh.rb/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/wazuh/client.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'wazuh/configuration'
|
2
|
+
require 'wazuh/connection'
|
3
|
+
require 'wazuh/client/agent'
|
4
|
+
require 'wazuh/client/agent'
|
5
|
+
require 'wazuh/response/raise_error'
|
6
|
+
|
7
|
+
module Wazuh
|
8
|
+
class Client
|
9
|
+
include Configuration
|
10
|
+
include Connection
|
11
|
+
include Agents
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Wazuh
|
2
|
+
module Configuration
|
3
|
+
def config
|
4
|
+
@config ||= Config.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def configure
|
8
|
+
yield config
|
9
|
+
end
|
10
|
+
|
11
|
+
class Config
|
12
|
+
attr_accessor :api_endpoint, :http_accept, :params_encoder, :proxy, :request, :user_agent, :ca_file, :client_key, :client_cert
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@http_accept = 'application/json'
|
16
|
+
@user_agent = "Wazuh.rb Ruby Gem #{Wazuh::VERSION}"
|
17
|
+
@params_encoder = Faraday::FlatParamsEncoder
|
18
|
+
@proxy = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def request
|
22
|
+
{
|
23
|
+
params_encoder: params_encoder
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def http_request_headers
|
28
|
+
headers = {
|
29
|
+
'Accept' => http_accept,
|
30
|
+
'User-Agent' => user_agent,
|
31
|
+
}
|
32
|
+
headers.select {|_, v| !!v}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
module Wazuh
|
6
|
+
module Connection
|
7
|
+
def get(url, params = {})
|
8
|
+
connection.get(url, params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def post(url, params = {})
|
12
|
+
connection.post(url) do |req|
|
13
|
+
req.headers['Content-Type'] = 'application/json'
|
14
|
+
req.body = params.to_json
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def put(url, params = {})
|
19
|
+
connection.put(url) do |req|
|
20
|
+
req.headers['Content-Type'] = 'application/json'
|
21
|
+
req.body = params.to_json
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete(url)
|
26
|
+
connection.delete(url) do |req|
|
27
|
+
req.headers['Content-Type'] = 'application/json'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def request(method, url, params = {})
|
32
|
+
connection.send(method, url, params)
|
33
|
+
end
|
34
|
+
|
35
|
+
def connection
|
36
|
+
options = { url: config.api_endpoint, headers: config.http_request_headers, request: config.request, proxy: config.proxy }
|
37
|
+
options[:ssl] = {
|
38
|
+
ca_file: config.ca_file,
|
39
|
+
client_key: ::OpenSSL::PKey::RSA.new(File.read(config.client_key)),
|
40
|
+
client_cert: ::OpenSSL::X509::Certificate.new(File.read(config.client_cert))
|
41
|
+
} if config.client_cert && config.client_key && config.ca_file
|
42
|
+
|
43
|
+
@connection ||= Faraday.new(options) do |faraday|
|
44
|
+
faraday.use Wazuh::Response::RaiseError
|
45
|
+
faraday.use Faraday::Response::Logger if ENV['DEBUG'] == '1'
|
46
|
+
faraday.use FaradayMiddleware::ParseJson
|
47
|
+
faraday.adapter Faraday.default_adapter
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/wazuh/error.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Wazuh
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def self.from_response(response)
|
6
|
+
status = response.status.to_i
|
7
|
+
|
8
|
+
klass = case status
|
9
|
+
when 400 then BadRequest
|
10
|
+
when 400..499 then ClientError
|
11
|
+
when 500 then InternalServerError
|
12
|
+
when 500..599 then ServerError
|
13
|
+
end
|
14
|
+
|
15
|
+
klass.new(response) if klass
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(response)
|
19
|
+
@response = response
|
20
|
+
super(build_error_message)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def build_error_message
|
26
|
+
return nil if @response.nil?
|
27
|
+
|
28
|
+
message = "#{@response.method.to_s.upcase} "
|
29
|
+
message << "#{@response.url.to_s}: "
|
30
|
+
message << "#{@response.status}"
|
31
|
+
message << " - #{response_error}>" if response_error
|
32
|
+
message
|
33
|
+
end
|
34
|
+
|
35
|
+
def response_error
|
36
|
+
data = @response.body
|
37
|
+
data.error if data.respond_to?(:error) && data.error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class ClientError < Error
|
42
|
+
end
|
43
|
+
|
44
|
+
class BadRequest < ClientError
|
45
|
+
end
|
46
|
+
|
47
|
+
class ServerError < Error
|
48
|
+
end
|
49
|
+
|
50
|
+
class InternalServerError < ServerError
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'wazuh/error'
|
3
|
+
|
4
|
+
module Wazuh
|
5
|
+
module Response
|
6
|
+
class RaiseError < Faraday::Response::Middleware
|
7
|
+
private
|
8
|
+
|
9
|
+
def on_complete(response)
|
10
|
+
error = Wazuh::Error.from_response(response)
|
11
|
+
raise error if error
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/wazuh.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "wazuh/version"
|
2
|
+
require "wazuh/client"
|
3
|
+
|
4
|
+
module Wazuh
|
5
|
+
class << self
|
6
|
+
private
|
7
|
+
|
8
|
+
def respond_to_missing?(method_name, include_private=false)
|
9
|
+
client.respond_to?(method_name, include_private)
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(method_name, *args, &block)
|
13
|
+
if client.respond_to?(method_name)
|
14
|
+
client.send(method_name, *args, &block)
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def client
|
21
|
+
@client ||= Client.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/wazuh-rb.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wazuh/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wazuh-rb"
|
8
|
+
spec.version = Wazuh::VERSION
|
9
|
+
spec.authors = ["pyama86"]
|
10
|
+
spec.email = ["www.kazu.com@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Wazuh client for Ruby.}
|
13
|
+
spec.description = %q{Wazuh client for Ruby.}
|
14
|
+
spec.homepage = "https://github.com/pyama86/wazuh.rb"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "bin"
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "thor"
|
22
|
+
spec.add_dependency "faraday"
|
23
|
+
spec.add_dependency "faraday_middleware"
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wazuh-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pyama86
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Wazuh client for Ruby.
|
98
|
+
email:
|
99
|
+
- www.kazu.com@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/wazuh.rb
|
110
|
+
- lib/wazuh/client.rb
|
111
|
+
- lib/wazuh/client/agent.rb
|
112
|
+
- lib/wazuh/configuration.rb
|
113
|
+
- lib/wazuh/connection.rb
|
114
|
+
- lib/wazuh/error.rb
|
115
|
+
- lib/wazuh/response/raise_error.rb
|
116
|
+
- lib/wazuh/version.rb
|
117
|
+
- wazuh-rb.gemspec
|
118
|
+
homepage: https://github.com/pyama86/wazuh.rb
|
119
|
+
licenses: []
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubygems_version: 3.0.6
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Wazuh client for Ruby.
|
140
|
+
test_files: []
|