Module: ForemanOpenscap::HostgroupOverriderCommon

Included in:
HostgroupOverrider, Oval::Configure
Defined in:
app/services/foreman_openscap/hostgroup_overrider_common.rb

Instance Method Summary collapse

Instance Method Details

#add_overrides(collection, host_or_hg, config) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/foreman_openscap/hostgroup_overrider_common.rb', line 3

def add_overrides(collection, host_or_hg, config)
  model_match = host_or_hg.class.name.underscore =~ /\Ahostgroup\z/ ? "hostgroup" : "fqdn"
  collection.where(:override => true).find_each do |override|
    return unless host_or_hg.openscap_proxy && (url = host_or_hg.openscap_proxy.url).present?

    openscap_proxy_uri = URI.parse(url)
    case override.key
    when config.server_param
      lookup_value = LookupValue.where(:match => "#{model_match}=#{host_or_hg.to_label}", :lookup_key_id => override.id).first_or_initialize
      lookup_value.update_attribute(:value, openscap_proxy_uri.host)
    when config.port_param
      lookup_value = LookupValue.where(:match => "#{model_match}=#{host_or_hg.to_label}", :lookup_key_id => override.id).first_or_initialize
      lookup_value.update_attribute(:value, openscap_proxy_uri.port)
    end
  end
end

#remove_overrides(collection, hostgroup, config) ⇒ Object



20
21
22
23
24
25
26
# File 'app/services/foreman_openscap/hostgroup_overrider_common.rb', line 20

def remove_overrides(collection, hostgroup, config)
  collection.where(:override => true).find_each do |override|
    if override.key == config.server_param || override.key == config.port_param
      LookupValue.find_by(:match => "hostgroup=#{hostgroup.to_label}", :lookup_key_id => override.id)&.destroy
    end
  end
end