vigilion 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.ruby-version +1 -0
- data/Gemfile +9 -0
- data/LICENSE.md +7 -0
- data/README.md +35 -0
- data/Rakefile +11 -0
- data/lib/vigilion.rb +28 -0
- data/lib/vigilion/configuration.rb +18 -0
- data/lib/vigilion/errors.rb +4 -0
- data/lib/vigilion/http.rb +75 -0
- data/lib/vigilion/version.rb +3 -0
- data/test/configuration_test.rb +17 -0
- data/test/http_test.rb +88 -0
- data/test/sample_file.txt +1 -0
- data/test/test_helper.rb +6 -0
- data/vigilion.gemspec +25 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 10b4c38751fd1fd34676937ab9a7653bdb003ebf
|
4
|
+
data.tar.gz: 53e88cbd504435d9f552128072a3ebf6fc442ae0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2e8b3cd387102ba0a0aeece76a7f5c33b276f41a000182279cdb7d248329d847dd8802c0b4fc7970d154be866eac2d6199a3c0170009133777777ea0f5c7885
|
7
|
+
data.tar.gz: 7122e42286d3cd6b20aa93f118846b6c9f5358a39370eba469218f5059fdffd5410d4eb26c5dbebcdb0eab6be3bb6ec4535566ed621fe4b3c65d639375fa0c13
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2015 Bit Zesty 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,35 @@
|
|
1
|
+
# Vigilion
|
2
|
+
|
3
|
+
This Ruby gem is for integrating with the [Vigilion Anti-Virus & Malware file scanning service](https://www.vigilion.com/).
|
4
|
+
|
5
|
+
If you are using Rails, you should use our [Rails gem](
|
6
|
+
https://github.com/vigilion/vigilion-rails), which includes
|
7
|
+
integration with Active Record and Action Controller.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add vigilion to your `Gemfile` and then run `bundle install`
|
12
|
+
|
13
|
+
`gem 'vigilion'`
|
14
|
+
|
15
|
+
or install it by hand
|
16
|
+
|
17
|
+
`gem install vigilion`
|
18
|
+
|
19
|
+
This gem uses faraday as HTTP middleware, so you may use any HTTP
|
20
|
+
backend you want, `Net:HTTP` is the default.
|
21
|
+
|
22
|
+
## Configuration
|
23
|
+
|
24
|
+
You need to configure the client before making any API requests e.g. in an initializer.
|
25
|
+
|
26
|
+
```
|
27
|
+
Vigilion.configure do |config|
|
28
|
+
config.access_key_id = ENV['VIGILION_API_KEY']
|
29
|
+
config.secret_access_key = ENV['VIGILION_API_SECRET']
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Vigilion documentation [https://vigilion.readme.io/docs/ruby](https://vigilion.readme.io/docs/ruby)
|
34
|
+
|
35
|
+
(c) 2015 Bit Zesty Ltd.
|
data/Rakefile
ADDED
data/lib/vigilion.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# faraday for connection handling
|
2
|
+
require "faraday"
|
3
|
+
require "faraday_middleware"
|
4
|
+
require "faraday/detailed_logger"
|
5
|
+
|
6
|
+
# Vigilion
|
7
|
+
require "vigilion/version"
|
8
|
+
require "vigilion/configuration"
|
9
|
+
require "vigilion/http"
|
10
|
+
require "vigilion/errors"
|
11
|
+
|
12
|
+
module Vigilion
|
13
|
+
def self.configure(&block)
|
14
|
+
Vigilion::Configuration.configure(&block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.scan_url(identifier, url, options = {})
|
18
|
+
Vigilion::HTTP.new.scan_url identifier, url, options
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.scan_path(identifier, path, options = {})
|
22
|
+
Vigilion::HTTP.new.scan_path identifier, path, options
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.check_status(identifier)
|
26
|
+
Vigilion::HTTP.new.get(identifier)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Vigilion
|
5
|
+
class Configuration < OpenStruct
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
yield instance
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.method_missing(m, *args, &block)
|
13
|
+
instance.send(m, *args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Configuration.server_url = "https://api.vigilion.com"
|
18
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Vigilion
|
2
|
+
class HTTP
|
3
|
+
attr_accessor :url, :options, :method
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
validate_access_keys
|
7
|
+
@conn = ::Faraday.new(url: Configuration.server_url) do |c|
|
8
|
+
c.request :multipart
|
9
|
+
c.request :json
|
10
|
+
c.response :json, content_type: /\bjson$/
|
11
|
+
c.response :detailed_logger
|
12
|
+
c.adapter ::Faraday.default_adapter
|
13
|
+
c.headers = {
|
14
|
+
'X-Api-Key' => Configuration.access_key_id,
|
15
|
+
'User-Agent' => "Vigilion #{Vigilion::VERSION} (#{RUBY_PLATFORM}, Ruby #{RUBY_VERSION})"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def scan_url(key, url, options = {})
|
21
|
+
send scan: options.merge({ key: key, url: url })
|
22
|
+
end
|
23
|
+
|
24
|
+
def scan_path(key, path, options = {})
|
25
|
+
send scan: options.merge({ key: key, file: Faraday::UploadIO.new(path, 'application') })
|
26
|
+
end
|
27
|
+
|
28
|
+
def get(uuid)
|
29
|
+
response = @conn.get "/scans/#{uuid}"
|
30
|
+
response.body
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate
|
34
|
+
response = @conn.get "/projects/validate"
|
35
|
+
process_response("", response)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.digest(body)
|
39
|
+
Digest::MD5.hexdigest("#{body}#{Vigilion::Configuration.secret_access_key}")
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
HOW_TO_CONFIGURE = <<-MESSAGE
|
45
|
+
To configure the access keys add a Vigilion.configure block during the application start up.
|
46
|
+
If you are using vigilion-rails, execute `rails g vigilion:install` to create an initializer.
|
47
|
+
By default the initializer uses environment variables so make sure they are present.
|
48
|
+
If you don't know your access keys, go to https://www.vigilion.com and get them!
|
49
|
+
MESSAGE
|
50
|
+
|
51
|
+
INVALID_CREDENTIALS = <<-MESSAGE
|
52
|
+
The provided credentials are not valid.
|
53
|
+
Visit https://www.vigilion.com to get the access keys of your project.
|
54
|
+
MESSAGE
|
55
|
+
|
56
|
+
def send(request)
|
57
|
+
response = @conn.post "/scans", request
|
58
|
+
process_response(request, response)
|
59
|
+
end
|
60
|
+
|
61
|
+
def process_response(request, response)
|
62
|
+
raise Vigilion::Error.new(INVALID_CREDENTIALS) if response.status == 401
|
63
|
+
raise Vigilion::Error.new("Payment required: #{response.body['error']}") if response.status == 402
|
64
|
+
unless response.success?
|
65
|
+
raise Vigilion::Error.new("Invalid scanning request: #{request}. Status: #{response.status}. Response: #{response.body}")
|
66
|
+
end
|
67
|
+
response.body
|
68
|
+
end
|
69
|
+
|
70
|
+
def validate_access_keys
|
71
|
+
raise Vigilion::Error.new("Configuration.access_key_id is not present\n#{HOW_TO_CONFIGURE}") unless Configuration.access_key_id
|
72
|
+
raise Vigilion::Error.new("Configuration.secret_access_key is not present\n#{HOW_TO_CONFIGURE}") unless Configuration.secret_access_key
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative "./test_helper.rb"
|
2
|
+
|
3
|
+
describe Vigilion::Configuration do
|
4
|
+
describe "configure" do
|
5
|
+
it "allows set attributes" do
|
6
|
+
Vigilion.configure do |config|
|
7
|
+
config.attribute = "something"
|
8
|
+
end
|
9
|
+
|
10
|
+
assert_equal Vigilion::Configuration.attribute, "something"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has default values" do
|
14
|
+
refute_nil Vigilion::Configuration.server_url
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/test/http_test.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require_relative "./test_helper.rb"
|
2
|
+
|
3
|
+
describe Vigilion::HTTP do
|
4
|
+
|
5
|
+
describe "constructor" do
|
6
|
+
it "raises error without access_key_id" do
|
7
|
+
Vigilion::Configuration.access_key_id = nil
|
8
|
+
assert_raises Vigilion::Error do
|
9
|
+
Vigilion::HTTP.new
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "raises error without secret_access_key" do
|
14
|
+
Vigilion::Configuration.secret_access_key = nil
|
15
|
+
assert_raises Vigilion::Error do
|
16
|
+
Vigilion::HTTP.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "with credentials" do
|
22
|
+
before do
|
23
|
+
Vigilion.configure do |config|
|
24
|
+
config.access_key_id = "some-key"
|
25
|
+
config.secret_access_key = "some-secret"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#scan_url" do
|
30
|
+
it "returns status of job if posted with success" do
|
31
|
+
# stub POST request for providing URL to files for scan
|
32
|
+
stub_request(:post, "localhost:5000/scans").to_return(
|
33
|
+
body: { "status" => "scanning" }.to_json)
|
34
|
+
|
35
|
+
# check if stubbed URL provides status for scan job
|
36
|
+
scan_request = Vigilion.scan_url("id", "url")
|
37
|
+
assert_includes(scan_request, "scanning")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "accepts options" do
|
41
|
+
# stub POST request for providing URL to files for scan
|
42
|
+
stub_request(:post, "localhost:5000/scans").to_return(
|
43
|
+
body: { "status" => "scanning" }.to_json)
|
44
|
+
|
45
|
+
# check if stubbed URL provides status for scan job
|
46
|
+
scan_request = Vigilion.scan_url("id", "url", force: true)
|
47
|
+
assert_includes(scan_request, "scanning")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#scan_path" do
|
52
|
+
it "returns status of job if posted with success" do
|
53
|
+
# stub POST request for providing URL to files for scan
|
54
|
+
stub_request(:post, "localhost:5000/scans").to_return(
|
55
|
+
body: { "status" => "scanning" }.to_json)
|
56
|
+
|
57
|
+
# check if stubbed URL provides status for scan job
|
58
|
+
scan_request = Vigilion.scan_path("id", "test/sample_file.txt")
|
59
|
+
assert_includes(scan_request, "scanning")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "accepts options" do
|
63
|
+
# stub POST request for providing URL to files for scan
|
64
|
+
stub_request(:post, "localhost:5000/scans").to_return(
|
65
|
+
body: { "status" => "scanning" }.to_json)
|
66
|
+
|
67
|
+
# check if stubbed URL provides status for scan job
|
68
|
+
scan_request = Vigilion.scan_path("id", "test/sample_file.txt", force: true)
|
69
|
+
assert_includes(scan_request, "scanning")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#get" do
|
74
|
+
it "returns status of a job for provided uuid" do
|
75
|
+
body = { id: "de401fdf-08b0-44a8-810b-20794c5c98c7",
|
76
|
+
result: "Eicar-Test-Signature FOUND",
|
77
|
+
md5: "69630e4574ec6798239b091cda43dca0",
|
78
|
+
status: "error" }.to_json
|
79
|
+
|
80
|
+
stub_request(:get, "localhost:5000/scans/de401fdf-08b0-44a8-810b-20794c5c98c7").to_return(
|
81
|
+
body: body)
|
82
|
+
|
83
|
+
result = Vigilion.check_status("de401fdf-08b0-44a8-810b-20794c5c98c7")
|
84
|
+
assert_equal(result, body)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
sample_file
|
data/test/test_helper.rb
ADDED
data/vigilion.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 "vigilion/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "vigilion"
|
8
|
+
s.version = Vigilion::VERSION
|
9
|
+
s.authors = ["Bit Zesty Ltd"]
|
10
|
+
s.email = ["help@vigilion.com"]
|
11
|
+
s.description = "API client for Vigilion Anti-Virus & Malware file scanning service"
|
12
|
+
s.summary = "API client for Vigilion Anti-Virus & Malware file scanning service"
|
13
|
+
s.homepage = "https://github.com/vigilion/vigilion-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
|
+
s.add_dependency "faraday-detailed_logger"
|
23
|
+
|
24
|
+
s.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vigilion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bit Zesty Ltd
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-18 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: faraday-detailed_logger
|
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: 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 Vigilion Anti-Virus & Malware file scanning service
|
70
|
+
email:
|
71
|
+
- help@vigilion.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/vigilion.rb
|
83
|
+
- lib/vigilion/configuration.rb
|
84
|
+
- lib/vigilion/errors.rb
|
85
|
+
- lib/vigilion/http.rb
|
86
|
+
- lib/vigilion/version.rb
|
87
|
+
- test/configuration_test.rb
|
88
|
+
- test/http_test.rb
|
89
|
+
- test/sample_file.txt
|
90
|
+
- test/test_helper.rb
|
91
|
+
- vigilion.gemspec
|
92
|
+
homepage: https://github.com/vigilion/vigilion-ruby
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.5
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: API client for Vigilion Anti-Virus & Malware file scanning service
|
116
|
+
test_files: []
|