virus-scanner 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.ruby-version +1 -0
- data/Gemfile +9 -0
- data/LICENSE.md +7 -0
- data/README.md +30 -0
- data/Rakefile +11 -0
- data/lib/virus_scanner/errors.rb +43 -0
- data/lib/virus_scanner/file.rb +21 -0
- data/lib/virus_scanner/http.rb +37 -0
- data/lib/virus_scanner/version.rb +3 -0
- data/lib/virus_scanner.rb +9 -0
- data/test/file_test.rb +28 -0
- data/test/http_test.rb +41 -0
- data/test/test_helper.rb +6 -0
- data/vs-ruby.gemspec +25 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 03b4ec9633dbafbb3b4bed8c86b03c488c121555
|
4
|
+
data.tar.gz: d79420981386d30c6263a89634b03663f63d2dc1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 523e8135e360df0639ea19ef59dca182aa13eba6eb849408dd7eb3c5becafacb95910e3887fbeda05bb1f3f6dd541a962cda261e5fe0b1199702742b09968edd
|
7
|
+
data.tar.gz: b447be15eef98ed818d80c2c055f5f17bbd3acdcef882ac4479840a642c718d7f71b4069f31da2ab27c2479b946bb54381a0ba3b7f300d58089405932dfaf9f7
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.0
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2015 BitZesty Ltd.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# vs-ruby
|
2
|
+
This is ruby gem for communication with Virus Scanner API.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
To use it in your project, add following line to your Gemfile
|
7
|
+
|
8
|
+
`gem vs-ruby`
|
9
|
+
|
10
|
+
and then run
|
11
|
+
|
12
|
+
`bundle`
|
13
|
+
|
14
|
+
or install it by hand
|
15
|
+
|
16
|
+
`gem install vs-ruby`
|
17
|
+
|
18
|
+
It uses faraday as HTTP middleware so you may use any HTTP backend you want. Net:HTTP is default one.
|
19
|
+
|
20
|
+
(TODO: add configuration option to change HTTP request)
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
`VirusScanner::File` class has two methods:
|
25
|
+
|
26
|
+
* `check_from_url` which accepts URL to remote file as argument and returns scan job status
|
27
|
+
* `check_status` which accepts job UUID as argument and returns information about job status
|
28
|
+
|
29
|
+
(c) 2015 BitZesty Ltd.
|
30
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module VirusScanner
|
2
|
+
class Error < StandardError
|
3
|
+
def initialize(statement)
|
4
|
+
if statement.is_a?(Exception)
|
5
|
+
@error = statement
|
6
|
+
else
|
7
|
+
@message = statement
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def message
|
12
|
+
@message || "#{@error.class} (wrapped in #{self.class}) - #{@error.message}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def backtrace
|
16
|
+
if @error
|
17
|
+
error_backtrace = ["--- Backtrace from #{@error.class} ---"] + (@error.backtrace || [])
|
18
|
+
wrapper_backtrace = ["--- Backtrace from #{self.class} ---"] + (super || [])
|
19
|
+
error_backtrace + wrapper_backtrace
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect
|
26
|
+
if @error
|
27
|
+
"#{error.inspect} (wrapped in a #{self.class})"
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
if @error
|
35
|
+
"#{@error.class} (wrapped in a #{self.class}) - #{@error}"
|
36
|
+
else
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class HTTPError < Error; end
|
43
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VirusScanner
|
2
|
+
class File
|
3
|
+
attr_accessor :body
|
4
|
+
def self.scan_url(url)
|
5
|
+
# Pass URL to file to check to the HTTP requests handler
|
6
|
+
body = handler.post(url)
|
7
|
+
|
8
|
+
body
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.check_status(uuid)
|
12
|
+
body = handler.get(uuid)
|
13
|
+
|
14
|
+
body
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.handler
|
18
|
+
VirusScanner::HTTP.new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module VirusScanner
|
2
|
+
class HTTP
|
3
|
+
attr_accessor :url, :options, :method
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@conn = ::Faraday.new(url: ENV["VIRUS_SCANNER_API_URL"]) do |c|
|
7
|
+
c.request :url_encoded
|
8
|
+
c.response :json, content_type: /\bjson$/
|
9
|
+
c.adapter ::Faraday.default_adapter
|
10
|
+
c.headers = { "X-Auth-Token" => ENV["VIRUS_SCANNER_API_KEY"] }
|
11
|
+
end
|
12
|
+
rescue VirusScanner::HttpError => e
|
13
|
+
handle_exception(e)
|
14
|
+
end
|
15
|
+
|
16
|
+
def post(url)
|
17
|
+
response = @conn.post "/scan", url: url
|
18
|
+
response.body
|
19
|
+
rescue VirusScanner::Error => e
|
20
|
+
handle_exception(e)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get(uuid)
|
24
|
+
response = @conn.get "/status/#{uuid}"
|
25
|
+
response.body
|
26
|
+
rescue VirusScanner::Error => e
|
27
|
+
handle_exception(e)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def handle_exception(e)
|
33
|
+
puts e.message
|
34
|
+
puts e.backtrace.inspect
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/test/file_test.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "./test_helper.rb"
|
2
|
+
|
3
|
+
describe VirusScanner::File do
|
4
|
+
describe "#check_from_url" do
|
5
|
+
it "returns info about scan job" do
|
6
|
+
response = { "status" => "scanning", "id" => "de401fdf-08b0-44a8-810b-20794c5c98c7" }
|
7
|
+
VirusScanner::HTTP.any_instance.stubs(:post).returns(response)
|
8
|
+
assert_equal(VirusScanner::File.scan_url("url-to-suspected-file"),
|
9
|
+
"status" => "scanning",
|
10
|
+
"id" => "de401fdf-08b0-44a8-810b-20794c5c98c7")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#check_status" do
|
15
|
+
it "returns OK when file is clean" do
|
16
|
+
response = {
|
17
|
+
"status" => "OK",
|
18
|
+
"uuid" => "de401fdf-08b0-44a8-810b-20794c5c98c7",
|
19
|
+
"md5" => "md5 hash" }
|
20
|
+
VirusScanner::HTTP.any_instance.stubs(:get).returns(response)
|
21
|
+
|
22
|
+
assert_equal(VirusScanner::File.check_status("de401fdf-08b0-44a8-810b-20794c5c98c7"),
|
23
|
+
"status" => "OK",
|
24
|
+
"uuid" => "de401fdf-08b0-44a8-810b-20794c5c98c7",
|
25
|
+
"md5" => "md5 hash")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/test/http_test.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative "./test_helper.rb"
|
2
|
+
|
3
|
+
ENV["VIRUS_SCANNER_API_URL"] = "http://localhost:3000"
|
4
|
+
|
5
|
+
describe VirusScanner::HTTP do
|
6
|
+
describe "#post" do
|
7
|
+
it "returns id of job if posted with success" do
|
8
|
+
# stub POST request for providing URL to files for scan
|
9
|
+
stub_request(:post, "localhost:3000/scan").to_return(
|
10
|
+
body:
|
11
|
+
{ id: "de401fdf-08b0-44a8-810b-20794c5c98c7" }.to_json)
|
12
|
+
|
13
|
+
# check if stubbed URL provides id for scan job
|
14
|
+
assert_includes(VirusScanner::HTTP.new.post("url"), "de401fdf-08b0-44a8-810b-20794c5c98c7")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#get" do
|
19
|
+
it "returns status of a job for provided uuid" do
|
20
|
+
stub_request(:get, "localhost:3000/status/de401fdf-08b0-44a8-810b-20794c5c98c7").to_return(
|
21
|
+
body:
|
22
|
+
{ id: "de401fdf-08b0-44a8-810b-20794c5c98c7",
|
23
|
+
result: "------------ SCAN SUMMARY -----------",
|
24
|
+
md5: "69630e4574ec6798239b091cda43dca0",
|
25
|
+
status: "error" }.to_json)
|
26
|
+
|
27
|
+
assert_includes(
|
28
|
+
VirusScanner::HTTP.new.get("de401fdf-08b0-44a8-810b-20794c5c98c7"),
|
29
|
+
"error")
|
30
|
+
assert_includes(
|
31
|
+
VirusScanner::HTTP.new.get("de401fdf-08b0-44a8-810b-20794c5c98c7"),
|
32
|
+
"SCAN SUMMARY")
|
33
|
+
assert_includes(
|
34
|
+
VirusScanner::HTTP.new.get("de401fdf-08b0-44a8-810b-20794c5c98c7"),
|
35
|
+
"69630e4574ec6798239b091cda43dca0")
|
36
|
+
assert_includes(
|
37
|
+
VirusScanner::HTTP.new.get("de401fdf-08b0-44a8-810b-20794c5c98c7"),
|
38
|
+
"de401fdf-08b0-44a8-810b-20794c5c98c7")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/test/test_helper.rb
ADDED
data/vs-ruby.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "virus_scanner/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "virus-scanner"
|
8
|
+
s.version = VirusScanner::VERSION
|
9
|
+
s.authors = ["BitZesty Ltd"]
|
10
|
+
s.email = ["info@bitzesty.com"]
|
11
|
+
s.description = "API client for virus-scanner service"
|
12
|
+
s.summary = "API client for virus-scanner service"
|
13
|
+
s.homepage = "https://github.com/bitzesty/vs-ruby"
|
14
|
+
s.license = "MIT"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split($/)
|
17
|
+
s.executables = s.files.grep(%q{^bin/}) { |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency "faraday"
|
21
|
+
s.add_dependency "faraday_middleware"
|
22
|
+
|
23
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
s.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: virus-scanner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- BitZesty Ltd
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-27 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: '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_middleware
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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
|
+
description: API client for virus-scanner service
|
70
|
+
email:
|
71
|
+
- info@bitzesty.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.md
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/virus_scanner.rb
|
83
|
+
- lib/virus_scanner/errors.rb
|
84
|
+
- lib/virus_scanner/file.rb
|
85
|
+
- lib/virus_scanner/http.rb
|
86
|
+
- lib/virus_scanner/version.rb
|
87
|
+
- test/file_test.rb
|
88
|
+
- test/http_test.rb
|
89
|
+
- test/test_helper.rb
|
90
|
+
- vs-ruby.gemspec
|
91
|
+
homepage: https://github.com/bitzesty/vs-ruby
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.5
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: API client for virus-scanner service
|
115
|
+
test_files: []
|