Skip to content

Commit

Permalink
Add an About tab with the version information in the Settings (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
maertv authored and richard-julien committed Oct 15, 2019
1 parent 0b622d3 commit 17761e2
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ class TopMenuSettings extends Component {
>
{t('Custom attributes')}
</Button>
<Button
component={Link}
to="/dashboard/settings/about"
variant={
location.pathname.includes('/dashboard/settings/about')
? 'contained'
: 'text'
}
size="small"
color={
location.pathname.includes('/dashboard/settings/about')
? 'primary'
: 'inherit'
}
classes={{ root: classes.button }}
>
{t('About')}
</Button>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React, { Component } from 'react';
import * as PropTypes from 'prop-types';
import graphql from 'babel-plugin-relay/macro';
import { compose } from 'ramda';
import { withStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import Paper from '@material-ui/core/Paper';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import inject18n from '../../../components/i18n';
import { QueryRenderer } from '../../../relay/environment';
import Loader from '../../Loader';

const styles = () => ({
panel: {
margin: '0 auto',
marginBottom: 30,
padding: '20px 20px 20px 20px',
textAlign: 'left',
borderRadius: 6,
},
});

const aboutQuery = graphql`
query AboutQuery {
about {
version
dependencies {
name
version
}
}
}
`;

class About extends Component {
render() {
const { classes, t } = this.props;
return (
<QueryRenderer
query={aboutQuery}
render={({ props }) => {
if (props) {
const { version, dependencies } = props.about;
return (
<Paper classes={{ root: classes.panel }} elevation={2}>
<Typography variant="h1" gutterBottom={true}>
{t('OpenCTI version')} {version}
</Typography>
<br/>
<Typography variant="h2" gutterBottom={true}>
<b>{t('Dependencies')}</b>
</Typography>
<List>
{dependencies.map(dep => (
<ListItem key={dep.name} divider>
<ListItemText primary={t(dep.name)} secondary={dep.version}/>
</ListItem>
))}
</List>
</Paper>
);
}
return <Loader/>;
}}
/>
);
}
}

About.propTypes = {
classes: PropTypes.object,
t: PropTypes.func,
};

export default compose(
inject18n,
withStyles(styles),
)(About);
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Users from './Users';
import Groups from './Groups';
import MarkingDefinitions from './MarkingDefinitions';
import KillChainPhases from './KillChainPhases';
import About from './About';
import Attributes from './Attributes';
import { BoundaryRoute } from '../Error';

Expand All @@ -31,6 +32,10 @@ const Root = () => (
exact
path="/dashboard/settings/attributes"
component={Attributes}/>
<BoundaryRoute
exact
path="/dashboard/settings/about"
component={About}/>
</Switch>
);

Expand Down
11 changes: 11 additions & 0 deletions opencti-platform/opencti-graphql/config/schema/opencti.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ type EditUserContext {
focusOn: String # Field name
}

### Info
type DependencyVersion {
name: String!
version: String!
}
type AppInfo {
version: String!,
dependencies: [DependencyVersion!]!
}

### Stats
type AckDetails {
rate: Float
Expand Down Expand Up @@ -2112,6 +2122,7 @@ input RelationsAddInput {
### QUERIES
type Query {
# Technical
about: AppInfo @auth
settings: Settings
attribute(id: String): Attribute @auth
attributes(first: Int, type: String!): AttributeConnection @auth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export const elasticIsAlive = async () => {
}
};

export const getElasticVersion = () => {
return el
.info()
.then(info => info.body.version.number)
.catch(() => 'Disconnected');
};

export const createIndexes = async () => {
return Promise.all(
defaultIndexes.map(index => {
Expand Down
6 changes: 6 additions & 0 deletions opencti-platform/opencti-graphql/src/database/grakn.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ const client = new Grakn(
);
let session = null;

export const getGraknVersion = async () => {
// TODO: It seems that Grakn server does not expose its version yet:
// https://github.com/graknlabs/client-nodejs/issues/47
return '1.5.8';
};

export const takeReadTx = async (retry = false) => {
if (session === null) {
session = await client.session('grakn');
Expand Down
6 changes: 6 additions & 0 deletions opencti-platform/opencti-graphql/src/database/rabbitmq.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ export const metrics = async () => {
});
return { overview, queues };
};

export const getRabbitMQVersion = () => {
return metrics()
.then(data => data.overview.rabbitmq_version)
.catch(() => 'Disconnected');
};
6 changes: 6 additions & 0 deletions opencti-platform/opencti-graphql/src/database/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ if (client) {
});
}
const isActive = () => client && client.status === 'ready';

export const getRedisVersion = () => {
if (isActive()) return client.serverInfo.redis_version;
return 'Disconnected';
};

/**
* Delete the user context for a specific edition
* @param user the user
Expand Down
25 changes: 23 additions & 2 deletions opencti-platform/opencti-graphql/src/domain/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,31 @@ import {
notify,
now,
takeWriteTx,
commitWriteTx
commitWriteTx,
getGraknVersion
} from '../database/grakn';
import { BUS_TOPICS } from '../config/conf';
import { delEditContext, setEditContext } from '../database/redis';
import {
delEditContext,
setEditContext,
getRedisVersion
} from '../database/redis';

import { getElasticVersion } from '../database/elasticSearch';

import { getRabbitMQVersion } from '../database/rabbitmq';
import { version } from '../../package.json';

export const getApplicationInfo = () => ({
version,
dependencies: [
{ name: 'Grakn', version: getGraknVersion() },
{ name: 'Elasticsearch', version: getElasticVersion() },
{ name: 'RabbitMQ', version: getRabbitMQVersion() },
{ name: 'Redis', version: getRedisVersion() }
// TODO Add Minio
]
});

export const getSettings = () =>
getObject(
Expand Down
4 changes: 3 additions & 1 deletion opencti-platform/opencti-graphql/src/resolvers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import {
settingsEditField,
settingsEditContext,
settingsCleanContext,
addSettings
addSettings,
getApplicationInfo
} from '../domain/settings';
import { fetchEditContext, pubsub } from '../database/redis';
import withCancel from '../schema/subscriptionWrapper';

const settingsResolvers = {
Query: {
about: () => getApplicationInfo(),
settings: () => getSettings()
},
Settings: {
Expand Down

0 comments on commit 17761e2

Please sign in to comment.