foreman_openscap 8.0.1 → 8.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bf645bb17178ebf3a7845c4955f6b100814e3fcae13f834bcaa4b94522e6d67
4
- data.tar.gz: e5a773297d59f9d7f81c3a26085b73534424149aac6dec6a205798d98f3764e2
3
+ metadata.gz: 8bbb0c081fe2e68b2a02f8c835f5bbbef162c1f2fa973bc591ad60e27da60884
4
+ data.tar.gz: 5067c304b892af1d53e7d0ae54e03e831c51f6027e0978058051a1d63e48e5b7
5
5
  SHA512:
6
- metadata.gz: c51175dfdebd026cf1cd0f75a77cb04b10ed2c1fbdb05c74557a5385ff390b6b6e979f5ec7433229e965fb35ab8528c7d817a368d16b3483ca8ac80f228f3341
7
- data.tar.gz: df041f57fe9dfa77f4568579c0294f92d2c7ce16b391884cc35fce39c2c60447b0aa648ee2c9edb8bd3322dc0c6ae1bccbf9d8b6bca0296cd32a3b89f53c51b4
6
+ metadata.gz: 95885c08136b4a8255767661ca869e899c1a115e99912cf613964edce482885b7e6cabc0690e4330fe95745af8fc743fb0314837a540ae2d6fae226311367c78
7
+ data.tar.gz: cef966ada1688c607047f829d512fb329972edaf9d415466f4259d647a9a0758a3e729532c0dbf7bbc732d6272b0aaeeaa607e358de58148a808a9606000dc9d
@@ -1,5 +1,16 @@
1
1
  module ::ProxyAPI
2
2
  class Openscap < ::ProxyAPI::Resource
3
+ HTTP_ERRORS = [
4
+ EOFError,
5
+ Errno::ECONNRESET,
6
+ Errno::EINVAL,
7
+ Net::HTTPBadResponse,
8
+ Net::HTTPHeaderSyntaxError,
9
+ Net::ProtocolError,
10
+ Timeout::Error,
11
+ ProxyAPI::ProxyException
12
+ ].freeze
13
+
3
14
  def initialize(args)
4
15
  @url = args[:url] + '/compliance/'
5
16
  super args
@@ -10,11 +10,7 @@ module ForemanOpenscap
10
10
  end
11
11
 
12
12
  def proxy_url
13
- @proxy_url ||= SmartProxy.with_features('Openscap').find do |proxy|
14
- available = ProxyAPI::AvailableProxy.new(:url => proxy.url)
15
- available.available?
16
- end.try(:url)
17
- @proxy_url
13
+ @proxy_url ||= SmartProxy.with_features('Openscap').find(&:ping)&.url
18
14
  end
19
15
 
20
16
  def create_profiles
@@ -22,7 +22,7 @@ module ForemanOpenscap
22
22
  errors['errors'].each { |error| data_stream_content.errors.add(:scap_file, _(error)) }
23
23
  return false
24
24
  end
25
- rescue *ProxyAPI::AvailableProxy::HTTP_ERRORS => e
25
+ rescue *ProxyAPI::Openscap::HTTP_ERRORS => e
26
26
  data_stream_content.errors.add(:base, _('No available proxy to validate. Returned with error: %s') % e)
27
27
  return false
28
28
  end
@@ -6,14 +6,15 @@ require 'tempfile'
6
6
  module ForemanOpenscap
7
7
  class DataMigration
8
8
  def initialize(proxy_id)
9
- @proxy = ::SmartProxy.find(proxy_id)
10
- puts "Found proxy #{@proxy.to_label}"
11
- @url = @proxy.url
9
+ @proxy = ::SmartProxy.with_features('Openscap').where(id: proxy_id).first
10
+ if @proxy
11
+ puts "Found proxy #{@proxy.to_label}"
12
+ @url = @proxy.url
13
+ end
12
14
  end
13
15
 
14
16
  def available?
15
- return false unless @proxy && @url
16
- ::ProxyAPI::AvailableProxy.new(:url => @url).available? && foreman_available?
17
+ @proxy&.ping && foreman_available?
17
18
  end
18
19
 
19
20
  def migrate
@@ -47,7 +48,7 @@ module ForemanOpenscap
47
48
  foreman_status_url = Setting[:foreman_url] + '/status'
48
49
  response = JSON.parse(RestClient.get(foreman_status_url))
49
50
  return true if response["status"] == "ok"
50
- rescue *::ProxyAPI::AvailableProxy::HTTP_ERRORS
51
+ rescue *::ProxyAPI::Openscap::HTTP_ERRORS
51
52
  return false
52
53
  end
53
54
 
@@ -1,3 +1,3 @@
1
1
  module ForemanOpenscap
2
- VERSION = "8.0.1".freeze
2
+ VERSION = "8.0.2".freeze
3
3
  end
@@ -17,7 +17,6 @@ class ScapContentTest < ActiveSupport::TestCase
17
17
 
18
18
  test 'scap content should fail if no openscap proxy' do
19
19
  SmartProxy.stubs(:with_features).returns([])
20
- ProxyAPI::AvailableProxy.any_instance.stubs(:available?).returns(false)
21
20
  scap_content = ForemanOpenscap::ScapContent.new(:title => 'Fedora', :scap_file => @scap_file)
22
21
  refute(scap_content.save)
23
22
  assert_includes(scap_content.errors.messages[:base], 'No proxy with OpenSCAP feature was found.')
@@ -26,8 +25,8 @@ class ScapContentTest < ActiveSupport::TestCase
26
25
  test 'proxy_url should return the first available proxy it finds' do
27
26
  available_proxy = SmartProxy.with_features('Openscap').first
28
27
  unavailable_proxy = FactoryBot.create(:smart_proxy, :url => 'http://proxy.example.com:8443', :features => [FactoryBot.create(:feature, :name => 'Openscap')])
29
- available_proxy.stubs(:proxy_url).returns(available_proxy.url)
30
- unavailable_proxy.stubs(:proxy_url).returns(nil)
28
+ SmartProxy.expects(:with_features).with('Openscap').returns([unavailable_proxy, available_proxy])
29
+ SmartProxy.any_instance.expects(:ping).twice.returns(false).then.returns(true)
31
30
  scap_content = ForemanOpenscap::ScapContent.new(:title => 'Fedora', :scap_file => @scap_file)
32
31
  assert_equal(available_proxy.url, scap_content.proxy_url)
33
32
  end
@@ -6,7 +6,7 @@ import { Button } from '@patternfly/react-core';
6
6
 
7
7
  import { translate as __ } from 'foremanReact/common/I18n';
8
8
  import { foremanUrl } from 'foremanReact/common/helpers';
9
- import { getHostsPageUrl } from 'foremanReact/Root/Context/ForemanContext';
9
+ import { useForemanHostsPageUrl } from 'foremanReact/Root/Context/ForemanContext';
10
10
 
11
11
  const ViewSelectedHostsLink = ({
12
12
  hostIdsParam,
@@ -14,7 +14,7 @@ const ViewSelectedHostsLink = ({
14
14
  defaultFailedHostsSearch,
15
15
  }) => {
16
16
  const search = isAllHostsSelected ? defaultFailedHostsSearch : hostIdsParam;
17
- const url = foremanUrl(`${getHostsPageUrl(false)}?search=${search}`);
17
+ const url = foremanUrl(`${useForemanHostsPageUrl()}?search=${search}`);
18
18
  return (
19
19
  <Button
20
20
  component="a"
@@ -7,6 +7,7 @@ import {
7
7
  ToolbarContent,
8
8
  ToolbarGroup,
9
9
  ToolbarItem,
10
+ Button,
10
11
  } from '@patternfly/react-core';
11
12
  import { Td } from '@patternfly/react-table';
12
13
  import { toArray } from 'lodash';
@@ -19,6 +20,7 @@ import { useBulkSelect } from 'foremanReact/components/PF4/TableIndexPage/Table/
19
20
  import { getPageStats } from 'foremanReact/components/PF4/TableIndexPage/Table/helpers';
20
21
  import { STATUS } from 'foremanReact/constants';
21
22
  import { useAPI } from 'foremanReact/common/hooks/API/APIHooks';
23
+ import { useForemanHostDetailsPageUrl } from 'foremanReact/Root/Context/ForemanContext';
22
24
 
23
25
  import OpenscapRemediationWizardContext from '../OpenscapRemediationWizardContext';
24
26
  import WizardHeader from '../WizardHeader';
@@ -158,11 +160,19 @@ const ReviewHosts = () => {
158
160
  rowData: PropTypes.object.isRequired,
159
161
  };
160
162
 
163
+ const hostDetailsURL = useForemanHostDetailsPageUrl();
161
164
  const columns = {
162
165
  name: {
163
166
  title: __('Name'),
164
- wrapper: ({ id, display_name: displayName }) => (
165
- <a href={foremanUrl(`hosts/${id}`)}>{displayName}</a>
167
+ wrapper: ({ name, display_name: displayName }) => (
168
+ <Button
169
+ component="a"
170
+ variant="link"
171
+ target="_blank"
172
+ href={foremanUrl(`${hostDetailsURL}${name}`)}
173
+ >
174
+ {displayName}
175
+ </Button>
166
176
  ),
167
177
  isSorted: true,
168
178
  weight: 50,
@@ -16,12 +16,15 @@ import { ExternalLinkSquareAltIcon } from '@patternfly/react-icons';
16
16
 
17
17
  import { translate as __ } from 'foremanReact/common/I18n';
18
18
  import { foremanUrl } from 'foremanReact/common/helpers';
19
- import { getHostsPageUrl } from 'foremanReact/Root/Context/ForemanContext';
19
+ import {
20
+ useForemanHostsPageUrl,
21
+ useForemanHostDetailsPageUrl,
22
+ } from 'foremanReact/Root/Context/ForemanContext';
20
23
 
21
24
  import OpenscapRemediationWizardContext from '../OpenscapRemediationWizardContext';
22
25
  import WizardHeader from '../WizardHeader';
23
26
  import ViewSelectedHostsLink from '../ViewSelectedHostsLink';
24
- import { HOSTS_PATH, FAIL_RULE_SEARCH } from '../constants';
27
+ import { FAIL_RULE_SEARCH } from '../constants';
25
28
  import { findFixBySnippet } from '../helpers';
26
29
 
27
30
  import './ReviewRemediation.scss';
@@ -120,7 +123,7 @@ const ReviewRemediation = () => {
120
123
  iconPosition="right"
121
124
  target="_blank"
122
125
  component="a"
123
- href={foremanUrl(`${getHostsPageUrl(true)}/${hostName}`)}
126
+ href={foremanUrl(`${useForemanHostDetailsPageUrl()}${hostName}`)}
124
127
  >
125
128
  {hostName}
126
129
  </Button>{' '}
@@ -133,7 +136,7 @@ const ReviewRemediation = () => {
133
136
  target="_blank"
134
137
  component="a"
135
138
  href={foremanUrl(
136
- `${HOSTS_PATH}/?search=${FAIL_RULE_SEARCH} = ${source}`
139
+ `${useForemanHostsPageUrl()}?search=${FAIL_RULE_SEARCH} = ${source}`
137
140
  )}
138
141
  >
139
142
  {__('Other hosts failing this rule')}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_openscap
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.1
4
+ version: 8.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - slukasik@redhat.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-15 00:00:00.000000000 Z
11
+ date: 2024-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -105,7 +105,6 @@ files:
105
105
  - app/helpers/policies_helper.rb
106
106
  - app/helpers/policy_dashboard_helper.rb
107
107
  - app/helpers/tailoring_files_helper.rb
108
- - app/lib/proxy_api/available_proxy.rb
109
108
  - app/lib/proxy_api/migration.rb
110
109
  - app/lib/proxy_api/openscap.rb
111
110
  - app/mailers/foreman_openscap/policy_mailer.rb
@@ -1,44 +0,0 @@
1
- module ::ProxyAPI
2
- class AvailableProxy
3
- HTTP_ERRORS = [
4
- EOFError,
5
- Errno::ECONNRESET,
6
- Errno::EINVAL,
7
- Net::HTTPBadResponse,
8
- Net::HTTPHeaderSyntaxError,
9
- Net::ProtocolError,
10
- Timeout::Error,
11
- ProxyAPI::ProxyException
12
- ].freeze
13
-
14
- def initialize(args)
15
- @args = args
16
- end
17
-
18
- def available?
19
- begin
20
- return true if has_scap_feature? && minimum_version
21
- rescue *HTTP_ERRORS
22
- return false
23
- end
24
- false
25
- end
26
-
27
- private
28
-
29
- def has_scap_feature?
30
- @features ||= ::ProxyAPI::Features.new(@args).features
31
- @features.include?('openscap')
32
- end
33
-
34
- def openscap_proxy_version
35
- @versions ||= ::ProxyAPI::Version.new(@args).proxy_versions['modules']
36
- @versions['openscap'] if @versions && @versions['openscap']
37
- end
38
-
39
- def minimum_version
40
- return false unless openscap_proxy_version
41
- openscap_proxy_version.to_f >= 0.5
42
- end
43
- end
44
- end