Class: Proxy::OpenSCAP::FetchScapFile

Inherits:
FetchFile
  • Object
show all
Defined in:
lib/smart_proxy_openscap/fetch_scap_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ FetchScapFile

Returns a new instance of FetchScapFile.



5
6
7
8
# File 'lib/smart_proxy_openscap/fetch_scap_file.rb', line 5

def initialize(type)
  raise "Expected one of the following symbols: #{allowed_types.join(', ')}, got: #{type}" unless allowed_types.include? type
  @type = type
end

Instance Method Details

#allowed_typesObject



37
38
39
# File 'lib/smart_proxy_openscap/fetch_scap_file.rb', line 37

def allowed_types
  [:scap_content, :tailoring_file]
end

#download_pathObject



21
22
23
24
25
26
27
28
# File 'lib/smart_proxy_openscap/fetch_scap_file.rb', line 21

def download_path
  case @type
  when :scap_content
    "api/v2/compliance/policies/:policy_id/content"
  when :tailoring_file
    "api/v2/compliance/policies/:policy_id/tailoring"
  end
end

#fetch(policy_id, digest, content_dir) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/smart_proxy_openscap/fetch_scap_file.rb', line 10

def fetch(policy_id, digest, content_dir)
  store_dir = File.join(Proxy::OpenSCAP.fullpath(content_dir), policy_id.to_s)
  scap_file = File.join(store_dir, file_name(policy_id, digest))

  file_download_path = download_path.sub(':policy_id', policy_id)
  create_store_dir store_dir
  file = policy_content_file scap_file
  clean_store_folder store_dir unless file
  file ||= save_or_serve_scap_file scap_file, file_download_path
end

#file_name(policy_id, digest) ⇒ Object



30
31
32
33
34
35
# File 'lib/smart_proxy_openscap/fetch_scap_file.rb', line 30

def file_name(policy_id, digest)
  case @type
  when :scap_content, :tailoring_file
    "#{policy_id}_#{digest}.xml"
  end
end