Class: ActiveStorage::ClamAV::Analyzer

Inherits:
Analyzer
  • Object
show all
Included in:
Railtie
Defined in:
lib/active_storage/clamav/analyzer.rb

Overview

Uses ClamAV to perform an antivirus scan on the ActiveStorage::Blob, taking action if a detection occurs and otherwise recording the scan results as metadata.

This analyzer requires that ClamAV is installed, but otherwise makes the command and flags available via accessors on this module.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.accept?Boolean

All blobs can be virus scanned

Returns:

  • (Boolean)


35
36
37
# File 'lib/active_storage/clamav/analyzer.rb', line 35

def self.accept?
  true
end

Instance Method Details

#commandObject

Configure the command to run when analyzing blobs. This can either be a string of command or command + args, or can be a callable object. If callable, it will be called before analysing, and will pass an instance of a tempfile. This is useful for using ClamAV via things like Docker, when you may want to mount the tempfile into a container for scanning.



24
# File 'lib/active_storage/clamav/analyzer.rb', line 24

mattr_accessor :command, default: 'clamscan'

#metadataObject



39
40
41
# File 'lib/active_storage/clamav/analyzer.rb', line 39

def 
  { clamav: download_blob_to_tempfile(&method(:perform_virus_scan)) }
end

#on_detectionObject

Configure a callable to run when ClamAV returns a non-zero status indicating a virus was detected. The callable receives the blob and can take action to quarantine or remove the blob record, send an alert, or some other action.



31
# File 'lib/active_storage/clamav/analyzer.rb', line 31

mattr_accessor :on_detection, default: ->(blob) {}