foreman_rh_cloud 14.7.1 → 15.0.1
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 +4 -4
- data/app/controllers/insights_cloud/ui_requests_controller.rb +11 -0
- data/app/services/foreman_rh_cloud/tags_auth.rb +28 -13
- data/config/routes.rb +10 -0
- data/lib/foreman_rh_cloud/plugin.rb +14 -0
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/package.json +1 -1
- data/test/controllers/insights_cloud/ui_requests_controller_test.rb +147 -2
- data/test/unit/services/foreman_rh_cloud/tags_auth_test.rb +26 -0
- data/webpack/ComplianceHostDetailsTab/ComplianceHostDetailsTab.js +36 -0
- data/webpack/ComplianceHostDetailsTab/ComplianceHostDetailsTab.scss +3 -0
- data/webpack/ComplianceHostDetailsTab/__tests__/ComplianceHostDetailsTab.test.js +159 -0
- data/webpack/ComplianceHostDetailsTab/index.js +3 -0
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/InventoryAutoUpload.js +3 -1
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/InventoryAutoUpload.test.js +23 -0
- data/webpack/ForemanRhCloudFills.js +11 -0
- data/webpack/ForemanRhCloudPages.js +7 -0
- data/webpack/InsightsCompliance/ComplianceIframe.js +34 -0
- data/webpack/InsightsCompliance/ComplianceIframe.scss +12 -0
- data/webpack/InsightsCompliance/InsightsCompliancePage.js +11 -0
- data/webpack/InsightsCompliance/InsightsCompliancePage.test.js +35 -0
- data/webpack/InsightsCompliance/complianceIframeConstants.js +7 -0
- data/webpack/InsightsCompliance/complianceIframeHelpers.js +23 -0
- data/webpack/InsightsCompliance/complianceIframeHelpers.test.js +50 -0
- data/webpack/common/Hooks/PermissionsHooks.js +10 -0
- data/webpack/common/IopIframe/IopAppIframe.js +74 -0
- data/webpack/common/IopIframe/IopHostDetailsIframe.js +66 -0
- data/webpack/common/IopIframe/IopHostDetailsIframe.scss +6 -0
- data/webpack/common/IopIframe/IopHostDetailsIframeTab.js +81 -0
- data/webpack/common/IopIframe/__tests__/IopAppIframe.test.js +92 -0
- data/webpack/common/IopIframe/__tests__/IopHostDetailsIframeTab.test.js +93 -0
- data/webpack/common/IopIframe/__tests__/iopIframeHelpers.test.js +63 -0
- data/webpack/common/IopIframe/__tests__/postIopChromeToIframe.test.js +60 -0
- data/webpack/common/IopIframe/__tests__/useIopIframeHeight.test.js +37 -0
- data/webpack/common/IopIframe/iopIframeConstants.js +5 -0
- data/webpack/common/IopIframe/iopIframeHelpers.js +49 -0
- data/webpack/common/IopIframe/postIopChromeToIframe.js +35 -0
- data/webpack/common/IopIframe/useIopIframeChrome.js +54 -0
- data/webpack/common/IopIframe/useIopIframeHeight.js +35 -0
- data/webpack/common/IopIframe/useIopIframeNavigate.js +40 -0
- metadata +27 -2
- data/lib/tasks/hybrid_cloud.rake +0 -132
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { postIopChromeToIframe } from '../postIopChromeToIframe';
|
|
2
|
+
import { IOP_CHROME_INIT } from '../iopIframeConstants';
|
|
3
|
+
|
|
4
|
+
describe('postIopChromeToIframe', () => {
|
|
5
|
+
it('posts appRoute and embedded mode', () => {
|
|
6
|
+
const postMessage = jest.fn();
|
|
7
|
+
const iframe = { contentWindow: { postMessage } };
|
|
8
|
+
|
|
9
|
+
postIopChromeToIframe(iframe, {
|
|
10
|
+
permissions: [{ permission: 'compliance:policies:read' }],
|
|
11
|
+
pathname: '/new/hosts/demo.example.com',
|
|
12
|
+
appRoute: 'systems/uuid-1',
|
|
13
|
+
embedded: 'host-tab',
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
expect(postMessage).toHaveBeenCalledWith(
|
|
17
|
+
{
|
|
18
|
+
type: IOP_CHROME_INIT,
|
|
19
|
+
payload: {
|
|
20
|
+
user: expect.any(Object),
|
|
21
|
+
permissions: [{ permission: 'compliance:policies:read' }],
|
|
22
|
+
appRoute: 'systems/uuid-1',
|
|
23
|
+
pathname: '/new/hosts/demo.example.com',
|
|
24
|
+
embedded: 'host-tab',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
window.location.origin
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('omits embedded from payload when not provided', () => {
|
|
32
|
+
const postMessage = jest.fn();
|
|
33
|
+
const iframe = { contentWindow: { postMessage } };
|
|
34
|
+
|
|
35
|
+
postIopChromeToIframe(iframe, {
|
|
36
|
+
permissions: [],
|
|
37
|
+
pathname: '/foreman_rh_cloud/insights_compliance/scappolicies',
|
|
38
|
+
appRoute: 'scappolicies',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
expect(postMessage).toHaveBeenCalledWith(
|
|
42
|
+
{
|
|
43
|
+
type: IOP_CHROME_INIT,
|
|
44
|
+
payload: {
|
|
45
|
+
user: expect.any(Object),
|
|
46
|
+
permissions: [],
|
|
47
|
+
appRoute: 'scappolicies',
|
|
48
|
+
pathname: '/foreman_rh_cloud/insights_compliance/scappolicies',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
window.location.origin
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('no-ops when iframe has no contentWindow', () => {
|
|
56
|
+
expect(() =>
|
|
57
|
+
postIopChromeToIframe(null, { appRoute: 'reports' })
|
|
58
|
+
).not.toThrow();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { useIopIframeHeight } from '../useIopIframeHeight';
|
|
4
|
+
import { IOP_IFRAME_HEIGHT } from '../iopIframeConstants';
|
|
5
|
+
|
|
6
|
+
const HostTabIframe = () => {
|
|
7
|
+
const iframeRef = useRef(null);
|
|
8
|
+
useIopIframeHeight({ iframeRef });
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<iframe
|
|
12
|
+
ref={iframeRef}
|
|
13
|
+
data-testid="height-iframe"
|
|
14
|
+
title="height-iframe"
|
|
15
|
+
src="about:blank"
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('useIopIframeHeight', () => {
|
|
21
|
+
it('sizes the iframe from a HEIGHT message', () => {
|
|
22
|
+
const { getByTestId } = render(<HostTabIframe />);
|
|
23
|
+
const iframe = getByTestId('height-iframe');
|
|
24
|
+
|
|
25
|
+
window.dispatchEvent(
|
|
26
|
+
new MessageEvent('message', {
|
|
27
|
+
origin: window.location.origin,
|
|
28
|
+
data: {
|
|
29
|
+
type: IOP_IFRAME_HEIGHT,
|
|
30
|
+
payload: { height: 2100 },
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(iframe.style.height).toBe('2100px');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Foreman browser path for an IoP app sub-route.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} appRoute Path inside the iframe application page
|
|
5
|
+
* @param {{ routePrefix: string, fallbackRoute: string }} options
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
export const getIopForemanPath = (
|
|
9
|
+
appRoute = '',
|
|
10
|
+
{ routePrefix, fallbackRoute } = {}
|
|
11
|
+
) => {
|
|
12
|
+
const subRoute = String(appRoute).replace(/^\/+/, '') || fallbackRoute;
|
|
13
|
+
|
|
14
|
+
return `${routePrefix}/${subRoute}`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Path inside the iframe application page derived from a Foreman pathname.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} pathname Foreman location pathname
|
|
21
|
+
* @param {{ routePrefix: string, fallbackRoute: string }} options
|
|
22
|
+
* @returns {string}
|
|
23
|
+
*/
|
|
24
|
+
export const getIopAppRoute = (
|
|
25
|
+
pathname = '',
|
|
26
|
+
{ routePrefix, fallbackRoute } = {}
|
|
27
|
+
) => {
|
|
28
|
+
if (!pathname.startsWith(routePrefix)) {
|
|
29
|
+
return fallbackRoute;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const subRoute = pathname.slice(routePrefix.length).replace(/^\//, '');
|
|
33
|
+
|
|
34
|
+
return subRoute || fallbackRoute;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Absolute URL for a static IoP app entry under Satellite assets.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} staticAppPath e.g. /assets/apps/compliance/index.html
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
export const getIopIframeSrc = staticAppPath => {
|
|
44
|
+
if (typeof window === 'undefined') {
|
|
45
|
+
return staticAppPath;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return `${window.location.origin}${staticAppPath}`;
|
|
49
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { mockUser } from '../ScalprumModule/ScalprumContext';
|
|
2
|
+
import { IOP_CHROME_INIT } from './iopIframeConstants';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sends chrome/RBAC context into an IoP app iframe after it loads.
|
|
6
|
+
*
|
|
7
|
+
* @param {HTMLIFrameElement} iframe
|
|
8
|
+
* @param {Object} options
|
|
9
|
+
* @param {Array} options.permissions Insights-format permissions from useInsightsPermissions
|
|
10
|
+
* @param {string} options.appRoute Path inside the iframe application page (e.g. reports, systems/<uuid>)
|
|
11
|
+
* @param {string} [options.pathname] Foreman pathname (informational; passed through to the child)
|
|
12
|
+
* @param {string} [options.embedded] Embedding mode for the iframe (e.g. 'host-tab')
|
|
13
|
+
*/
|
|
14
|
+
export const postIopChromeToIframe = (
|
|
15
|
+
iframe,
|
|
16
|
+
{ permissions = [], pathname = '', appRoute = '', embedded } = {}
|
|
17
|
+
) => {
|
|
18
|
+
if (!iframe?.contentWindow || typeof window === 'undefined') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
iframe.contentWindow.postMessage(
|
|
23
|
+
{
|
|
24
|
+
type: IOP_CHROME_INIT,
|
|
25
|
+
payload: {
|
|
26
|
+
user: mockUser,
|
|
27
|
+
permissions,
|
|
28
|
+
appRoute,
|
|
29
|
+
pathname,
|
|
30
|
+
...(embedded ? { embedded } : {}),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
window.location.origin
|
|
34
|
+
);
|
|
35
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useCallback, useEffect } from 'react';
|
|
2
|
+
import { postIopChromeToIframe } from './postIopChromeToIframe';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Posts IOP chrome context into an iframe and re-posts when the child signals READY.
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} options
|
|
8
|
+
* @param {React.RefObject} options.iframeRef
|
|
9
|
+
* @param {Array} options.permissions
|
|
10
|
+
* @param {string} options.appRoute
|
|
11
|
+
* @param {string} [options.pathname]
|
|
12
|
+
* @param {string} [options.embedded]
|
|
13
|
+
* @param {string} options.readyMessageType postMessage type from the child (e.g. IOP_COMPLIANCE_READY)
|
|
14
|
+
* @returns {Function} sendChromeContext — also pass to iframe onLoad
|
|
15
|
+
*/
|
|
16
|
+
export const useIopIframeChrome = ({
|
|
17
|
+
iframeRef,
|
|
18
|
+
permissions,
|
|
19
|
+
appRoute,
|
|
20
|
+
pathname = '',
|
|
21
|
+
embedded,
|
|
22
|
+
readyMessageType,
|
|
23
|
+
}) => {
|
|
24
|
+
const sendChromeContext = useCallback(() => {
|
|
25
|
+
postIopChromeToIframe(iframeRef.current, {
|
|
26
|
+
permissions,
|
|
27
|
+
appRoute,
|
|
28
|
+
pathname,
|
|
29
|
+
embedded,
|
|
30
|
+
});
|
|
31
|
+
}, [appRoute, embedded, iframeRef, pathname, permissions]);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
sendChromeContext();
|
|
35
|
+
}, [sendChromeContext]);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const handleMessage = event => {
|
|
39
|
+
if (event.origin !== window.location.origin) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (event.data?.type === readyMessageType) {
|
|
44
|
+
sendChromeContext();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
window.addEventListener('message', handleMessage);
|
|
49
|
+
|
|
50
|
+
return () => window.removeEventListener('message', handleMessage);
|
|
51
|
+
}, [readyMessageType, sendChromeContext]);
|
|
52
|
+
|
|
53
|
+
return sendChromeContext;
|
|
54
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { IOP_IFRAME_HEIGHT } from './iopIframeConstants';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sizes a host-details iframe from IOP_IFRAME_HEIGHT messages sent by the child.
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} options
|
|
8
|
+
* @param {React.RefObject} options.iframeRef
|
|
9
|
+
*/
|
|
10
|
+
export const useIopIframeHeight = ({ iframeRef }) => {
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const handleMessage = event => {
|
|
13
|
+
if (event.origin !== window.location.origin) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (event.data?.type !== IOP_IFRAME_HEIGHT) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const iframe = iframeRef.current;
|
|
22
|
+
const height = event.data.payload?.height;
|
|
23
|
+
|
|
24
|
+
if (!iframe || !height) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
iframe.style.height = `${height}px`;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
window.addEventListener('message', handleMessage);
|
|
32
|
+
|
|
33
|
+
return () => window.removeEventListener('message', handleMessage);
|
|
34
|
+
}, [iframeRef]);
|
|
35
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Listens for iframe NAVIGATE messages and pushes matching Foreman paths.
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} options
|
|
7
|
+
* @param {Object} options.history react-router v5 history
|
|
8
|
+
* @param {string} options.navigateMessageType
|
|
9
|
+
* @param {(appRoute: string) => string} options.getForemanPath
|
|
10
|
+
* @param {string} options.defaultAppRoute fallback when payload.appRoute is missing
|
|
11
|
+
*/
|
|
12
|
+
export const useIopIframeNavigate = ({
|
|
13
|
+
history,
|
|
14
|
+
navigateMessageType,
|
|
15
|
+
getForemanPath,
|
|
16
|
+
defaultAppRoute,
|
|
17
|
+
}) => {
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const handleMessage = event => {
|
|
20
|
+
if (event.origin !== window.location.origin) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (event.data?.type !== navigateMessageType) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const appRoute = event.data.payload?.appRoute || defaultAppRoute;
|
|
29
|
+
const nextPath = getForemanPath(appRoute);
|
|
30
|
+
|
|
31
|
+
if (window.location.pathname !== nextPath) {
|
|
32
|
+
history.push(nextPath);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
window.addEventListener('message', handleMessage);
|
|
37
|
+
|
|
38
|
+
return () => window.removeEventListener('message', handleMessage);
|
|
39
|
+
}, [defaultAppRoute, getForemanPath, history, navigateMessageType]);
|
|
40
|
+
};
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foreman_rh_cloud
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 15.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Foreman Red Hat Cloud team
|
|
@@ -200,7 +200,6 @@ files:
|
|
|
200
200
|
- lib/inventory_sync/async/inventory_self_host_sync.rb
|
|
201
201
|
- lib/inventory_sync/async/query_inventory_job.rb
|
|
202
202
|
- lib/tasks/foreman_rh_cloud_tasks.rake
|
|
203
|
-
- lib/tasks/hybrid_cloud.rake
|
|
204
203
|
- lib/tasks/insights.rake
|
|
205
204
|
- lib/tasks/rh_cloud_inventory.rake
|
|
206
205
|
- locale/Makefile
|
|
@@ -282,6 +281,10 @@ files:
|
|
|
282
281
|
- webpack/CVEsHostDetailsTab/CVEsHostDetailsTab.scss
|
|
283
282
|
- webpack/CVEsHostDetailsTab/__tests__/CVEsHostDetailsTab.test.js
|
|
284
283
|
- webpack/CVEsHostDetailsTab/index.js
|
|
284
|
+
- webpack/ComplianceHostDetailsTab/ComplianceHostDetailsTab.js
|
|
285
|
+
- webpack/ComplianceHostDetailsTab/ComplianceHostDetailsTab.scss
|
|
286
|
+
- webpack/ComplianceHostDetailsTab/__tests__/ComplianceHostDetailsTab.test.js
|
|
287
|
+
- webpack/ComplianceHostDetailsTab/index.js
|
|
285
288
|
- webpack/CveDetailsPage/CveDetailsPage.js
|
|
286
289
|
- webpack/CveDetailsPage/CveDetailsPage.test.js
|
|
287
290
|
- webpack/CveDetailsPage/index.js
|
|
@@ -447,6 +450,13 @@ files:
|
|
|
447
450
|
- webpack/InsightsCloudSync/InsightsCloudSyncReducers.js
|
|
448
451
|
- webpack/InsightsCloudSync/__tests__/InsightsCloudSyncActions.test.js
|
|
449
452
|
- webpack/InsightsCloudSync/index.js
|
|
453
|
+
- webpack/InsightsCompliance/ComplianceIframe.js
|
|
454
|
+
- webpack/InsightsCompliance/ComplianceIframe.scss
|
|
455
|
+
- webpack/InsightsCompliance/InsightsCompliancePage.js
|
|
456
|
+
- webpack/InsightsCompliance/InsightsCompliancePage.test.js
|
|
457
|
+
- webpack/InsightsCompliance/complianceIframeConstants.js
|
|
458
|
+
- webpack/InsightsCompliance/complianceIframeHelpers.js
|
|
459
|
+
- webpack/InsightsCompliance/complianceIframeHelpers.test.js
|
|
450
460
|
- webpack/InsightsHostDetailsTab/InsightsTab.js
|
|
451
461
|
- webpack/InsightsHostDetailsTab/InsightsTab.scss
|
|
452
462
|
- webpack/InsightsHostDetailsTab/InsightsTabActions.js
|
|
@@ -494,6 +504,21 @@ files:
|
|
|
494
504
|
- webpack/common/ForemanTasks/index.js
|
|
495
505
|
- webpack/common/Hooks/ConfigHooks.js
|
|
496
506
|
- webpack/common/Hooks/PermissionsHooks.js
|
|
507
|
+
- webpack/common/IopIframe/IopAppIframe.js
|
|
508
|
+
- webpack/common/IopIframe/IopHostDetailsIframe.js
|
|
509
|
+
- webpack/common/IopIframe/IopHostDetailsIframe.scss
|
|
510
|
+
- webpack/common/IopIframe/IopHostDetailsIframeTab.js
|
|
511
|
+
- webpack/common/IopIframe/__tests__/IopAppIframe.test.js
|
|
512
|
+
- webpack/common/IopIframe/__tests__/IopHostDetailsIframeTab.test.js
|
|
513
|
+
- webpack/common/IopIframe/__tests__/iopIframeHelpers.test.js
|
|
514
|
+
- webpack/common/IopIframe/__tests__/postIopChromeToIframe.test.js
|
|
515
|
+
- webpack/common/IopIframe/__tests__/useIopIframeHeight.test.js
|
|
516
|
+
- webpack/common/IopIframe/iopIframeConstants.js
|
|
517
|
+
- webpack/common/IopIframe/iopIframeHelpers.js
|
|
518
|
+
- webpack/common/IopIframe/postIopChromeToIframe.js
|
|
519
|
+
- webpack/common/IopIframe/useIopIframeChrome.js
|
|
520
|
+
- webpack/common/IopIframe/useIopIframeHeight.js
|
|
521
|
+
- webpack/common/IopIframe/useIopIframeNavigate.js
|
|
497
522
|
- webpack/common/ScalprumModule/ScalprumContext.js
|
|
498
523
|
- webpack/common/ScalprumModule/__tests__/ScalprumContext.test.js
|
|
499
524
|
- webpack/common/Switcher/HelpLabel.js
|
data/lib/tasks/hybrid_cloud.rake
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
require 'io/console'
|
|
2
|
-
require 'uri'
|
|
3
|
-
|
|
4
|
-
def logger
|
|
5
|
-
@logger ||= Logger.new(STDOUT)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
namespace :rh_cloud do
|
|
9
|
-
desc 'Register Satellite Organization with Hybrid Cloud API.'
|
|
10
|
-
# This task registers the Satellite Organization with the Hybrid Cloud API.
|
|
11
|
-
# It requires the user to input their organization ID, Insights URL, and token.
|
|
12
|
-
# The task will then send a POST request to the Hybrid Cloud API to register the organization.
|
|
13
|
-
# The response will be logged, and any errors will be caught and logged as well.
|
|
14
|
-
# The task will exit with an error message if the organization does not have a manifest imported or if the token is not entered.
|
|
15
|
-
# The task will also log a warning if the custom URL is not set and the default one is used.
|
|
16
|
-
task hybridcloud_register: [:environment] do
|
|
17
|
-
include ::ForemanRhCloud::CertAuth
|
|
18
|
-
include ::InsightsCloud::CandlepinCache
|
|
19
|
-
|
|
20
|
-
def default_registrations_url
|
|
21
|
-
URI.join(ForemanRhCloud.base_url, '/api/identity/certificate/registrations').to_s
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# Helper method to get the registrations URL, with a warning for default usage
|
|
25
|
-
def registrations_url(custom_url)
|
|
26
|
-
if custom_url.empty?
|
|
27
|
-
logger.warn("Custom url is not set, using the default one: #{default_registrations_url}")
|
|
28
|
-
default_registrations_url
|
|
29
|
-
else
|
|
30
|
-
if URI(custom_url).scheme.nil?
|
|
31
|
-
logger.warn("Custom URL lacks a scheme; prepending https:// prefix.")
|
|
32
|
-
custom_url = "https://" + custom_url
|
|
33
|
-
end
|
|
34
|
-
custom_url
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def get_organization(user_org_id)
|
|
39
|
-
maybe_organization = Organization.find_by(id: user_org_id)
|
|
40
|
-
if maybe_organization.nil?
|
|
41
|
-
logger.error("Organization with ID '#{user_org_id}' not found.")
|
|
42
|
-
exit(1)
|
|
43
|
-
end
|
|
44
|
-
maybe_organization
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def get_uid(organization)
|
|
48
|
-
maybe_uid = cp_owner_id(organization)
|
|
49
|
-
if maybe_uid.nil?
|
|
50
|
-
logger.error("Organization '#{organization}' does not have a manifest imported.")
|
|
51
|
-
exit(1)
|
|
52
|
-
end
|
|
53
|
-
maybe_uid
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# --- Input Collection ---
|
|
57
|
-
puts "Paste in your organization ID, this can be retrieved with the command: hammer organization list"
|
|
58
|
-
loop do
|
|
59
|
-
input = STDIN.gets.chomp
|
|
60
|
-
if input.match?(/^\d+$/) # Checks if input consists only of digits
|
|
61
|
-
@user_org_id = input.to_i
|
|
62
|
-
break
|
|
63
|
-
else
|
|
64
|
-
puts "Invalid input. Please enter a numeric organization ID."
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
puts "\n" + "-" * 50 + "\n\n"
|
|
69
|
-
puts "Paste in your custom Insights URL. If nothing is entered, the default will be used (#{default_registrations_url})."
|
|
70
|
-
insights_user_input = STDIN.gets.chomp
|
|
71
|
-
|
|
72
|
-
puts "\n" + "-" * 50 + "\n\n"
|
|
73
|
-
puts 'Paste in your Hybrid Cloud API token, output will be hidden.'
|
|
74
|
-
puts 'This token can be retrieved from the Hybrid Cloud console.'
|
|
75
|
-
token = STDIN.noecho(&:gets).chomp
|
|
76
|
-
if token.empty?
|
|
77
|
-
logger.error('Token was not entered.')
|
|
78
|
-
exit(1)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# --- Data Preparation ---
|
|
82
|
-
|
|
83
|
-
organization = get_organization(@user_org_id)
|
|
84
|
-
uid = get_uid(organization)
|
|
85
|
-
hostname = ForemanRhCloud.foreman_host_name
|
|
86
|
-
insights_url = registrations_url(insights_user_input)
|
|
87
|
-
|
|
88
|
-
# --- API Request ---
|
|
89
|
-
|
|
90
|
-
headers = {
|
|
91
|
-
Authorization: "Bearer #{token}",
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
payload = {
|
|
95
|
-
'uid': uid,
|
|
96
|
-
"display_name": "#{hostname}+#{organization.label}",
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
begin
|
|
100
|
-
response = execute_cloud_request(
|
|
101
|
-
organization: organization,
|
|
102
|
-
method: :post,
|
|
103
|
-
url: insights_url,
|
|
104
|
-
headers: headers,
|
|
105
|
-
payload: payload.to_json
|
|
106
|
-
)
|
|
107
|
-
logger.debug("Cloud request completed: status=#{response.code}, body_preview=#{response.body&.slice(0, 200)}")
|
|
108
|
-
rescue RestClient::Unauthorized => _ex
|
|
109
|
-
# Add a more specific rescue for 401 Unauthorized errors
|
|
110
|
-
logger.error('Registration failed: Your token is invalid or unauthorized. Please check your token and try again.')
|
|
111
|
-
# Optionally, you can still log the full debug info if helpful for advanced troubleshooting
|
|
112
|
-
# logger.debug(ex.backtrace.join("\n"))
|
|
113
|
-
exit(1)
|
|
114
|
-
rescue RestClient::ExceptionWithResponse => ex
|
|
115
|
-
# This catches any RestClient exception that has a response (like 400, 403, 404, 500, etc.)
|
|
116
|
-
status_code = begin
|
|
117
|
-
ex.response.code
|
|
118
|
-
rescue StandardError
|
|
119
|
-
"unknown"
|
|
120
|
-
end
|
|
121
|
-
logger.error("Registration failed with HTTP status #{status_code}: #{ex.message}")
|
|
122
|
-
logger.debug("Response body (if available): #{ex.response.body}")
|
|
123
|
-
exit(1)
|
|
124
|
-
rescue StandardError => ex
|
|
125
|
-
# This is the catch-all for any other unexpected errors
|
|
126
|
-
logger.error("An unexpected error occurred during registration: #{ex.message}")
|
|
127
|
-
exit(1)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
logger.info("Satellite Organization '#{organization.label}' (ID: #{@user_org_id}) successfully registered.")
|
|
131
|
-
end
|
|
132
|
-
end
|