Skip to content

Commit 4b3b56e

Browse files
authored
Merge and disable cross console to master. (#606)
* Updated server side changes. * Added code to retrieve cross console apps on client side. * Server.js updates and addition of demo mode env variable. * Updated with latest version of integration builds. * Fixed linting errors. * Fix for CORS error. * Fixed import error * updated to use getAvailableApps * Fixed issues with prettier problems. * Fixed typo. * Updated DEMO_MODE to CROSS_CONSOLE_LOCAL_DEV_MODE * Refactor some of the cross console server code. * Added code to get list of apps from live server. * Updated with bug fixes and latest cross console version. * Fixed APICUITO change and missing null value for appList. * Updated to latest version of rh integration. * Fixed issue with rootURL * upgraded 1.0.2 integration and added amqonline. * Updated with rebase from RHMI master. * Added code for cross console but have it disabled. * Fixed with review comments. * Fixed yarn.lock file.
1 parent 9bea72e commit 4b3b56e

File tree

6 files changed

+281
-194
lines changed

6 files changed

+281
-194
lines changed

.env.development

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ REACT_APP_LAUNCHER_URL=http://localhost:3006
2020
REACT_APP_CHE_URL=http://localhost:3006
2121
REACT_APP_ENMASSE_URL=http://localhost:3006
2222
REACT_APP_APICURIO_URL=http://localhost:3006
23+
24+
REACT_APP_RHMI_SERVER_URL=http://localhost:5001

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
"proxy": "http://localhost:5001/",
66
"dependencies": {
77
"@fortawesome/fontawesome-free": "5.7.2",
8-
"@patternfly/patternfly": "4.16.7",
9-
"@patternfly/react-core": "4.23.1",
8+
"@patternfly/patternfly": "4.23.3",
9+
"@patternfly/react-core": "4.32.1",
10+
"@patternfly/react-icons": "4.5.0",
11+
"@patternfly/react-styles" :"4.5.0",
12+
"@rh-uxd/appservices-patternfly-core": "1.0.5",
1013
"asciidoctor.js": "1.5.7",
1114
"axios": "^0.19.0",
1215
"body-parser": "^1.18.3",
@@ -84,6 +87,7 @@
8487
"build:js": "react-scripts build",
8588
"start": "node server.js",
8689
"start:dev": "FUSE_URL=http://localhost:3006 LAUNCHER_URL=http://localhost:3006 ENMASSE_URL=http://localhost:3006 CHE_URL=http://localhost:3006 APICURIO_URL=http://localhost:3006 run-p -l watch:css start:local start:server",
90+
"start:dev:crossconsole": "CROSS_CONSOLE_LOCAL_DEV_MODE=true FUSE_URL=http://localhost:3000 LAUNCHER_URL=http://localhost:3006 ENMASSE_URL=http://localhost:3006 CHE_URL=http://localhost:3006 APICURIO_URL=http://localhost:4200 run-p -l watch:css start:local start:server",
8791
"start:local": "react-scripts start",
8892
"start:server": "nodemon --watch server.js --exec 'node server.js'",
8993
"commit:hash": "echo REACT_APP_UI_COMMIT_HASH=$(git rev-list -1 --all) > .env",

server.js

Lines changed: 142 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-shadow */
12
const express = require('express');
23
const path = require('path');
34
const url = require('url');
@@ -21,14 +22,48 @@ const OPENSHIFT_PROXY_PATH = '/proxy/openshift';
2122
const app = express();
2223

2324
const adoc = asciidoctor();
25+
const LOCAL_DEV_INSTALLED_SERVICES = {
26+
'3scale': {
27+
Host: 'https://3scale-admin.apps.demo.com',
28+
Version: '2.7'
29+
},
30+
amqonline: {
31+
Host: 'http://localhost:3003',
32+
Version: '1.3.1'
33+
},
34+
apicurito: {
35+
Host: 'http://localhost:4200',
36+
Version: '1.0.1'
37+
},
38+
codeready: {
39+
Host: 'https://codeready-redhat-rhmi-codeready-workspaces.apps.demo.com',
40+
Version: '2.0.0'
41+
},
42+
'fuse-managed': {
43+
Host: 'http://localhost:3000',
44+
Version: '7.5'
45+
},
46+
ups: {
47+
Host: 'https://ups-unifiedpush-proxy-redhat-rhmi-ups.apps.demo.com',
48+
Version: '2.3.2'
49+
},
50+
'user-rhsso': {
51+
Host: 'https://keycloak-edge-redhat-rhmi-user-sso.apps.demo.com',
52+
Version: '8.0.1'
53+
}
54+
};
55+
const CROSS_CONSOLE_ENABLED = false;
2456

2557
app.use(bodyParser.json());
26-
app.use(OPENSHIFT_PROXY_PATH, proxy(`https://${process.env.OPENSHIFT_API}`, {
27-
proxyReqOptDecorator: function(proxyReqOpts, _) {
28-
proxyReqOpts.rejectUnauthorized = false;
29-
return proxyReqOpts;
30-
}
31-
}));
58+
app.use(
59+
OPENSHIFT_PROXY_PATH,
60+
proxy(`https://${process.env.OPENSHIFT_API}`, {
61+
proxyReqOptDecorator(proxyReqOpts, _) {
62+
proxyReqOpts.rejectUnauthorized = false;
63+
return proxyReqOpts;
64+
}
65+
})
66+
);
3267

3368
// prometheus metrics endpoint
3469
app.use(
@@ -79,6 +114,21 @@ const backendRequiredRoles = [
79114
const walkthroughs = [];
80115
let server;
81116

117+
app.get('/services', (req, res) => {
118+
res.setHeader('Content-Type', 'application/json');
119+
res.setHeader('Access-Control-Allow-Origin', '*');
120+
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
121+
if ((isOpenShift4() || process.env.CROSS_CONSOLE_LOCAL_DEV_MODE === 'true') && CROSS_CONSOLE_ENABLED) {
122+
if (process.env.INSTALLED_SERVICES) {
123+
res.send(process.env.INSTALLED_SERVICES);
124+
} else {
125+
res.send(JSON.stringify(LOCAL_DEV_INSTALLED_SERVICES));
126+
}
127+
} else {
128+
res.send(JSON.stringify({}));
129+
}
130+
});
131+
82132
app.get('/customWalkthroughs', (req, res) => {
83133
res.status(200).json(walkthroughs);
84134
});
@@ -97,9 +147,8 @@ app.get('/user_walkthroughs', (req, res) =>
97147
if (data) {
98148
const { value } = data;
99149
return res.json(value);
100-
} else {
101-
return res.end();
102150
}
151+
return res.end();
103152
})
104153
.catch(err => {
105154
console.error(err);
@@ -281,89 +330,88 @@ function resolveWalkthroughLocations(locations) {
281330
}
282331

283332
const tmpDirPrefix = uuid.v4();
284-
const mappedLocations = locations.map(
285-
location =>
286-
new Promise((resolve, reject) => {
287-
const locationResultTemplate = { origin: location };
288-
if (!location) {
289-
return reject(new Error(`Invalid location ${location}`));
290-
} else if (isPath(location)) {
291-
console.log(`Importing walkthrough from path ${location}`);
292-
const locationResult = Object.assign(
293-
{
294-
parentId: path.basename(location),
295-
walkthroughLocationInfo: Object.assign({}, WALKTHROUGH_LOCATION_DEFAULT, {
296-
type: WALKTHROUGH_LOCATION_TYPE_PATH,
297-
directory: path.basename(location)
298-
})
299-
},
300-
locationResultTemplate,
301-
{ local: location }
302-
);
303-
return resolve(locationResult);
304-
} else if (isGitRepo(location)) {
305-
const clonePath = path.join(TMP_DIR, tmpDirPrefix);
306-
307-
// Need to parse out query params for walkthroughs, e.g custom directory
308-
const cloneUrl = generateCloneUrlFromLocation(location);
309-
const repoName = getWalkthroughRepoNameFromLocation(location);
310-
const walkthroughParams = querystring.parse(url.parse(location).query);
311-
312-
console.log(`Importing walkthrough from git ${cloneUrl}`);
313-
return gitClient
314-
.cloneRepo(cloneUrl, clonePath)
315-
.then(cloned => {
316-
gitClient.latestLog(cloned.localDir).then(log => {
317-
getWalkthroughHeader(cloned.localDir)
318-
.then(head => {
319-
let wtHeader;
320-
if (head === null) {
321-
wtHeader = null;
322-
} else {
323-
wtHeader = head.prettyName;
324-
}
325-
const walkthroughFolders = [];
326-
if (!Array.isArray(walkthroughParams.walkthroughsFolder)) {
327-
walkthroughFolders.push(walkthroughParams.walkthroughsFolder || 'walkthroughs');
328-
} else {
329-
walkthroughFolders.push(...walkthroughParams.walkthroughsFolder);
330-
}
331-
// Get the folders to import in the repository.
332-
const walkthroughInfos = walkthroughFolders.map(folder => {
333-
const walkthroughLocationInfo = Object.assign({}, WALKTHROUGH_LOCATION_DEFAULT, {
334-
type: WALKTHROUGH_LOCATION_TYPE_GIT,
335-
commitHash: log.latest.hash,
336-
commitDate: log.latest.date,
337-
remote: cloned.repoName,
338-
directory: folder,
339-
header: wtHeader
340-
});
341-
342-
return Object.assign({}, locationResultTemplate, {
343-
parentId: `${repoName}-${path.basename(folder)}`,
344-
walkthroughLocationInfo,
345-
local: path.join(cloned.localDir, folder)
346-
});
347-
});
348-
resolve(walkthroughInfos);
349-
})
350-
.catch(reject);
351-
});
333+
const mappedLocations = locations.map(location =>
334+
new Promise((resolve, reject) => {
335+
const locationResultTemplate = { origin: location };
336+
if (!location) {
337+
return reject(new Error(`Invalid location ${location}`));
338+
} else if (isPath(location)) {
339+
console.log(`Importing walkthrough from path ${location}`);
340+
const locationResult = Object.assign(
341+
{
342+
parentId: path.basename(location),
343+
walkthroughLocationInfo: Object.assign({}, WALKTHROUGH_LOCATION_DEFAULT, {
344+
type: WALKTHROUGH_LOCATION_TYPE_PATH,
345+
directory: path.basename(location)
352346
})
353-
.catch(reject);
354-
}
347+
},
348+
locationResultTemplate,
349+
{ local: location }
350+
);
351+
return resolve(locationResult);
352+
} else if (isGitRepo(location)) {
353+
const clonePath = path.join(TMP_DIR, tmpDirPrefix);
354+
355+
// Need to parse out query params for walkthroughs, e.g custom directory
356+
const cloneUrl = generateCloneUrlFromLocation(location);
357+
const repoName = getWalkthroughRepoNameFromLocation(location);
358+
const walkthroughParams = querystring.parse(url.parse(location).query);
359+
360+
console.log(`Importing walkthrough from git ${cloneUrl}`);
361+
return gitClient
362+
.cloneRepo(cloneUrl, clonePath)
363+
.then(cloned => {
364+
gitClient.latestLog(cloned.localDir).then(log => {
365+
getWalkthroughHeader(cloned.localDir)
366+
.then(head => {
367+
let wtHeader;
368+
if (head === null) {
369+
wtHeader = null;
370+
} else {
371+
wtHeader = head.prettyName;
372+
}
373+
const walkthroughFolders = [];
374+
if (!Array.isArray(walkthroughParams.walkthroughsFolder)) {
375+
walkthroughFolders.push(walkthroughParams.walkthroughsFolder || 'walkthroughs');
376+
} else {
377+
walkthroughFolders.push(...walkthroughParams.walkthroughsFolder);
378+
}
379+
// Get the folders to import in the repository.
380+
const walkthroughInfos = walkthroughFolders.map(folder => {
381+
const walkthroughLocationInfo = Object.assign({}, WALKTHROUGH_LOCATION_DEFAULT, {
382+
type: WALKTHROUGH_LOCATION_TYPE_GIT,
383+
commitHash: log.latest.hash,
384+
commitDate: log.latest.date,
385+
remote: cloned.repoName,
386+
directory: folder,
387+
header: wtHeader
388+
});
355389

356-
return reject(new Error(`${location} is neither a path nor a git repo`));
357-
}).catch(err => {
358-
console.error(err);
359-
return undefined;
360-
})
390+
return Object.assign({}, locationResultTemplate, {
391+
parentId: `${repoName}-${path.basename(folder)}`,
392+
walkthroughLocationInfo,
393+
local: path.join(cloned.localDir, folder)
394+
});
395+
});
396+
resolve(walkthroughInfos);
397+
})
398+
.catch(reject);
399+
});
400+
})
401+
.catch(reject);
402+
}
403+
404+
return reject(new Error(`${location} is neither a path nor a git repo`));
405+
}).catch(err => {
406+
console.error(err);
407+
return undefined;
408+
})
361409
);
362410

363-
return Promise.all(mappedLocations).then(promises => {
411+
return Promise.all(mappedLocations).then(promises =>
364412
// Ignore all locations that could not be resolved
365-
return flattenDeep(promises.filter(p => !!p));
366-
});
413+
flattenDeep(promises.filter(p => !!p))
414+
);
367415
}
368416

369417
/**
@@ -623,13 +671,19 @@ function getConfigData(req) {
623671
logoutRedirectUri = 'http://localhost:3006';
624672
}
625673
if (!process.env.OPENSHIFT_OAUTH_HOST) {
626-
console.warn('OPENSHIFT_OAUTH_HOST not set, using OPENSHIFT_HOST instead. This is okay on OCP 3.11, but will not work on 4.x, see INTLY-2791.');
674+
console.warn(
675+
'OPENSHIFT_OAUTH_HOST not set, using OPENSHIFT_HOST instead. This is okay on OCP 3.11, but will not work on 4.x, see INTLY-2791.'
676+
);
627677
process.env.OPENSHIFT_OAUTH_HOST = process.env.OPENSHIFT_HOST;
628678
}
629679

630680
const masterUri = isOpenShift4() ? OPENSHIFT_PROXY_PATH : `https://${process.env.OPENSHIFT_HOST}`;
631681
const wssMasterUri = isOpenShift4() ? OPENSHIFT_PROXY_PATH : `wss://${process.env.OPENSHIFT_HOST}`;
632-
const ssoLogoutUri = isOpenShift4() ? '/' : `https://${process.env.SSO_ROUTE}/auth/realms/openshift/protocol/openid-connect/logout?redirect_uri=${logoutRedirectUri}`;
682+
const ssoLogoutUri = isOpenShift4()
683+
? '/'
684+
: `https://${
685+
process.env.SSO_ROUTE
686+
}/auth/realms/openshift/protocol/openid-connect/logout?redirect_uri=${logoutRedirectUri}`;
633687

634688
const installedServices = process.env.INSTALLED_SERVICES || '{}';
635689
return `window.OPENSHIFT_CONFIG = {

src/components/masthead/masthead.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
// TODO: ENABLE WHEN WE ARE READY TO RELEASE CROSS CONSOLE
4+
// import { getAvailableApps, getSolutionExplorerServer } from '@rh-uxd/integration-core';
5+
// import { CrossNavHeader } from '@rh-uxd/integration-react';
36
import {
47
Brand,
58
Button,
@@ -17,6 +20,8 @@ import {
1720
import { CogIcon, HelpIcon } from '@patternfly/react-icons';
1821
import accessibleStyles from '@patternfly/patternfly/utilities/Accessibility/accessibility.css';
1922
import { css } from '@patternfly/react-styles';
23+
// TODO: ENABLE WHEN WE ARE READY TO RELEASE CROSS CONSOLE
24+
// import rhiImage from '@rh-uxd/appservices-patternfly-core/styles/assets/Logo-Red_Hat-Managed_Integration-A-Reverse-RGB.png';
2025
import { withRouter } from 'react-router-dom';
2126
import { noop } from '../../common/helpers';
2227
import { connect, reduxActions } from '../../redux';
@@ -35,6 +40,8 @@ class Masthead extends React.Component {
3540
isHelpDropdownOpen: false,
3641
isUserDropdownOpen: false,
3742
showAboutModal: false
43+
// showLogo: false,
44+
// appList: null
3845
};
3946

4047
this.onTitleClick = this.onTitleClick.bind(this);
@@ -48,6 +55,19 @@ class Masthead extends React.Component {
4855

4956
this.onAboutModal = this.onAboutModal.bind(this);
5057
this.closeAboutModal = this.closeAboutModal.bind(this);
58+
59+
// TODO: ENABLE WHEN WE ARE READY TO RELEASE CROSS CONSOLE
60+
// if (!this.state.appList) {
61+
// getAvailableApps(
62+
// process.env.REACT_APP_RHMI_SERVER_URL ? process.env.REACT_APP_RHMI_SERVER_URL : getSolutionExplorerServer(),
63+
// undefined,
64+
// undefined,
65+
// ['3scale', 'solution-explorer'],
66+
// !!process.env.REACT_APP_RHMI_SERVER_URL
67+
// ).then(apps => {
68+
// this.setState({ appList: apps, showLogo: true });
69+
// });
70+
// }
5171
}
5272

5373
onLogoutUser = () => {
@@ -106,6 +126,18 @@ class Masthead extends React.Component {
106126
getLogo = () => {
107127
let clusterType = '';
108128
let logoName = '';
129+
// TODO: ENABLE ONCE WE ARE READY TO RELEASE CROSS CONSOLE.
130+
// if (window.OPENSHIFT_CONFIG && this.state.showLogo) {
131+
// clusterType = window.OPENSHIFT_CONFIG.mockData ? 'localhost' : window.OPENSHIFT_CONFIG.clusterType;
132+
// if (clusterType === 'poc') {
133+
// logoName =
134+
// this.state.appList && this.state.appList.length > 0 ? rhiImage : managedIntegrationSolutionExplorerImg;
135+
// } else if (clusterType === 'osd') {
136+
// logoName =
137+
// this.state.appList && this.state.appList.length > 0 ? rhiImage : managedIntegrationSolutionExplorerImg;
138+
// } else {
139+
// logoName = this.state.appList && this.state.appList.length > 0 ? rhiImage : solutionExplorerImg;
140+
// }
109141
if (window.OPENSHIFT_CONFIG) {
110142
clusterType = window.OPENSHIFT_CONFIG.mockData ? 'localhost' : window.OPENSHIFT_CONFIG.clusterType;
111143
if (clusterType === 'poc') {
@@ -306,7 +338,16 @@ class Masthead extends React.Component {
306338
{showAboutModal && <AboutModal isOpen={showAboutModal} closeAboutModal={this.closeAboutModal} />}
307339
</React.Fragment>
308340
);
309-
341+
// TODO: ENABLE ONCE WE ARE READY TO SHOW CROSS CONSOLE.
342+
// return (
343+
// <CrossNavHeader
344+
// apps={this.state.appList}
345+
// currentApp={{ id: 'solution-explorer', name: 'Solution Explorer', rootUrl: window.location.href }}
346+
// logo={this.state.showLogo ? <Brand src={this.getLogo()} alt="Red Hat Solution Explorer" /> : null}
347+
// logoProps={logoProps}
348+
// headerTools={MastheadToolbar}
349+
// />
350+
// );
310351
return (
311352
<PageHeader
312353
logo={<Brand src={this.getLogo()} alt="Red Hat Solution Explorer" />}

0 commit comments

Comments
 (0)