Class: Proxy::OpenSCAP::StorageFs

Inherits:
Storage
  • Object
show all
Includes:
StorageFsCommon
Defined in:
lib/smart_proxy_openscap/storage_fs.rb

Instance Method Summary collapse

Methods inherited from Storage

#get_arf_html, #initialize

Constructor Details

This class inherits a constructor from Proxy::OpenSCAP::Storage

Instance Method Details

#delete_arf_fileObject

Raises:



39
40
41
42
43
44
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 39

def delete_arf_file
  path = "#{@path_to_dir}/#{@namespace}/#{@cname}/#{@id}"
  raise FileNotFound, "Can't find path #{path}" if !File.directory?(path) || File.zero?(path)
  FileUtils.rm_r path
  {:id => @id, :deleted => true}.to_json
end

#get_arf_file(digest) ⇒ Object



46
47
48
49
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 46

def get_arf_file(digest)
  file = File.open(get_path digest)
  { :size => File.size(file), :xml => file.read }
end

#get_arf_xml(digest) ⇒ Object



35
36
37
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 35

def get_arf_xml(digest)
  get_arf_file(digest)[:xml]
end

#get_path(digest) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 51

def get_path(digest)
  full_path = @path + digest
  if !File.file?(full_path) || File.zero?(full_path)
    logger.info "File not found in storage, trying to get it from spool"
    path_to_spool = Proxy::OpenSCAP::Plugin.settings.spooldir
    move_from_spool(digest, path_to_spool)
  end
  full_path
rescue StoreSpoolError
  raise FileNotFound, "Can't find path #{full_path}"
end

#list_dirs(path) ⇒ Object



68
69
70
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 68

def list_dirs(path)
  Pathname.new(path).children.select(&:directory?)
end

#move_corrupted(digest, spooldir) ⇒ Object



25
26
27
28
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 25

def move_corrupted(digest, spooldir)
  source = "#{spooldir}/#{@namespace}/#{@cname}/#{@id}/#{@date}"
  move "#{source}/#{digest}", StoreCorruptedError
end

#move_from_spool(digest, spooldir) ⇒ Object



30
31
32
33
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 30

def move_from_spool(digest, spooldir)
  path = Dir.glob("#{spooldir}/#{@namespace}/#{@cname}/*/#{@date}/#{digest}").first
  move path, StoreSpoolError
end

#spool_errorsObject



63
64
65
66
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 63

def spool_errors
  path = "#{@path_to_dir}/#{@namespace}"
  { :errors_count => File.exists?(path) ? list_dirs(path).count : 0 }
end

#store_archive(data) ⇒ Object



9
10
11
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 9

def store_archive(data)
  store(data, StoreReportError)
end

#store_corrupted(data) ⇒ Object



21
22
23
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 21

def store_corrupted(data)
  store(data, StoreCorruptedError)
end

#store_failed(data) ⇒ Object



17
18
19
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 17

def store_failed(data)
  store(data, StoreFailedError)
end

#store_spool(data) ⇒ Object



13
14
15
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 13

def store_spool(data)
  store(data, StoreSpoolError)
end