ratonvirus-resty 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de801c65869a22224c37180d25d454fabb3a6f92ce20f0c35c519f20cf8bebc8
4
+ data.tar.gz: e71e339fa4ceff836d5e5c48a67bc3520cdc35137ed9cbfbea3bda3319b5e866
5
+ SHA512:
6
+ metadata.gz: 30beb2cfa79f106da76939e0407cbf81061d6d496617e996736b8073b58285d69b52425d7c4cc2e4c5ff9cb643beb48e0e61224690e071b5f50b9ec880f4a20d
7
+ data.tar.gz: a1abb2e01e4d7db7efb899f7a86932f1f9d7f92151ba96488877f3819db8064e1ab14650836f82714a49bd926b647b243f969b7ef3594eb55cac4cabba86a6d8
@@ -0,0 +1,40 @@
1
+ # Ratonvirus::Resty
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ratonvirus/resty`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ratonvirus-resty'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ratonvirus-resty
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ratonvirus-resty.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,15 @@
1
+ module Ratonvirus
2
+ module Resty
3
+ module Generators
4
+ class InstallGenerator > Rails::Generators::Base
5
+
6
+ desc 'Generates the initializer'
7
+
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ def generate_initializer
11
+ template 'initializer.rb', 'config/initializers/ratonvirus_resty.rb'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ Ratonvirus::Resty.configure do |config|
2
+ # Sets the base url for api requests
3
+ #
4
+ # default: config.base_url = ENV.fetch('RESTY_SERVICE_URL') { 'http://localhost:9000/scan' }
5
+ #
6
+ config.base_url = ENV.fetch('RESTY_SERVICE_URL', 'http://localhost:9000/scan')
7
+
8
+ # Optional sets the username for api requests
9
+ #
10
+ # config.username = ENV.fetch('RESTY_USER', nil)
11
+ #
12
+ config.username = ENV.fetch('RESTY_USER', nil)
13
+ # Optional sets the password for api requests
14
+ #
15
+ # config.password = ENV.fetch('RESTY_PASSWORD', nil)
16
+ #
17
+ config.password = ENV.fetch('RESTY_PASSWORD', nil)
18
+
19
+
20
+ # Optional sets the proxy url
21
+ #
22
+ # config.proxy_url = ENV.fetch('PROXY_URL', nil)
23
+ #
24
+ config.proxy_url = ENV.fetch('PROXY_URL', nil)
25
+ end
@@ -0,0 +1,17 @@
1
+ require "ratonvirus/resty/version"
2
+ require "ratonvirus/resty/configuration"
3
+ require "faraday"
4
+ require "mimemagic"
5
+ require 'active_support'
6
+
7
+ require_relative "scanner/resty"
8
+ require_relative "resty/configuration"
9
+
10
+ module Ratonvirus
11
+ autoload :AntivirusCheckService, 'ratonvirus/services/antivirus_check_service'
12
+
13
+ module Resty
14
+ extend Configuration
15
+ class Error < StandardError; end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'active_support/core_ext/module/delegation'
2
+ require 'active_support/core_ext/module/attribute_accessors'
3
+
4
+ module Ratonvirus
5
+ module Resty
6
+ module Configuration
7
+ def configure
8
+ yield self
9
+ end
10
+
11
+ mattr_accessor(:service_url) { ENV.fetch('RESTY_SERVICE_URL', 'http://localhost:9000/scan') }
12
+ mattr_accessor(:username) { ENV.fetch('RESTY_USER', nil) }
13
+ mattr_accessor(:password) { ENV.fetch('RESTY_PASSWORD', nil) }
14
+ mattr_accessor(:proxy_url) { ENV.fetch('PROXY_URL') { nil } }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Ratonvirus
2
+ module Resty
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ require 'ratonvirus'
2
+
3
+ module Ratonvirus
4
+ module Scanner
5
+ class Resty < Ratonvirus::Scanner::Base
6
+ class << self
7
+ def executable?
8
+ AntivirusCheckService.installed?
9
+ end
10
+ end
11
+
12
+ protected
13
+
14
+ def run_scan(path)
15
+ if File.file?(path)
16
+ result = AntivirusCheckService.new(path).call
17
+ if result.virus?
18
+ errors << :antivirus_virus_deteced
19
+ end
20
+ else
21
+ errors << :antivirus_file_not_found
22
+ end
23
+ rescue StandardError
24
+ errors << :antivirus_client_error
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,90 @@
1
+ module Ratonvirus
2
+ class AntivirusCheckService
3
+ class Result
4
+ attr_accessor :parsed_response
5
+
6
+ def virus?
7
+ parsed_response.any? && parsed_response['status'] != 'OK'
8
+ end
9
+ end
10
+
11
+ attr_accessor :file_path, :result
12
+
13
+ def initialize(path)
14
+ @file_path = path
15
+
16
+ @logger = Logger.new(STDOUT)
17
+ @result = Result.new
18
+ end
19
+
20
+ def installed?
21
+ true
22
+ end
23
+
24
+ def call
25
+ perform_request
26
+ @result
27
+ end
28
+
29
+ private
30
+
31
+ def perform_request
32
+ @logger.debug { "Performing request to #{base_url}" }
33
+ begin
34
+ @response = connection.post(base_url, { file: initialize_upload_file })
35
+ @result.parsed_response = parse_response
36
+ unless @response.success?
37
+ @logger.debug { "API request respond with status code #{@response.status}: #{parse_response}"}
38
+ end
39
+ rescue => exception
40
+ @logger.debug { "There was an error performing the API request: #{exception.message}"}
41
+ end
42
+ end
43
+
44
+ def parse_response
45
+ @logger.debug { "Parsing response #{@response}"}
46
+ JSON.parse(@response.body).transform_keys(&:downcase)
47
+ end
48
+
49
+ def connection
50
+ @connection ||= initialize_connection
51
+ end
52
+
53
+ def request_headers
54
+ { 'Content-Type' => 'application/json;charset=UTF-8' }
55
+ end
56
+
57
+ def initialize_connection
58
+ Faraday.new(base_url, proxy: proxy) do |f|
59
+ f.request :url_encoded
60
+ f.request :multipart
61
+ f.request :basic_auth, Ratonvirus::Resty::Configuration.username, Ratonvirus::Resty::Configuration.password if request_use_basic_auth?
62
+ f.adapter :net_http
63
+ end
64
+ end
65
+
66
+ def initialize_upload_file
67
+ Faraday::UploadIO.new(file_path, mime_type)
68
+ end
69
+
70
+ def mime_type
71
+ MimeMagic.by_path(file_path)
72
+ end
73
+
74
+ def base_url
75
+ Ratonvirus::Resty::Configuration.service_url
76
+ end
77
+
78
+ def request_path
79
+ "#{base_url}"
80
+ end
81
+
82
+ def request_use_basic_auth?
83
+ Ratonvirus::Resty::Configuration.username && Ratonvirus::Resty::Configuration.password
84
+ end
85
+
86
+ def proxy
87
+ Ratonvirus::Resty::Configuration.proxy_url
88
+ end
89
+ end
90
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ratonvirus-resty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eugen Müller
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: mimemagic
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: ratonvirus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.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.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: webmock
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.13.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.13.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.18.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.18.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.86.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.86.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.40'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.40'
139
+ description: Ratonviurs scanner based on a ClamAv Rest service. Expect a Restservice
140
+ based on https://github.com/ajilaag/clamav-rest
141
+ email:
142
+ - eugen.mueller@enermarket.de
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - README.md
148
+ - lib/generators/ratonviurs/resty/install_generator.rb
149
+ - lib/generators/ratonviurs/resty/templates/initializer.rb
150
+ - lib/ratonvirus/resty.rb
151
+ - lib/ratonvirus/resty/configuration.rb
152
+ - lib/ratonvirus/resty/version.rb
153
+ - lib/ratonvirus/scanner/resty.rb
154
+ - lib/ratonvirus/services/antivirus_check_service.rb
155
+ homepage: https://github.com/enermarket/ratonvirus-resty.git
156
+ licenses:
157
+ - MIT
158
+ metadata:
159
+ homepage_uri: https://github.com/enermarket/ratonvirus-resty.git
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: 2.3.0
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubygems_version: 3.1.2
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Restfull scanner for Ratonvirus
179
+ test_files: []