foreman_rh_cloud 5.0.35 → 5.0.38

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/rh_cloud/cloud_request_controller.rb +1 -1
  3. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +0 -7
  4. data/app/controllers/foreman_inventory_upload/uploads_settings_controller.rb +0 -1
  5. data/app/controllers/insights_cloud/hits_controller.rb +0 -1
  6. data/app/controllers/insights_cloud/settings_controller.rb +0 -8
  7. data/app/controllers/insights_cloud/tasks_controller.rb +1 -1
  8. data/app/models/insights_facet.rb +1 -0
  9. data/app/models/insights_hit.rb +1 -0
  10. data/app/models/insights_rule.rb +2 -0
  11. data/app/models/setting/rh_cloud.rb +1 -2
  12. data/app/services/foreman_rh_cloud/cert_auth.rb +22 -0
  13. data/app/services/foreman_rh_cloud/cloud_connector.rb +10 -1
  14. data/app/services/foreman_rh_cloud/cloud_ping_service.rb +0 -27
  15. data/app/services/foreman_rh_cloud/hit_remediations_retriever.rb +4 -0
  16. data/app/services/foreman_rh_cloud/remediations_retriever.rb +7 -3
  17. data/app/services/foreman_rh_cloud/template_renderer_helper.rb +4 -3
  18. data/app/services/foreman_rh_cloud/url_remediations_retriever.rb +6 -1
  19. data/app/views/job_templates/cloud_connector.erb +6 -0
  20. data/app/views/job_templates/rh_cloud_download_playbook.erb +5 -1
  21. data/config/routes.rb +0 -1
  22. data/db/migrate/20220321000001_add_unique_to_insights_rules.foreman_rh_cloud.rb +13 -0
  23. data/lib/foreman_inventory_upload.rb +1 -1
  24. data/lib/foreman_rh_cloud/engine.rb +1 -1
  25. data/lib/foreman_rh_cloud/version.rb +1 -1
  26. data/lib/foreman_rh_cloud.rb +0 -5
  27. data/lib/insights_cloud/async/cloud_connector_announce_task.rb +44 -0
  28. data/lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb +7 -1
  29. data/lib/insights_cloud/async/insights_full_sync.rb +40 -24
  30. data/lib/insights_cloud/async/insights_resolutions_sync.rb +10 -13
  31. data/lib/insights_cloud/async/insights_rules_sync.rb +27 -19
  32. data/lib/insights_cloud/async/insights_scheduled_sync.rb +1 -1
  33. data/lib/insights_cloud.rb +4 -8
  34. data/lib/inventory_sync/async/host_result.rb +3 -2
  35. data/lib/inventory_sync/async/inventory_full_sync.rb +3 -3
  36. data/lib/inventory_sync/async/inventory_hosts_sync.rb +11 -10
  37. data/lib/inventory_sync/async/inventory_self_host_sync.rb +5 -6
  38. data/lib/inventory_sync/async/query_inventory_job.rb +40 -12
  39. data/lib/tasks/insights.rake +1 -1
  40. data/package.json +6 -6
  41. data/test/controllers/insights_cloud/api/cloud_request_controller_test.rb +0 -1
  42. data/test/controllers/inventory_upload/cloud_status_controller_test.rb +0 -6
  43. data/test/jobs/cloud_connector_announce_task_test.rb +125 -0
  44. data/test/jobs/insights_full_sync_test.rb +9 -5
  45. data/test/jobs/insights_resolutions_sync_test.rb +7 -1
  46. data/test/jobs/insights_rules_sync_test.rb +8 -4
  47. data/test/jobs/inventory_full_sync_test.rb +16 -5
  48. data/test/jobs/inventory_hosts_sync_test.rb +18 -4
  49. data/test/jobs/inventory_self_host_sync_test.rb +6 -1
  50. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +0 -1
  51. data/test/unit/services/foreman_rh_cloud/cloud_status_service_test.rb +1 -14
  52. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +5 -1
  53. data/test/unit/services/foreman_rh_cloud/url_remediations_retriever_test.rb +3 -1
  54. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettingsSelectors.js +0 -2
  55. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.js +1 -10
  56. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +3 -12
  57. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButton.test.js +1 -1
  58. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButton.test.js.snap +0 -4
  59. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/index.js +0 -2
  60. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +0 -3
  61. data/webpack/InsightsCloudSync/Components/InsightsTable/Pagination.js +16 -0
  62. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableSelectors.test.js +0 -2
  63. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableSelectors.test.js.snap +0 -2
  64. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/fixtures.js +0 -1
  65. data/webpack/InsightsCloudSync/InsightsCloudSync.js +1 -17
  66. data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +0 -7
  67. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -4
  68. data/webpack/InsightsCloudSync/InsightsCloudSyncHelpers.js +0 -7
  69. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +0 -9
  70. data/webpack/InsightsCloudSync/index.js +1 -5
  71. metadata +7 -9
  72. data/app/services/foreman_rh_cloud/cloud_auth.rb +0 -44
  73. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.scss +0 -5
  74. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Modal.js +0 -63
  75. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/modal.scss +0 -20
  76. data/webpack/InsightsCloudSync/Components/NoTokenEmptyState.js +0 -79
  77. data/webpack/InsightsCloudSync/Components/__tests__/NoTokenEmptyState.test.js +0 -19
  78. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +0 -225
@@ -1,44 +0,0 @@
1
- module ForemanRhCloud
2
- module CloudAuth
3
- extend ActiveSupport::Concern
4
-
5
- include CloudRequest
6
-
7
- def cloud_auth_available?
8
- Setting[:rh_cloud_token].present?
9
- end
10
-
11
- def rh_credentials
12
- @rh_credentials ||= query_refresh_token
13
- end
14
-
15
- def query_refresh_token
16
- token_response = RestClient::Request.execute(
17
- method: :post,
18
- url: ForemanRhCloud.authentication_url,
19
- verify_ssl: ForemanRhCloud.verify_ssl_method,
20
- proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
21
- payload: {
22
- grant_type: 'refresh_token',
23
- client_id: 'rhsm-api',
24
- refresh_token: Setting[:rh_cloud_token],
25
- }
26
- )
27
-
28
- JSON.parse(token_response)['access_token']
29
- rescue RestClient::ExceptionWithResponse => e
30
- Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
31
- raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
32
- end
33
-
34
- def execute_cloud_request(params)
35
- final_params = {
36
- headers: {
37
- Authorization: "Bearer #{rh_credentials}",
38
- },
39
- }.deep_merge(params)
40
-
41
- super(final_params)
42
- end
43
- end
44
- end
@@ -1,5 +0,0 @@
1
- #cloud-ping-modal {
2
- .token-status {
3
- margin-bottom: 24px;
4
- }
5
- }
@@ -1,63 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { Icon, Modal, Grid, Button } from 'patternfly-react';
4
- import { translate as __ } from 'foremanReact/common/I18n';
5
- import { foremanUrl } from '../../../../../../ForemanRhCloudHelpers';
6
- import './modal.scss';
7
-
8
- const SyncModal = ({ show, toggleModal }) => (
9
- <Modal show={show} onHide={toggleModal} id="inventory-sync-modal">
10
- <Modal.Header>
11
- <button
12
- className="close"
13
- onClick={toggleModal}
14
- aria-hidden="true"
15
- aria-label="Close"
16
- >
17
- <Icon type="pf" name="close" />
18
- </button>
19
- <Modal.Title>{__('Token is required')}</Modal.Title>
20
- </Modal.Header>
21
- <Modal.Body>
22
- <Grid>
23
- <p>
24
- {__(`Please go over the following steps to add a Red Hat API token:`)}
25
- </p>
26
- <p>
27
- {__(`1. Obtain an Red Hat API token: `)}
28
- <a
29
- href="https://access.redhat.com/management/api"
30
- target="_blank"
31
- rel="noopener noreferrer"
32
- >
33
- access.redhat.com <Icon name="external-link" />
34
- </a>
35
- <br />
36
- {__("2. Copy the token to 'Red Hat Cloud token' setting: ")}
37
- <a
38
- href={foremanUrl('/settings?search=name+%3D+rh_cloud_token')}
39
- target="_blank"
40
- rel="noopener noreferrer"
41
- >
42
- {__('Red Hat Cloud token ')}
43
- <Icon name="external-link" />
44
- </a>
45
- <br />
46
- {__(
47
- '3. Now you can synchronize inventory status manually, by clicking the "Sync inventory status" button.'
48
- )}
49
- </p>
50
- <Button bsStyle="primary" bsSize="lg" onClick={toggleModal}>
51
- {__('Close')}
52
- </Button>
53
- </Grid>
54
- </Modal.Body>
55
- </Modal>
56
- );
57
-
58
- SyncModal.propTypes = {
59
- show: PropTypes.bool.isRequired,
60
- toggleModal: PropTypes.func.isRequired,
61
- };
62
-
63
- export default SyncModal;
@@ -1,20 +0,0 @@
1
- #inventory-sync-modal {
2
- height: 300px;
3
- margin: auto;
4
- overflow: hidden;
5
-
6
- .modal-content {
7
- width: 700px;
8
- }
9
-
10
- .modal-body {
11
- .container {
12
- padding: 0;
13
-
14
- button {
15
- float: right;
16
- margin-top: 10px;
17
- }
18
- }
19
- }
20
- }
@@ -1,79 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { useDispatch } from 'react-redux';
3
- import {
4
- Button,
5
- TextInput,
6
- FormGroup,
7
- GridItem,
8
- Grid,
9
- EmptyState,
10
- EmptyStateIcon,
11
- EmptyStateVariant,
12
- EmptyStateBody,
13
- } from '@patternfly/react-core';
14
- import { ExternalLinkAltIcon, RocketIcon } from '@patternfly/react-icons';
15
- import { post } from 'foremanReact/redux/API';
16
- import { translate as __ } from 'foremanReact/common/I18n';
17
- import { INSIGHTS_SAVE_AND_SYNC_PATH } from '../InsightsCloudSyncConstants';
18
- import { INSIGHTS_HITS_API_KEY } from './InsightsTable/InsightsTableConstants';
19
-
20
- export const NoTokenEmptyState = () => {
21
- const [token, setToken] = useState('');
22
- const dispatch = useDispatch();
23
- const onSave = () => {
24
- dispatch(
25
- post({
26
- key: INSIGHTS_HITS_API_KEY,
27
- url: INSIGHTS_SAVE_AND_SYNC_PATH,
28
- params: { value: token },
29
- })
30
- );
31
- };
32
- return (
33
- <EmptyState variant={EmptyStateVariant.xl}>
34
- <EmptyStateIcon icon={RocketIcon} />
35
- <EmptyStateBody>
36
- <p>
37
- {__(`Insights synchronization process is used to provide Insights
38
- recommendations output for hosts managed here`)}
39
- </p>
40
- <p>
41
- {__(
42
- `To use recommendations please add a token to 'Red Hat Cloud token' setting here or in the settings page`
43
- )}
44
- <br />
45
- {__(`You can obtain a Red Hat API token here: `)}
46
- <a
47
- href="https://access.redhat.com/management/api"
48
- target="_blank"
49
- rel="noopener noreferrer"
50
- >
51
- access.redhat.com <ExternalLinkAltIcon />
52
- </a>
53
- <br />
54
- </p>
55
-
56
- <br />
57
- <FormGroup
58
- label={__('Red Hat Cloud token:')}
59
- fieldId="input-cloud-token"
60
- >
61
- <Grid>
62
- <GridItem span={3} />
63
- <GridItem span={6}>
64
- <TextInput
65
- value={token}
66
- type="password"
67
- onChange={newValue => setToken(newValue)}
68
- aria-label="input-cloud-token"
69
- />
70
- </GridItem>
71
- </Grid>
72
- </FormGroup>
73
- </EmptyStateBody>
74
- <Button variant="primary" onClick={onSave} isDisabled={!token.length}>
75
- {__('Save setting and sync recommendations')}
76
- </Button>
77
- </EmptyState>
78
- );
79
- };
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
- import { mount } from '@theforeman/test';
3
- import { Provider } from 'react-redux';
4
- import configureMockStore from 'redux-mock-store';
5
-
6
- import { NoTokenEmptyState } from '../NoTokenEmptyState';
7
-
8
- const mockStore = configureMockStore();
9
- const store = mockStore({});
10
- describe('NoTokenEmptyState', () => {
11
- it('render', () => {
12
- const component = mount(
13
- <Provider store={store}>
14
- <NoTokenEmptyState />
15
- </Provider>
16
- );
17
- expect(component).toMatchSnapshot();
18
- });
19
- });
@@ -1,225 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`NoTokenEmptyState render 1`] = `
4
- <Provider
5
- store={
6
- Object {
7
- "clearActions": [Function],
8
- "dispatch": [Function],
9
- "getActions": [Function],
10
- "getState": [Function],
11
- "replaceReducer": [Function],
12
- "subscribe": [Function],
13
- }
14
- }
15
- >
16
- <NoTokenEmptyState>
17
- <EmptyState
18
- variant="xl"
19
- >
20
- <div
21
- className="pf-c-empty-state pf-m-xl"
22
- >
23
- <div
24
- className="pf-c-empty-state__content"
25
- >
26
- <EmptyStateIcon
27
- icon={[Function]}
28
- >
29
- <RocketIcon
30
- aria-hidden="true"
31
- className="pf-c-empty-state__icon"
32
- color="currentColor"
33
- noVerticalAlign={false}
34
- size="sm"
35
- >
36
- <svg
37
- aria-hidden="true"
38
- aria-labelledby={null}
39
- className="pf-c-empty-state__icon"
40
- fill="currentColor"
41
- height="1em"
42
- role="img"
43
- style={
44
- Object {
45
- "verticalAlign": "-0.125em",
46
- }
47
- }
48
- viewBox="0 0 512 512"
49
- width="1em"
50
- >
51
- <path
52
- d="M505.12019,19.09375c-1.18945-5.53125-6.65819-11-12.207-12.1875C460.716,0,435.507,0,410.40747,0,307.17523,0,245.26909,55.20312,199.05238,128H94.83772c-16.34763.01562-35.55658,11.875-42.88664,26.48438L2.51562,253.29688A28.4,28.4,0,0,0,0,264a24.00867,24.00867,0,0,0,24.00582,24H127.81618l-22.47457,22.46875c-11.36521,11.36133-12.99607,32.25781,0,45.25L156.24582,406.625c11.15623,11.1875,32.15619,13.15625,45.27726,0l22.47457-22.46875V488a24.00867,24.00867,0,0,0,24.00581,24,28.55934,28.55934,0,0,0,10.707-2.51562l98.72834-49.39063c14.62888-7.29687,26.50776-26.5,26.50776-42.85937V312.79688c72.59753-46.3125,128.03493-108.40626,128.03493-211.09376C512.07526,76.5,512.07526,51.29688,505.12019,19.09375ZM384.04033,168A40,40,0,1,1,424.05,128,40.02322,40.02322,0,0,1,384.04033,168Z"
53
- />
54
- </svg>
55
- </RocketIcon>
56
- </EmptyStateIcon>
57
- <EmptyStateBody>
58
- <div
59
- className="pf-c-empty-state__body"
60
- >
61
- <p>
62
- Insights synchronization process is used to provide Insights
63
- recommendations output for hosts managed here
64
- </p>
65
- <p>
66
- To use recommendations please add a token to 'Red Hat Cloud token' setting here or in the settings page
67
- <br />
68
- You can obtain a Red Hat API token here:
69
- <a
70
- href="https://access.redhat.com/management/api"
71
- rel="noopener noreferrer"
72
- target="_blank"
73
- >
74
- access.redhat.com
75
- <ExternalLinkAltIcon
76
- color="currentColor"
77
- noVerticalAlign={false}
78
- size="sm"
79
- >
80
- <svg
81
- aria-hidden={true}
82
- aria-labelledby={null}
83
- fill="currentColor"
84
- height="1em"
85
- role="img"
86
- style={
87
- Object {
88
- "verticalAlign": "-0.125em",
89
- }
90
- }
91
- viewBox="0 0 512 512"
92
- width="1em"
93
- >
94
- <path
95
- d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"
96
- />
97
- </svg>
98
- </ExternalLinkAltIcon>
99
- </a>
100
- <br />
101
- </p>
102
- <br />
103
- <FormGroup
104
- fieldId="input-cloud-token"
105
- label="Red Hat Cloud token:"
106
- >
107
- <div
108
- className="pf-c-form__group"
109
- >
110
- <div
111
- className="pf-c-form__group-label"
112
- >
113
- <label
114
- className="pf-c-form__label"
115
- htmlFor="input-cloud-token"
116
- >
117
- <span
118
- className="pf-c-form__label-text"
119
- >
120
- Red Hat Cloud token:
121
- </span>
122
- </label>
123
-
124
- </div>
125
- <div
126
- className="pf-c-form__group-control"
127
- >
128
- <Grid>
129
- <div
130
- className="pf-l-grid"
131
- >
132
- <GridItem
133
- span={3}
134
- >
135
- <div
136
- className="pf-l-grid__item pf-m-3-col"
137
- />
138
- </GridItem>
139
- <GridItem
140
- span={6}
141
- >
142
- <div
143
- className="pf-l-grid__item pf-m-6-col"
144
- >
145
- <TextInput
146
- aria-label="input-cloud-token"
147
- onChange={[Function]}
148
- type="password"
149
- value=""
150
- >
151
- <TextInputBase
152
- aria-label="input-cloud-token"
153
- className=""
154
- innerRef={null}
155
- isDisabled={false}
156
- isLeftTruncated={false}
157
- isReadOnly={false}
158
- isRequired={false}
159
- onChange={[Function]}
160
- ouiaSafe={true}
161
- type="password"
162
- validated="default"
163
- value=""
164
- >
165
- <input
166
- aria-invalid={false}
167
- aria-label="input-cloud-token"
168
- className="pf-c-form-control"
169
- data-ouia-component-id="OUIA-Generated-TextInputBase-1"
170
- data-ouia-component-type="PF4/TextInput"
171
- data-ouia-safe={true}
172
- disabled={false}
173
- onBlur={[Function]}
174
- onChange={[Function]}
175
- onFocus={[Function]}
176
- readOnly={false}
177
- required={false}
178
- type="password"
179
- value=""
180
- />
181
- </TextInputBase>
182
- </TextInput>
183
- </div>
184
- </GridItem>
185
- </div>
186
- </Grid>
187
- </div>
188
- </div>
189
- </FormGroup>
190
- </div>
191
- </EmptyStateBody>
192
- <Button
193
- isDisabled={true}
194
- onClick={[Function]}
195
- variant="primary"
196
- >
197
- <ButtonBase
198
- innerRef={null}
199
- isDisabled={true}
200
- onClick={[Function]}
201
- variant="primary"
202
- >
203
- <button
204
- aria-disabled={true}
205
- aria-label={null}
206
- className="pf-c-button pf-m-primary pf-m-disabled"
207
- data-ouia-component-id="OUIA-Generated-Button-primary-1"
208
- data-ouia-component-type="PF4/Button"
209
- data-ouia-safe={true}
210
- disabled={true}
211
- onClick={[Function]}
212
- role={null}
213
- tabIndex={null}
214
- type="button"
215
- >
216
- Save setting and sync recommendations
217
- </button>
218
- </ButtonBase>
219
- </Button>
220
- </div>
221
- </div>
222
- </EmptyState>
223
- </NoTokenEmptyState>
224
- </Provider>
225
- `;