foreman_openscap 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/compliance/oval_contents_controller.rb +72 -0
  3. data/app/controllers/api/v2/compliance/oval_policies_controller.rb +111 -0
  4. data/app/controllers/api/v2/compliance/oval_reports_controller.rb +47 -0
  5. data/app/controllers/concerns/foreman/controller/parameters/oval_content.rb +22 -0
  6. data/app/controllers/concerns/foreman/controller/parameters/oval_policy.rb +22 -0
  7. data/app/controllers/concerns/foreman_openscap/hosts_controller_extensions.rb +1 -1
  8. data/app/graphql/types/cve.rb +17 -0
  9. data/app/graphql/types/oval_content.rb +17 -0
  10. data/app/graphql/types/oval_policy.rb +21 -0
  11. data/app/helpers/arf_reports_helper.rb +0 -14
  12. data/app/mailers/foreman_openscap/policy_mailer.rb +2 -2
  13. data/app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb +1 -1
  14. data/app/models/concerns/foreman_openscap/data_stream_content.rb +0 -17
  15. data/app/models/concerns/foreman_openscap/host_extensions.rb +11 -11
  16. data/app/models/concerns/foreman_openscap/hostgroup_extensions.rb +3 -5
  17. data/app/models/concerns/foreman_openscap/inherited_policies.rb +11 -0
  18. data/app/models/concerns/foreman_openscap/oval_facet_host_extensions.rb +38 -0
  19. data/app/models/concerns/foreman_openscap/oval_facet_hostgroup_extensions.rb +15 -0
  20. data/app/models/concerns/foreman_openscap/policy_common.rb +75 -0
  21. data/app/models/concerns/foreman_openscap/scap_file_content.rb +24 -0
  22. data/app/models/foreman_openscap/cve.rb +23 -0
  23. data/app/models/foreman_openscap/host/oval_facet.rb +14 -0
  24. data/app/models/foreman_openscap/host_cve.rb +7 -0
  25. data/app/models/foreman_openscap/hostgroup/oval_facet.rb +14 -0
  26. data/app/models/foreman_openscap/hostgroup_oval_facet_oval_policy.rb +6 -0
  27. data/app/models/foreman_openscap/oval_content.rb +26 -0
  28. data/app/models/foreman_openscap/oval_facet_oval_policy.rb +6 -0
  29. data/app/models/foreman_openscap/oval_policy.rb +54 -0
  30. data/app/models/foreman_openscap/oval_status.rb +45 -0
  31. data/app/models/foreman_openscap/policy.rb +7 -69
  32. data/app/models/foreman_openscap/scap_content.rb +1 -0
  33. data/app/models/foreman_openscap/tailoring_file.rb +1 -0
  34. data/app/services/foreman_openscap/client_config/ansible.rb +39 -6
  35. data/app/services/foreman_openscap/client_config/base.rb +5 -1
  36. data/app/services/foreman_openscap/client_config/puppet.rb +2 -1
  37. data/app/services/foreman_openscap/config_name_service.rb +1 -1
  38. data/app/services/foreman_openscap/hostgroup_overrider.rb +2 -24
  39. data/app/services/foreman_openscap/hostgroup_overrider_common.rb +28 -0
  40. data/app/services/foreman_openscap/lookup_key_overrider.rb +30 -62
  41. data/app/services/foreman_openscap/lookup_key_overrides_common.rb +63 -0
  42. data/app/services/foreman_openscap/oval/check_collection.rb +45 -0
  43. data/app/services/foreman_openscap/oval/configure.rb +80 -0
  44. data/app/services/foreman_openscap/oval/cves.rb +41 -0
  45. data/app/services/foreman_openscap/oval/setup.rb +93 -0
  46. data/app/services/foreman_openscap/oval/setup_check.rb +55 -0
  47. data/app/services/foreman_openscap/oval/sync_oval_contents.rb +42 -0
  48. data/app/views/api/v2/compliance/oval_contents/base.json.rabl +6 -0
  49. data/app/views/api/v2/compliance/oval_contents/create.json.rabl +3 -0
  50. data/app/views/api/v2/compliance/oval_contents/index.json.rabl +3 -0
  51. data/app/views/api/v2/compliance/oval_contents/show.json.rabl +3 -0
  52. data/app/views/api/v2/compliance/oval_contents/sync.json.rabl +3 -0
  53. data/app/views/api/v2/compliance/oval_contents/sync_result.json.rabl +11 -0
  54. data/app/views/api/v2/compliance/oval_contents/update.json.rabl +3 -0
  55. data/app/views/api/v2/compliance/oval_policies/create.json.rabl +3 -0
  56. data/app/views/api/v2/compliance/oval_policies/index.json.rabl +3 -0
  57. data/app/views/api/v2/compliance/oval_policies/main.json.rabl +15 -0
  58. data/app/views/api/v2/compliance/oval_policies/show.json.rabl +3 -0
  59. data/app/views/api/v2/compliance/policies/base.json.rabl +2 -2
  60. data/app/views/api/v2/compliance/policies_common/_attrs.json.rabl +2 -0
  61. data/app/views/arf_reports/_output.html.erb +9 -1
  62. data/app/views/job_templates/run_oval_scans.erb +24 -0
  63. data/app/views/policies/steps/_deployment_options_form.html.erb +2 -2
  64. data/config/initializers/inflections.rb +12 -0
  65. data/config/routes.rb +19 -0
  66. data/db/migrate/20201019074925_create_oval_policy.rb +13 -0
  67. data/db/migrate/20201020113801_create_oval_facet.rb +14 -0
  68. data/db/migrate/20201021084109_create_hostgroup_oval_facet.rb +14 -0
  69. data/db/migrate/20201106080924_create_oval_content.rb +12 -0
  70. data/db/migrate/20201116110256_add_oval_content_to_oval_policy.rb +5 -0
  71. data/db/migrate/20201120080329_create_cves.rb +13 -0
  72. data/db/migrate/20201202110213_update_puppet_port_param_type.rb +2 -6
  73. data/db/migrate/20201217130800_add_has_errata_to_cve.rb +8 -0
  74. data/db/migrate/20201217161511_add_url_to_oval_content.rb +5 -0
  75. data/db/migrate/20210409095625_add_oval_policy_reference_to_cve.rb +7 -0
  76. data/lib/foreman_openscap/engine.rb +67 -9
  77. data/lib/foreman_openscap/version.rb +1 -1
  78. data/lib/tasks/foreman_openscap_tasks.rake +14 -9
  79. data/locale/de/LC_MESSAGES/foreman_openscap.mo +0 -0
  80. data/locale/de/foreman_openscap.edit.po +0 -0
  81. data/locale/de/foreman_openscap.po +215 -17
  82. data/locale/en_GB/LC_MESSAGES/foreman_openscap.mo +0 -0
  83. data/locale/en_GB/foreman_openscap.edit.po +0 -0
  84. data/locale/en_GB/foreman_openscap.po +213 -15
  85. data/locale/es/LC_MESSAGES/foreman_openscap.mo +0 -0
  86. data/locale/es/foreman_openscap.edit.po +0 -0
  87. data/locale/es/foreman_openscap.po +239 -41
  88. data/locale/foreman_openscap.pot +395 -112
  89. data/locale/fr/LC_MESSAGES/foreman_openscap.mo +0 -0
  90. data/locale/fr/foreman_openscap.edit.po +0 -0
  91. data/locale/fr/foreman_openscap.po +243 -45
  92. data/locale/gl/LC_MESSAGES/foreman_openscap.mo +0 -0
  93. data/locale/gl/foreman_openscap.edit.po +0 -0
  94. data/locale/gl/foreman_openscap.po +213 -15
  95. data/locale/it/LC_MESSAGES/foreman_openscap.mo +0 -0
  96. data/locale/it/foreman_openscap.edit.po +0 -0
  97. data/locale/it/foreman_openscap.po +213 -15
  98. data/locale/ja/LC_MESSAGES/foreman_openscap.mo +0 -0
  99. data/locale/ja/foreman_openscap.edit.po +0 -0
  100. data/locale/ja/foreman_openscap.po +262 -66
  101. data/locale/ko/LC_MESSAGES/foreman_openscap.mo +0 -0
  102. data/locale/ko/foreman_openscap.edit.po +0 -0
  103. data/locale/ko/foreman_openscap.po +214 -16
  104. data/locale/pt_BR/LC_MESSAGES/foreman_openscap.mo +0 -0
  105. data/locale/pt_BR/foreman_openscap.edit.po +0 -0
  106. data/locale/pt_BR/foreman_openscap.po +252 -54
  107. data/locale/ru/LC_MESSAGES/foreman_openscap.mo +0 -0
  108. data/locale/ru/foreman_openscap.edit.po +0 -0
  109. data/locale/ru/foreman_openscap.po +214 -16
  110. data/locale/sv_SE/LC_MESSAGES/foreman_openscap.mo +0 -0
  111. data/locale/sv_SE/foreman_openscap.edit.po +0 -0
  112. data/locale/sv_SE/foreman_openscap.po +213 -15
  113. data/locale/zh_CN/LC_MESSAGES/foreman_openscap.mo +0 -0
  114. data/locale/zh_CN/foreman_openscap.edit.po +0 -0
  115. data/locale/zh_CN/foreman_openscap.po +369 -169
  116. data/locale/zh_TW/LC_MESSAGES/foreman_openscap.mo +0 -0
  117. data/locale/zh_TW/foreman_openscap.edit.po +0 -0
  118. data/locale/zh_TW/foreman_openscap.po +214 -16
  119. data/test/factories/compliance_host_factory.rb +12 -0
  120. data/test/factories/oval_content_factory.rb +7 -0
  121. data/test/factories/oval_policy_factory.rb +9 -0
  122. data/test/files/oval_contents/ansible-2.9.oval.xml.bz2 +0 -0
  123. data/test/fixtures/cve_fixtures.rb +104 -0
  124. data/test/functional/api/v2/compliance/oval_contents_controller_test.rb +39 -0
  125. data/test/functional/api/v2/compliance/oval_policies_controller_test.rb +141 -0
  126. data/test/functional/api/v2/compliance/oval_reports_controller_test.rb +32 -0
  127. data/test/graphql/queries/oval_contents_query_test.rb +35 -0
  128. data/test/graphql/queries/oval_policies_query_test.rb +35 -0
  129. data/test/test_plugin_helper.rb +4 -0
  130. data/test/unit/oval_host_test.rb +45 -0
  131. data/test/unit/oval_policy_test.rb +133 -0
  132. data/test/unit/oval_status_test.rb +47 -0
  133. data/test/unit/services/oval/cves_test.rb +81 -0
  134. data/test/unit/services/oval/setup_test.rb +87 -0
  135. metadata +97 -3
@@ -0,0 +1,63 @@
1
+ module ForemanOpenscap
2
+ module LookupKeyOverridesCommon
3
+ extend ActiveSupport::Concern
4
+
5
+ def override(config)
6
+ return unless handle_config_not_available(config)
7
+ override_required_params config
8
+ end
9
+
10
+ def override_required_params(config)
11
+ return unless config.managed_overrides?
12
+ item = config.find_config_item
13
+
14
+ return unless handle_config_item_not_available(config, item)
15
+ override_params item.public_send(config.override_method_name), config
16
+ end
17
+
18
+ def override_params(lookup_keys, config)
19
+ policies_param = lookup_keys.find_by :key => config.policies_param
20
+ port_param = lookup_keys.find_by :key => config.port_param
21
+ server_param = lookup_keys.find_by :key => config.server_param
22
+
23
+ missing_keys = missing_lookup_keys(config.policies_param => policies_param,
24
+ config.port_param => port_param,
25
+ config.server_param => server_param)
26
+
27
+ return unless handle_missing_lookup_keys config, missing_keys.compact.join(', ')
28
+
29
+ override_policies_param(policies_param, config)
30
+ override_port_param(port_param, config)
31
+ override_server_param(server_param, config)
32
+ end
33
+
34
+ def override_policies_param(parameter, config)
35
+ override_param 'policies', config.policies_param, parameter, config, 'array', config.policies_param_default_value
36
+ end
37
+
38
+ def override_port_param(param, config)
39
+ override_param 'port', config.port_param, param, config, 'integer'
40
+ end
41
+
42
+ def override_server_param(param, config)
43
+ override_param 'server', config.server_param, param, config, 'string'
44
+ end
45
+
46
+ def override_param(handler, param_name, param, config, key_type, default_value = nil)
47
+ param.override = true
48
+ param.hidden_value = false
49
+ param.key_type = key_type
50
+ param.default_value = default_value
51
+
52
+ send("handle_#{handler}_param_override", config, param)
53
+ end
54
+
55
+ def missing_lookup_keys(hash)
56
+ return [] if hash.values.all?
57
+ hash.reduce([]) do |memo, (key, value)|
58
+ memo << key if value.blank?
59
+ memo
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,45 @@
1
+ module ForemanOpenscap
2
+ module Oval
3
+ class CheckCollection
4
+ attr_reader :checks
5
+
6
+ def initialize(initial_check_attrs = [])
7
+ @checks = initial_check_attrs.map { |hash| SetupCheck.new hash }
8
+ end
9
+
10
+ def all_passed?
11
+ @checks.all?(&:passed?)
12
+ end
13
+
14
+ def find_check(check_id)
15
+ @checks.find { |item| item.id == check_id }
16
+ end
17
+
18
+ def find_failed
19
+ @checks.select(&:failed?)
20
+ end
21
+
22
+ def fail_check(check_id, error_data = nil)
23
+ find_check(check_id).fail_with! error_data
24
+ end
25
+
26
+ def pass_check(check_id)
27
+ find_check(check_id).pass!
28
+ end
29
+
30
+ def add_check(check)
31
+ @checks << check
32
+ self
33
+ end
34
+
35
+ def merge(other)
36
+ @checks = @checks.concat other.checks
37
+ self
38
+ end
39
+
40
+ def to_h
41
+ @checks.map(&:to_h)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,80 @@
1
+ module ForemanOpenscap
2
+ module Oval
3
+ class Configure
4
+ include ::ForemanOpenscap::HostgroupOverriderCommon
5
+
6
+ def initialize
7
+ @config = ForemanOpenscap::ClientConfig::Ansible.new(::ForemanOpenscap::OvalPolicy)
8
+ end
9
+
10
+ def assign(oval_policy, ids, model_class)
11
+ check_collection = ::ForemanOpenscap::Oval::Setup.new.run
12
+ return check_collection unless check_collection.all_passed?
13
+
14
+ ansible_role = @config.find_config_item
15
+
16
+ if model_class == ::Hostgroup
17
+ roles_method = :inherited_and_own_ansible_roles
18
+ ids_setter = :hostgroup_ids=
19
+ elsif model_class == ::Host::Managed
20
+ roles_method = :all_ansible_roles
21
+ ids_setter = :host_ids=
22
+ else
23
+ raise "Unexpected model_class, expected ::Hostgroup or ::Host::Managed, got: #{model_class}"
24
+ end
25
+
26
+ items_with_proxy, items_without_proxy = openscap_proxy_associated(ids, model_class)
27
+
28
+ oval_policy.send(ids_setter, items_with_proxy.pluck(:id))
29
+
30
+ check_collection = without_proxy_to_check items_without_proxy
31
+
32
+ unless oval_policy.save
33
+ return check_collection.add_check model_to_check(oval_policy)
34
+ end
35
+
36
+ check_collection.merge modify_items(items_with_proxy, oval_policy, ansible_role, roles_method)
37
+ end
38
+
39
+ private
40
+
41
+ def openscap_proxy_associated(ids, model_class)
42
+ model_class.where(:id => ids).partition(&:openscap_proxy)
43
+ end
44
+
45
+ def modify_items(items, oval_policy, ansible_role, roles_method)
46
+ items.reduce(CheckCollection.new) do |memo, item|
47
+ role_ids = item.ansible_role_ids + [ansible_role.id]
48
+ item.ansible_role_ids = role_ids unless item.send(roles_method).include? ansible_role
49
+ item.save if item.changed?
50
+ memo.add_check model_to_check(item)
51
+ add_overrides ansible_role.ansible_variables, item, @config
52
+ memo
53
+ end
54
+ end
55
+
56
+ def without_proxy_to_check(items)
57
+ items.reduce(CheckCollection.new) do |memo, item|
58
+ memo.add_check(
59
+ SetupCheck.new(
60
+ :title => (_("Was %s configured successfully?") % item.class.name),
61
+ :fail_msg => ->(_) { _("Assign openscap_proxy to %s before proceeding.") % item.name }
62
+ ).fail!
63
+ )
64
+ end
65
+ end
66
+
67
+ def model_to_s(model)
68
+ model.is_a?(::Hostgroup) ? 'hostgroup' : 'host'
69
+ end
70
+
71
+ def model_to_check(model)
72
+ check = SetupCheck.new(
73
+ :title => (_("Was %{model_name} %{name} configured successfully?") % { :model_name => model_to_s(model), :name => model.name }),
74
+ :errors => model.errors.to_h
75
+ )
76
+ model.errors.any? ? check.fail! : check.pass!
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,41 @@
1
+ module ForemanOpenscap
2
+ module Oval
3
+ class Cves
4
+ def create(host, cve_data)
5
+ policy_id = cve_data['oval_policy_id']
6
+
7
+ incoming_cves = cve_data['oval_results'].reduce([]) do |memo, data|
8
+ next memo unless data['result'] == 'true'
9
+ cves, errata = data['references'].partition { |ref| ref['ref_id'].start_with?('CVE') }
10
+
11
+ cves.map do |cve|
12
+ memo << ::ForemanOpenscap::Cve.find_or_create_by(
13
+ :ref_id => cve['ref_id'],
14
+ :ref_url => cve['ref_url'],
15
+ :has_errata => !errata.empty?,
16
+ :definition_id => data['definition_id']
17
+ )
18
+ end
19
+ memo
20
+ end
21
+
22
+ current = ForemanOpenscap::Cve.of_oval_policy(policy_id).of_host(host.id)
23
+ to_delete = current - incoming_cves
24
+ to_create = incoming_cves - current
25
+
26
+ ::ForemanOpenscap::HostCve.where(:host_id => host.id, :oval_policy_id => policy_id, :cve_id => to_delete.pluck(:id)).destroy_all
27
+ host.host_cves.build(to_create.map { |cve| { :host_id => host.id, :oval_policy_id => policy_id, :cve_id => cve.id } })
28
+
29
+ delete_orphaned_cves to_delete.pluck(:id) if host.save
30
+ host
31
+ end
32
+
33
+ private
34
+
35
+ def delete_orphaned_cves(ids)
36
+ associated_ids = ::ForemanOpenscap::HostCve.where(:cve_id => ids).select(:cve_id).distinct.pluck(:cve_id)
37
+ ::ForemanOpenscap::Cve.where(:id => ids - associated_ids).destroy_all
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,93 @@
1
+ module ForemanOpenscap
2
+ module Oval
3
+ class Setup
4
+ include ::ForemanOpenscap::LookupKeyOverridesCommon
5
+
6
+ def initialize
7
+ @config = ForemanOpenscap::ClientConfig::Ansible.new(::ForemanOpenscap::OvalPolicy)
8
+ @check_collection = CheckCollection.new initial_check_attrs
9
+ end
10
+
11
+ def run
12
+ override @config
13
+ @check_collection
14
+ end
15
+
16
+ def handle_config_not_available(config)
17
+ return @check_collection.pass_check :foreman_ansible_present if config.available?
18
+ fail_check :foreman_ansible_present
19
+ end
20
+
21
+ def handle_config_item_not_available(config, item)
22
+ return @check_collection.pass_check :foreman_scap_client_role_present if item
23
+ fail_check :foreman_scap_client_role_present
24
+ end
25
+
26
+ def handle_missing_lookup_keys(config, key_names)
27
+ return @check_collection.pass_check :foreman_scap_client_vars_present if key_names.empty?
28
+ fail_check :foreman_scap_client_vars_present, :missing_vars => key_names
29
+ end
30
+
31
+ def handle_server_param_override(config, param)
32
+ handle_param_override :foreman_scap_client_server_overriden, config, param
33
+ end
34
+
35
+ def handle_port_param_override(config, param)
36
+ handle_param_override :foreman_scap_client_port_overriden, config, param
37
+ end
38
+
39
+ def handle_policies_param_override(config, param)
40
+ handle_param_override :foreman_scap_client_policies_overriden, config, param
41
+ end
42
+
43
+ def handle_param_override(check_id, config, param)
44
+ return fail_check check_id if param.changed? && !param.save
45
+ @check_collection.pass_check check_id
46
+ end
47
+
48
+ def fail_check(check_id, error_data = nil)
49
+ @check_collection.fail_check(check_id, error_data)
50
+ false
51
+ end
52
+
53
+ private
54
+
55
+ def initial_check_attrs
56
+ override_msg = _("Could not update Ansible Variables with override: true")
57
+
58
+ [
59
+ {
60
+ :id => :foreman_ansible_present,
61
+ :title => _("Is foreman_ansible present?"),
62
+ :fail_msg => ->(hash) { _("foreman_ansible plugin not found, please install it before running this action again.") }
63
+ },
64
+ {
65
+ :id => :foreman_scap_client_role_present,
66
+ :title => _("Is theforeman.foreman_scap_client present?"),
67
+ :fail_msg => ->(hash) { @config.ansible_role_missing_msg }
68
+ },
69
+ {
70
+ :id => :foreman_scap_client_vars_present,
71
+ :title => _("Are required variables for theforeman.foreman_scap_client present?"),
72
+ :fail_msg => ->(hash) { _("The following Ansible Variables were not found: %{missing_vars}, please import them before running this action again.") % hash }
73
+ },
74
+ {
75
+ :id => :foreman_scap_client_server_overriden,
76
+ :title => _("Is %s param set to be overriden?") % @config.server_param,
77
+ :fail_msg => ->(hash) { override_msg }
78
+ },
79
+ {
80
+ :id => :foreman_scap_client_port_overriden,
81
+ :title => _("Is %s param set to be overriden?") % @config.port_param,
82
+ :fail_msg => ->(hash) { override_msg }
83
+ },
84
+ {
85
+ :id => :foreman_scap_client_policies_overriden,
86
+ :title => _("Is %s param set to be overriden?") % @config.policies_param,
87
+ :fail_msg => ->(hash) { override_msg }
88
+ }
89
+ ]
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,55 @@
1
+ module ForemanOpenscap
2
+ module Oval
3
+ class SetupCheck
4
+ attr_reader :result, :id
5
+
6
+ def initialize(hash)
7
+ @id = hash[:id]
8
+ @title = hash[:title]
9
+ @fail_msg = hash[:fail_msg]
10
+ @errors = hash[:errors]
11
+ @result = :skip
12
+ end
13
+
14
+ def fail_with!(fail_data)
15
+ @fail_msg_data = fail_data
16
+ fail!
17
+ end
18
+
19
+ def fail!
20
+ @result = :fail
21
+ self
22
+ end
23
+
24
+ def pass!
25
+ @result = :pass
26
+ self
27
+ end
28
+
29
+ def failed?
30
+ @result == :fail
31
+ end
32
+
33
+ def passed?
34
+ @result == :pass
35
+ end
36
+
37
+ def skipped?
38
+ @result == :skip
39
+ end
40
+
41
+ def fail_msg
42
+ @fail_msg.call @fail_msg_data if @fail_msg
43
+ end
44
+
45
+ def to_h
46
+ {
47
+ :title => @title,
48
+ :result => @result,
49
+ :fail_message => failed? ? fail_msg : nil,
50
+ :errors => @errors
51
+ }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,42 @@
1
+ module ForemanOpenscap
2
+ module Oval
3
+ class SyncOvalContents
4
+ def sync(oval_content)
5
+ begin
6
+ content_blob = fetch_content_blob(oval_content.url)
7
+ rescue StandardError => e
8
+ oval_content.errors.add(:base, "#{fail_msg oval_content}, cause: #{e.message}")
9
+ return oval_content
10
+ end
11
+
12
+ unless content_blob
13
+ oval_content.errors.add(:base, fail_msg(oval_content))
14
+ return oval_content
15
+ end
16
+ oval_content.scap_file = content_blob
17
+ oval_content
18
+ end
19
+
20
+ def sync_all
21
+ to_sync = ForemanOpenscap::OvalContent.where.not(:url => nil)
22
+ to_sync.map { |content| content.tap { |item| sync(item).save } }
23
+ end
24
+
25
+ private
26
+
27
+ def fail_msg(content)
28
+ "Failed to fetch content file from #{content.url}"
29
+ end
30
+
31
+ def fetch_content_blob(url)
32
+ response = fetch url
33
+ return unless response.code == 200
34
+ response.body
35
+ end
36
+
37
+ def fetch(url)
38
+ RestClient.get(url)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,6 @@
1
+ object @oval_content
2
+
3
+ extends "api/v2/compliance/common/org"
4
+ extends "api/v2/compliance/common/loc"
5
+
6
+ attributes :id, :name, :original_filename, :digest, :created_at, :updated_at, :url
@@ -0,0 +1,3 @@
1
+ object @oval_content
2
+
3
+ extends "api/v2/compliance/oval_contents/base"
@@ -0,0 +1,3 @@
1
+ collection @oval_contents
2
+
3
+ extends "api/v2/compliance/oval_contents/base"