Class: Metascan::Client
- Inherits:
-
Object
- Object
- Metascan::Client
- Defined in:
- lib/metascan/client.rb
Overview
The Client object, which stores an API key and has a (currently not used) Typhoeus::Hydra for when you have a lot of requests to make at once.
Instance Method Summary collapse
- #api_key ⇒ Object
-
#hydra ⇒ Object
A Typhoeus Hydra manages parallel HTTP requests.
-
#initialize(api_key) ⇒ Client
constructor
An API key is required.
-
#scan_batch(filenames, archivepwds: nil) ⇒ Object
Scan a batch of files by processing the requests in parallel with Typhoeus::Hydra.
-
#scan_file(filename, archivepwd: nil) ⇒ Object
Returns a Scan object Sample usage:.
Constructor Details
#initialize(api_key) ⇒ Client
An API key is required. Free at www.metascan-online.com
9 10 11 12 |
# File 'lib/metascan/client.rb', line 9 def initialize(api_key) @api_key = api_key @hydra = Typhoeus::Hydra.hydra end |
Instance Method Details
#api_key ⇒ Object
14 15 16 |
# File 'lib/metascan/client.rb', line 14 def api_key @api_key end |
#hydra ⇒ Object
A Typhoeus Hydra manages parallel HTTP requests.
19 20 21 22 23 24 |
# File 'lib/metascan/client.rb', line 19 def hydra if !@hydra @hydra = Typhoeus::Hydra.hydra end @hydra end |
#scan_batch(filenames, archivepwds: nil) ⇒ Object
Scan a batch of files by processing the requests in parallel with Typhoeus::Hydra. Returns a Metascan::Batch object, which can iterate over the set of finished scans. Sample usage:
scanner = Metascan::Client.new(MY_API_KEY)
filenames = ["/etc/passwd", "/dev/sda0", "/dev/random.tgz"] # don't try this
scanner.scan_batch(filenames, archivepwds: { "/dev/random.tgz" => "hunter2" })
=> <Metascan::Batch ...>
50 51 52 53 54 55 56 57 58 |
# File 'lib/metascan/client.rb', line 50 def scan_batch(filenames, archivepwds: nil) scans = Metascan::Batch.new(self.hydra) filenames.each do |f| scan = Metascan::Scan.new(f, self) scans.add(scan) end scans.run scans end |
#scan_file(filename, archivepwd: nil) ⇒ Object
Returns a Scan object Sample usage:
scanner = Metascan::Client.new(MY_API_KEY)
filename = "/etc/unwise-backups/passwd.rar" # FULLY QUALIFIED
scanner.scan_file(filename, archivepwd: "the eagle has left the nest")
=> <Metascan::Scan ... >
35 36 37 38 39 |
# File 'lib/metascan/client.rb', line 35 def scan_file(filename, archivepwd: nil) scan = Metascan::Scan.new(filename, self) scan.run scan end |