foreman_rh_cloud 1.0.7 → 2.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/app/controllers/foreman_inventory_upload/accounts_controller.rb +1 -0
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +22 -3
- data/app/controllers/foreman_rh_cloud/react_controller.rb +3 -0
- data/app/controllers/insights_cloud/tasks_controller.rb +8 -0
- data/app/helpers/foreman_inventory_upload_host_helper.rb +11 -0
- data/app/models/insights_facet.rb +3 -0
- data/app/models/insights_hit.rb +6 -0
- data/app/models/setting/rh_cloud.rb +1 -0
- data/app/overrides/hosts_list.rb +13 -0
- data/app/views/foreman_rh_cloud/react/insights_cloud.html.erb +1 -0
- data/config/routes.rb +7 -0
- data/db/migrate/20191215104806_create_insights_hits.foreman_inventory_upload.rb +14 -0
- data/db/migrate/20191216062008_create_insights_facets.foreman_inventory_upload.rb +7 -0
- data/lib/foreman_inventory_upload/async/upload_report_job.rb +1 -5
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +1 -1
- data/lib/foreman_inventory_upload/generators/slice.rb +1 -0
- data/lib/foreman_inventory_upload/notifications/manifest_import_success_notification_override.rb +19 -0
- data/lib/foreman_rh_cloud/engine.rb +22 -10
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud.rb +15 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +92 -0
- data/package.json +20 -100
- data/test/factories/inventory_upload_factories.rb +13 -13
- data/test/jobs/insights_full_sync_test.rb +62 -0
- data/test/unit/slice_generator_test.rb +10 -3
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +6 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.stories.js +5 -14
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +2 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +9 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +7 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/EmptyResults.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/EmptyState.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/ErrorState.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/ListItem.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/ListItemStatus.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +9 -2
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +12 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +8 -3
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +20 -2
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +10 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +3 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.js +6 -6
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcher.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcher.test.js.snap +9 -9
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/autoUploadSwitcher.scss +1 -1
- data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.fixtures.js +13 -9
- data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.stories.js +5 -15
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/Dashboard.test.js +1 -2
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +17 -4
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardIntegration.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardReducer.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +3 -3
- data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/FileDownload.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/FullScreenModal.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.fixtures.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +29 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +30 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherConstants.js +3 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcher.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcher.test.js.snap +38 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcherActions.test.js.snap +14 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/hostObfuscationSwitcher.scss +0 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/index.js +20 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilter.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterActions.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterReducer.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterSelectors.test.js +3 -3
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/integration.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +15 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettings.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +13 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/inventorySettings.scss +15 -0
- data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.fixtures.js +5 -2
- data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/NavContainer.test.js +1 -2
- data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/__snapshots__/NavContainer.test.js.snap +1 -1
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +14 -4
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageHeader.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +22 -3
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/DocsButton.js +17 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/DocsButton.test.js +12 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/__snapshots__/DocsButton.test.js.snap +20 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/HistoryButton.js +18 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/HistoryButton.test.js +12 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/__snapshots__/HistoryButton.test.js.snap +21 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +24 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/PageDescription.test.js +11 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +17 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +12 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +10 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/toolbarButtons.scss +7 -0
- data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/ReportGenerate.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/ReportUpload.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/StatusChart.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/TabBody.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/TabContainer.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/TabFooter.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/TabHeader.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +1 -2
- data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +4 -0
- data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +13 -0
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/SubscriptionsPageExtensionActions.js +34 -0
- data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryHelpers.test.js +3 -4
- data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryUpload.test.js +1 -1
- data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +2 -0
- data/webpack/ForemanRhCloudReducers.js +2 -0
- data/webpack/ForemanRhCloudSelectors.js +2 -0
- data/webpack/ForemanRhCloudTestHelpers.js +2 -1
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +26 -0
- data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +13 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +23 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +6 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncHelpers.js +3 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncReducers.js +3 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +25 -0
- data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncHelpers.test.js +9 -0
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncHelpers.test.js.snap +3 -0
- data/webpack/InsightsCloudSync/index.js +17 -0
- data/webpack/__tests__/ForemanRhCloudHelpers.test.js +1 -1
- data/webpack/__tests__/ForemanRhCloudSelectors.test.js +5 -3
- data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +3 -3
- data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +9 -0
- data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +3 -0
- data/webpack/index.js +7 -0
- data/webpack/subscriptions_extension_index.js +8 -0
- metadata +59 -9
- data/webpack/stories/ForemanInventoryUploadReducers.js +0 -3
- data/webpack/stories/configureStore.js +0 -15
- data/webpack/stories/decorators/index.js +0 -1
- data/webpack/stories/decorators/withCardsDecorator.js +0 -14
- data/webpack/stories/index.js +0 -10
- data/webpack/stories/index.scss +0 -7
- data/webpack/test_setup.js +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b4d5750b4b0ff6361c7694fb3808a4c33d5ff12e37bd5d946c1baa454b805a1
|
4
|
+
data.tar.gz: 5e18ea289049d0525a82adb8f7cbeec66d5ac4abf2cae5867aa18c3aab753640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e9b9c292ed88641c954bc79d665c7f3e77a0c04e426bde5e12d92e25d53b72ef7ade25a69b08da5f20442c3a4a41a7d8854dac529108376eae49b188c1eb839
|
7
|
+
data.tar.gz: 94998762071b568f438dd03c37f22c969a55cc2c71410bf60c2b4e21ebda259e1e20a85d6a821324014d98683f1b928cce4fe94e39a0a4f8f34dd338237252ed
|
data/README.md
CHANGED
@@ -11,6 +11,14 @@ for how to install Foreman plugins
|
|
11
11
|
|
12
12
|
*Usage here*
|
13
13
|
|
14
|
+
### In Satellite
|
15
|
+
|
16
|
+
Normally you run it via UI in RH Cloud -> Inventory Upload -> Restart, but if you need to run from command-line for some reason:
|
17
|
+
|
18
|
+
export organization_id=1
|
19
|
+
export target=/var/lib/foreman/red_hat_inventory/generated_reports/
|
20
|
+
/usr/sbin/foreman-rake foreman_inventory_upload:report:generate
|
21
|
+
|
14
22
|
## TODO
|
15
23
|
|
16
24
|
*Todo list here*
|
@@ -26,13 +26,32 @@ module ForemanInventoryUpload
|
|
26
26
|
|
27
27
|
def auto_upload
|
28
28
|
Setting[:allow_auto_inventory_upload] = auto_upload_params
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
render_setting(:autoUploadEnabled, :allow_auto_inventory_upload)
|
30
|
+
end
|
31
|
+
|
32
|
+
def show_auto_upload
|
33
|
+
render_setting(:autoUploadEnabled, :allow_auto_inventory_upload)
|
32
34
|
end
|
33
35
|
|
34
36
|
def auto_upload_params
|
35
37
|
ActiveModel::Type::Boolean.new.cast(params.require(:value))
|
36
38
|
end
|
39
|
+
|
40
|
+
def host_obfuscation
|
41
|
+
Setting[:obfuscate_inventory_hostnames] = host_obfuscation_params
|
42
|
+
render_setting(:hostObfuscationEnabled, :obfuscate_inventory_hostnames)
|
43
|
+
end
|
44
|
+
|
45
|
+
def host_obfuscation_params
|
46
|
+
ActiveModel::Type::Boolean.new.cast(params.require(:value))
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def render_setting(node_name, setting)
|
52
|
+
render json: {
|
53
|
+
node_name => Setting[setting],
|
54
|
+
}
|
55
|
+
end
|
37
56
|
end
|
38
57
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module ForemanInventoryUploadHostHelper
|
2
|
+
def hits_counts
|
3
|
+
@hits_counts ||= InsightsHit.where(host_id: @hosts).group(:host_id).count
|
4
|
+
end
|
5
|
+
|
6
|
+
def hits_counts_cell(host)
|
7
|
+
host_hits = hits_counts[host.id]
|
8
|
+
content = n_('One recommendation', '%{hits} recommendations', host_hits) % { hits: host_hits } if host_hits
|
9
|
+
tag.td content, class: ['hidden-xs', 'ellipsis']
|
10
|
+
end
|
11
|
+
end
|
@@ -5,6 +5,7 @@ class Setting::RhCloud < Setting
|
|
5
5
|
[
|
6
6
|
set('allow_auto_inventory_upload', N_('Allow automatic upload of the host inventory to the Red Hat cloud'), true),
|
7
7
|
set('obfuscate_inventory_hostnames', N_('Obfuscate host names sent to Red Hat cloud'), false),
|
8
|
+
set('rh_cloud_token', N_('Authentication token to Red Hat cloud services. Used to authenticate requests to cloud APIs'), 'DEFAULT', N_('Red Hat Cloud token'), nil, encrypted: true),
|
8
9
|
]
|
9
10
|
end
|
10
11
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'hosts/_list',
|
3
|
+
name: 'insights_hits_header',
|
4
|
+
insert_before: 'thead tr th.hidden-xs:first-of-type',
|
5
|
+
text: '<th class="hidden-xs" width="10%"><%= _("Insights")%></th>'
|
6
|
+
)
|
7
|
+
|
8
|
+
Deface::Override.new(
|
9
|
+
virtual_path: 'hosts/_list',
|
10
|
+
name: 'insights_hits_cells',
|
11
|
+
insert_before: 'tbody tr td.hidden-xs:first-of-type',
|
12
|
+
text: '<%= hits_counts_cell(host) %>'
|
13
|
+
)
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= mount_react_component('InsightsCloudSync', '#ForemanRhCloudReactRoot') %>
|
data/config/routes.rb
CHANGED
@@ -5,10 +5,17 @@ Rails.application.routes.draw do
|
|
5
5
|
get ':organization_id/uploads/last', to: 'uploads#last', constraints: { organization_id: %r{[^\/]+} }
|
6
6
|
get ':organization_id/uploads/file', to: 'uploads#download_file', constraints: { organization_id: %r{[^\/]+} }
|
7
7
|
get 'accounts', to: 'accounts#index'
|
8
|
+
get 'auto_upload', to: 'uploads#show_auto_upload'
|
8
9
|
post 'auto_upload', to: 'uploads#auto_upload'
|
10
|
+
post 'host_obfuscation', to: 'uploads#host_obfuscation'
|
11
|
+
end
|
12
|
+
|
13
|
+
namespace :insights_cloud do
|
14
|
+
resources :tasks, only: [:create]
|
9
15
|
end
|
10
16
|
|
11
17
|
namespace :foreman_rh_cloud do
|
12
18
|
get 'inventory_upload', to: 'react#inventory_upload'
|
19
|
+
get 'insights_cloud', to: 'react#insights_cloud'
|
13
20
|
end
|
14
21
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateInsightsHits < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :insights_hits do |t|
|
4
|
+
t.references :host, foreign_key: true, null: false
|
5
|
+
t.datetime :last_seen
|
6
|
+
t.string :title
|
7
|
+
t.string :solution_url
|
8
|
+
t.integer :total_risk
|
9
|
+
t.integer :likelihood
|
10
|
+
t.datetime :publish_date
|
11
|
+
t.string :results_url
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -37,11 +37,7 @@ module ForemanInventoryUpload
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def http_proxy_string
|
40
|
-
@http_proxy_string ||=
|
41
|
-
if Setting[:content_default_http_proxy]
|
42
|
-
HttpProxy.unscoped.find_by(name: Setting[:content_default_http_proxy])&.full_url
|
43
|
-
end
|
44
|
-
end
|
40
|
+
@http_proxy_string ||= HttpProxy.default_global_content_proxy&.full_url
|
45
41
|
end
|
46
42
|
|
47
43
|
def rh_credentials
|
@@ -157,6 +157,7 @@ module ForemanInventoryUpload
|
|
157
157
|
@stream.simple_field('distribution_version', fact_value(host, 'distribution::version'))
|
158
158
|
@stream.simple_field('satellite_instance_id', Foreman.try(:instance_id))
|
159
159
|
@stream.simple_field('is_simple_content_access', golden_ticket?(host.organization))
|
160
|
+
@stream.simple_field('is_hostname_obfuscated', !!obfuscate_hostname?(host))
|
160
161
|
@stream.simple_field('organization_id', host.organization_id, :last)
|
161
162
|
end
|
162
163
|
|
data/lib/foreman_inventory_upload/notifications/manifest_import_success_notification_override.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
module Notifications
|
3
|
+
module ManifestImportSuccessNotificationOverride
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def actions
|
7
|
+
{
|
8
|
+
:links => [
|
9
|
+
{
|
10
|
+
:href => Rails.application.routes.url_helpers.foreman_rh_cloud_inventory_upload_path,
|
11
|
+
:title => _('Enable inventory upload'),
|
12
|
+
:external => false,
|
13
|
+
},
|
14
|
+
],
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -26,17 +26,21 @@ module ForemanRhCloud
|
|
26
26
|
|
27
27
|
initializer 'foreman_rh_cloud.register_plugin', :before => :finisher_hook do |_app|
|
28
28
|
Foreman::Plugin.register :foreman_rh_cloud do
|
29
|
-
requires_foreman '
|
29
|
+
requires_foreman '> 1.24'
|
30
30
|
|
31
31
|
# Add permissions
|
32
32
|
security_block :foreman_rh_cloud do
|
33
|
-
permission(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
permission(
|
34
|
+
:generate_foreman_rh_cloud,
|
35
|
+
'foreman_inventory_upload/reports': [:generate]
|
36
|
+
)
|
37
|
+
permission(
|
38
|
+
:view_foreman_rh_cloud,
|
39
|
+
'foreman_inventory_upload/accounts': [:index],
|
40
|
+
'foreman_inventory_upload/reports': [:last],
|
41
|
+
'foreman_inventory_upload/uploads': [:auto_upload, :show_auto_upload, :download_file, :last],
|
42
|
+
'foreman_rh_cloud/react': [:inventory_upload]
|
43
|
+
)
|
40
44
|
end
|
41
45
|
|
42
46
|
plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud]
|
@@ -49,10 +53,18 @@ module ForemanRhCloud
|
|
49
53
|
Role::SYSTEM_ADMIN => plugin_permissions
|
50
54
|
|
51
55
|
# Adding a sub menu after hosts menu
|
52
|
-
|
53
|
-
|
56
|
+
divider :top_menu, caption: N_('RH Cloud'), parent: :configure_menu
|
57
|
+
menu :top_menu, :inventory_upload, :caption => N_('Inventory Upload'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :inventory_upload}, parent: :configure_menu
|
58
|
+
menu :top_menu, :insights_hits_import, :caption => N_('Insights'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :insights_cloud }, parent: :configure_menu
|
59
|
+
|
60
|
+
register_facet InsightsFacet, :insights do
|
61
|
+
configure_host
|
54
62
|
end
|
63
|
+
|
64
|
+
register_global_js_file 'subscriptions_extension'
|
55
65
|
end
|
66
|
+
|
67
|
+
::Katello::UINotifications::Subscriptions::ManifestImportSuccess.include ForemanInventoryUpload::Notifications::ManifestImportSuccessNotificationOverride if defined?(Katello)
|
56
68
|
end
|
57
69
|
|
58
70
|
initializer "foreman_rh_cloud.set_dynflow.config.on_init", :before => :finisher_hook do |_app|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module InsightsCloud
|
2
|
+
def self.base_url
|
3
|
+
# for testing set ENV to 'https://ci.cloud.redhat.com'
|
4
|
+
@base_url ||= ENV['SATELLITE_INSIGHTS_CLOUD_URL'] || 'https://cloud.redhat.com'
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.authentication_url
|
8
|
+
# https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
|
9
|
+
@authentication_url ||= ENV['SATELLITE_INSIGHTS_CLOUD_SSO_URL'] || 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.hits_export_url
|
13
|
+
base_url + '/api/insights/v1/export/hits/'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module InsightsCloud
|
4
|
+
module Async
|
5
|
+
class InsightsFullSync < ::ApplicationJob
|
6
|
+
def perform(organization)
|
7
|
+
@organization = organization
|
8
|
+
|
9
|
+
hits = query_insights_hits
|
10
|
+
|
11
|
+
host_names = hits.map { |hit| hit['hostname'] }.uniq
|
12
|
+
setup_host_names(host_names)
|
13
|
+
|
14
|
+
replace_hits_data(hits)
|
15
|
+
end
|
16
|
+
|
17
|
+
def logger
|
18
|
+
Foreman::Logging.logger('background')
|
19
|
+
end
|
20
|
+
|
21
|
+
def rh_credentials
|
22
|
+
@rh_credentials ||= query_refresh_token
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def query_insights_hits
|
28
|
+
hits_response = RestClient::Request.execute(
|
29
|
+
method: :get,
|
30
|
+
url: InsightsCloud.hits_export_url,
|
31
|
+
verify_ssl: ENV['SATELLITE_INSIGHTS_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER,
|
32
|
+
headers: {
|
33
|
+
Authorization: "Bearer #{rh_credentials}",
|
34
|
+
}
|
35
|
+
)
|
36
|
+
|
37
|
+
JSON.parse(hits_response)
|
38
|
+
end
|
39
|
+
|
40
|
+
def query_refresh_token
|
41
|
+
token_response = RestClient::Request.execute(
|
42
|
+
method: :post,
|
43
|
+
url: InsightsCloud.authentication_url,
|
44
|
+
verify_ssl: ENV['SATELLITE_INSIGHTS_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER,
|
45
|
+
payload: {
|
46
|
+
grant_type: 'refresh_token',
|
47
|
+
client_id: 'rhsm-api',
|
48
|
+
refresh_token: Setting[:rh_cloud_token],
|
49
|
+
}
|
50
|
+
)
|
51
|
+
|
52
|
+
JSON.parse(token_response)['access_token']
|
53
|
+
rescue RestClient::ExceptionWithResponse => e
|
54
|
+
Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
|
55
|
+
raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
|
56
|
+
end
|
57
|
+
|
58
|
+
def setup_host_names(host_names)
|
59
|
+
@host_ids = Hash[
|
60
|
+
Host.where(name: host_names).pluck(:name, :id)
|
61
|
+
]
|
62
|
+
end
|
63
|
+
|
64
|
+
def host_id(host_name)
|
65
|
+
@host_ids[host_name]
|
66
|
+
end
|
67
|
+
|
68
|
+
def replace_hits_data(hits)
|
69
|
+
InsightsHit.transaction do
|
70
|
+
InsightsHit.delete_all
|
71
|
+
InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) })
|
72
|
+
# create new facets for hosts that are missing one
|
73
|
+
hosts_with_existing_facets = InsightsFacet.where(host_id: @host_ids.values).pluck(:host_id)
|
74
|
+
InsightsFacet.create((@host_ids.values - hosts_with_existing_facets).map { |id| {host_id: id} })
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_model_hash(hit_hash)
|
79
|
+
{
|
80
|
+
host_id: host_id(hit_hash['hostname']),
|
81
|
+
last_seen: DateTime.parse(hit_hash['last_seen']),
|
82
|
+
publish_date: DateTime.parse(hit_hash['publish_date']),
|
83
|
+
title: hit_hash['title'],
|
84
|
+
solution_url: hit_hash['solution_url'],
|
85
|
+
total_risk: hit_hash['total_risk'].to_i,
|
86
|
+
likelihood: hit_hash['likelihood'].to_i,
|
87
|
+
results_url: hit_hash['results_url'],
|
88
|
+
}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/package.json
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
"description": "Inventory Upload =============",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
7
|
-
"lint": "
|
8
|
-
"test": "
|
9
|
-
"test:watch": "
|
10
|
-
"test:current": "
|
11
|
-
"
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
7
|
+
"lint": "tfm-lint --plugin -d /webpack",
|
8
|
+
"test": "tfm-test --plugin",
|
9
|
+
"test:watch": "tfm-test --plugin --watchAll",
|
10
|
+
"test:current": "tfm-test --plugin --watch",
|
11
|
+
"publish-coverage": "tfm-publish-coverage",
|
12
|
+
"stories": "tfm-stories --plugin",
|
13
|
+
"stories:build": "tfm-build-stories --plugin",
|
14
|
+
"stories:deploy": "surge --project .storybook-dist"
|
15
15
|
},
|
16
16
|
"repository": {
|
17
17
|
"type": "git",
|
@@ -20,106 +20,26 @@
|
|
20
20
|
"bugs": {
|
21
21
|
"url": "http://projects.theforeman.org/projects/foreman_rh_cloud/issues"
|
22
22
|
},
|
23
|
-
"
|
24
|
-
"
|
23
|
+
"peerDependencies": {
|
24
|
+
"@theforeman/vendor": ">= 4.0.2"
|
25
25
|
},
|
26
26
|
"devDependencies": {
|
27
|
-
"@
|
28
|
-
"@
|
29
|
-
"@
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
33
|
-
"babel-
|
34
|
-
"
|
35
|
-
"babel-plugin-dynamic-import-node": "^2.0.0",
|
36
|
-
"babel-plugin-lodash": "^3.3.4",
|
37
|
-
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
38
|
-
"babel-plugin-transform-class-properties": "^6.24.1",
|
39
|
-
"babel-plugin-transform-object-assign": "^6.8.0",
|
40
|
-
"babel-plugin-transform-object-rest-spread": "^6.8.0",
|
41
|
-
"babel-preset-env": "^1.7.0",
|
42
|
-
"babel-preset-react": "^6.5.0",
|
43
|
-
"coveralls": "^3.0.0",
|
44
|
-
"enzyme": "^3.4.0",
|
45
|
-
"enzyme-adapter-react-16": "^1.4.0",
|
46
|
-
"enzyme-to-json": "^3.2.1",
|
47
|
-
"eslint": "^4.10.0",
|
48
|
-
"eslint-import-resolver-babel-module": "^4.0.0",
|
49
|
-
"eslint-plugin-patternfly-react": "0.2.0",
|
50
|
-
"identity-obj-proxy": "^3.0.0",
|
51
|
-
"jed": "^1.1.1",
|
52
|
-
"jest-cli": "^23.6.0",
|
53
|
-
"jest-prop-type-error": "^1.1.0",
|
54
|
-
"node-sass": "^4.5.0",
|
55
|
-
"patternfly": "^3.58.0",
|
27
|
+
"@babel/core": "^7.7.0",
|
28
|
+
"@theforeman/builder": "^4.0.2",
|
29
|
+
"@theforeman/stories": "^4.0.2",
|
30
|
+
"@theforeman/test": "^4.0.2",
|
31
|
+
"@theforeman/vendor-dev": "^4.0.2",
|
32
|
+
"@theforeman/eslint-plugin-foreman": "^4.0.2",
|
33
|
+
"babel-eslint": "^10.0.0",
|
34
|
+
"eslint": "^6.7.2",
|
56
35
|
"prettier": "^1.13.5",
|
57
36
|
"raf": "^3.4.0",
|
58
|
-
"react-redux-test-utils": "^0.1.1",
|
59
|
-
"react-remarkable": "^1.1.3",
|
60
|
-
"sass-loader": "^6.0.7",
|
61
37
|
"stylelint": "^9.3.0",
|
62
38
|
"stylelint-config-standard": "^18.0.0",
|
63
39
|
"surge": "^0.20.3"
|
64
40
|
},
|
65
41
|
"dependencies": {
|
66
|
-
"
|
67
|
-
"
|
68
|
-
"lodash": "^4.17.10",
|
69
|
-
"patternfly-react": "^2.19.1",
|
70
|
-
"prop-types": "^15.6.0",
|
71
|
-
"react": "^16.4.0",
|
72
|
-
"react-dom": "^16.4.0",
|
73
|
-
"react-intl": "^2.8.0",
|
74
|
-
"react-redux": "^5.0.6",
|
75
|
-
"redux": "^3.6.0",
|
76
|
-
"redux-thunk": "^2.2.0",
|
77
|
-
"reselect": "^3.0.1",
|
78
|
-
"seamless-immutable": "^7.1.2",
|
79
|
-
"urijs": "^1.18.10",
|
80
|
-
"uuid": "^3.0.1"
|
81
|
-
},
|
82
|
-
"jest": {
|
83
|
-
"automock": true,
|
84
|
-
"verbose": true,
|
85
|
-
"testMatch": [
|
86
|
-
"**/*.test.js"
|
87
|
-
],
|
88
|
-
"testURL": "http://localhost/",
|
89
|
-
"collectCoverage": true,
|
90
|
-
"collectCoverageFrom": [
|
91
|
-
"webpack/**/*.js",
|
92
|
-
"!webpack/index.js",
|
93
|
-
"!webpack/test_setup.js",
|
94
|
-
"!webpack/**/bundle*",
|
95
|
-
"!webpack/stories/**",
|
96
|
-
"!webpack/**/*stories.js"
|
97
|
-
],
|
98
|
-
"coverageReporters": [
|
99
|
-
"lcov"
|
100
|
-
],
|
101
|
-
"unmockedModulePathPatterns": [
|
102
|
-
"webpack/",
|
103
|
-
"react",
|
104
|
-
"node_modules/"
|
105
|
-
],
|
106
|
-
"moduleNameMapper": {
|
107
|
-
"^.+\\.(png|gif|css|scss)$": "identity-obj-proxy"
|
108
|
-
},
|
109
|
-
"globals": {
|
110
|
-
"__testing__": true
|
111
|
-
},
|
112
|
-
"transform": {
|
113
|
-
"^.+\\.js$": "babel-jest"
|
114
|
-
},
|
115
|
-
"moduleDirectories": [
|
116
|
-
"node_modules",
|
117
|
-
"webpack"
|
118
|
-
],
|
119
|
-
"setupFiles": [
|
120
|
-
"raf/polyfill",
|
121
|
-
"jest-prop-type-error",
|
122
|
-
"./webpack/test_setup.js"
|
123
|
-
]
|
42
|
+
"jed": "^1.1.1",
|
43
|
+
"react-intl": "^2.8.0"
|
124
44
|
}
|
125
45
|
}
|