kaspersky-linux_fs 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa69a35db657dce5ce78c878a0d6d878f1e09adc
4
- data.tar.gz: 2413e6350a0a30ee26ab89cf6bfb5e9c5d97e871
3
+ metadata.gz: d7362c182b5d69d09c5dd84d5165525d2bb6b85e
4
+ data.tar.gz: f9d6c94c8e6c42bb81178cf4e96a4895d2db4de5
5
5
  SHA512:
6
- metadata.gz: e2fb76f499a5f2046f74d54ba78faf27410ab3eb0dcb62b209f825554c24c6f795da0bbb89ca71ce5ac4e36f68ff7e11aaf973bd3c645c9a986f0e10d9c59273
7
- data.tar.gz: a2a9b1e4f3bf3b9bfca326d7ce3e5d92a9175043359eb0ed6e3d72fa20fdab1703e9c0d4719f33e86a0a79d2f4be1ba3754ef0bcec629efb3ccbfcc502a808c4
6
+ metadata.gz: d1dfb5ba88939035c2c1359021c8b9758745f55270af0a7e8b92cb0ed8d97a228e84c9f4a5a5bba5a8e6de90a54d898bb3bf54eab6b84c84f4b0685a6fd4f1ff
7
+ data.tar.gz: 55dbaffbd12a4d752fecc31e33d834879aed94d3a9f8bbf5fcac803a1c09c3e7f196f54ff25fe16a1dd58297345f2a6ad7315896fd1ffb403c7d61ae06f8a6b3
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Small wrapper for Kaspersky linux file system
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/kaspersky-linux_fs.svg)](http://badge.fury.io/rb/kaspersky-linux_fs)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -21,6 +23,8 @@ Or install it yourself as:
21
23
  ## Usage
22
24
 
23
25
  ```ruby
26
+ require 'kaspersky/linux_fs'
27
+
24
28
  # prepare arguments
25
29
  use_sudo = true
26
30
  bin_path_to_kaspersky = '/opt/kaspersky/kav4fs/bin/kav4fs-control'
@@ -29,12 +33,16 @@ bin_path_to_kaspersky = '/opt/kaspersky/kav4fs/bin/kav4fs-control'
29
33
  linux_fs = Kaspersky::LinuxFs.new(bin_path_to_kaspersky, use_sudo)
30
34
 
31
35
  # check file for virus
32
- file_path = '/home/user/uploads/infected_file.exe'
33
- response = linux_fs.fast_scan(file_path)
34
-
35
- # check response
36
- response.threat? # => true
37
- response.safe? # => false
36
+ begin
37
+ file_path = '/home/user/uploads/infected_file.exe'
38
+ response = linux_fs.fast_scan(file_path)
39
+
40
+ # check response
41
+ response.threat? # => true
42
+ response.safe? # => false
43
+ rescue => e
44
+ # process exception
45
+ end
38
46
  ````
39
47
 
40
48
  ## Contributing
@@ -14,10 +14,12 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ #spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  #spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.required_ruby_version = '~> 2.0'
22
+ spec.required_rubygems_version = '~> 1.8'
21
23
  spec.add_development_dependency "bundler", "~> 1.7"
22
24
  spec.add_development_dependency "rake", "~> 10.0"
23
25
  end
@@ -2,60 +2,57 @@ require "kaspersky/linux_fs/version"
2
2
  require 'open3'
3
3
 
4
4
  module Kaspersky
5
- module LinuxFs
5
+ class LinuxFs
6
+ SKIP_ACTION = 'Skip'
7
+
8
+ def initialize(bin, use_sudo = false)
9
+ @bin = bin
10
+ @use_sudo = use_sudo
11
+ @default_options = {
12
+ action: SKIP_ACTION
13
+ }
14
+ end
6
15
 
7
- class << self
8
- SKIP_ACTION = 'Skip'
16
+ def fast_scan(path_to_file, options = {})
17
+ command = "#{build_base_request}#{build_options(options.to_hash.merge({ scan_file: path_to_file.to_s }))}"
18
+ output = nil
19
+ success = false
9
20
 
10
- def initialize(bin, use_sudo = false)
11
- @bin = bin
12
- @use_sudo = use_sudo
13
- @default_options = {
14
- action: SKIP_ACTION
15
- }
16
- end
21
+ Open3.popen3(command) do |stdin, stdout, stderr, thread|
22
+ process = thread.value
23
+ output = stderr.read
17
24
 
18
- def fast_scan(path_to_file, options = {})
19
- command = "#{build_base_request}#{build_options(options.to_hash.merge({scan_file: path_to_file.to_s}))}"
20
- output = nil
21
- success = false
22
-
23
- Open3.popen3(command) do |stdin, stdout, stderr, thread|
24
- process = thread.value
25
- output = stderr.read
26
-
27
- # "sudo -n ..." exit with code 0 when password is incorrect
28
- # so, checking stderr is required
29
- if process.success? && output.size.zero?
30
- output = stdout.read
31
- success = true
32
- end
25
+ # "sudo -n ..." exit with code 0 when password is incorrect
26
+ # so, checking stderr is required
27
+ if process.success? && output.size.zero?
28
+ output = stdout.read
29
+ success = true
33
30
  end
31
+ end
34
32
 
35
- fail "#{output}" unless success
33
+ fail "#{output}" unless success
36
34
 
37
- Kaspersky::LinuxFs::Response::FastScan.new(output)
38
- end
35
+ Kaspersky::LinuxFs::Response::FastScan.new(output)
36
+ end
39
37
 
40
- private
38
+ private
41
39
 
42
- def build_base_request
43
- request = @bin
40
+ def build_base_request
41
+ request = @bin
44
42
 
45
- # n - non-interactive
46
- request.prepend('sudo -n ') if @use_sudo
43
+ # n - non-interactive
44
+ request.prepend('sudo -n ') if @use_sudo
47
45
 
48
- request
49
- end
46
+ request
47
+ end
50
48
 
51
- def build_options(data)
52
- data = @default_options.merge(data)
53
- options = ''
54
- data.each do |key, value|
55
- options += " --#{key.to_s.tr('_','-')} #{value}"
56
- end
57
- options
49
+ def build_options(data)
50
+ data = @default_options.merge(data)
51
+ options = ''
52
+ data.each do |key, value|
53
+ options += " --#{key.to_s.tr('_', '-')} #{value}"
58
54
  end
55
+ options
59
56
  end
60
57
  end
61
58
  end
@@ -1,5 +1,5 @@
1
1
  module Kaspersky
2
- module LinuxFs
3
- VERSION = "0.0.1"
2
+ class LinuxFs
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaspersky-linux_fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - LightSuner
@@ -64,14 +64,14 @@ require_paths:
64
64
  - lib
65
65
  required_ruby_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: '2.0'
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">="
72
+ - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0'
74
+ version: '1.8'
75
75
  requirements: []
76
76
  rubyforge_project:
77
77
  rubygems_version: 2.4.5