2017-09-20 12:30:53 +03:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import forceArray from 'force-array';
|
|
|
|
import { compose, graphql } from 'react-apollo';
|
|
|
|
import find from 'lodash.find';
|
|
|
|
import get from 'lodash.get';
|
|
|
|
|
2017-10-09 16:43:51 +03:00
|
|
|
import {
|
|
|
|
ViewContainer,
|
|
|
|
StatusLoader,
|
|
|
|
Message,
|
|
|
|
MessageDescription,
|
2017-10-31 12:29:15 +02:00
|
|
|
MessageTitle,
|
|
|
|
Table,
|
|
|
|
TableThead,
|
|
|
|
TableTr,
|
|
|
|
TableTh,
|
|
|
|
TableTbody,
|
|
|
|
P
|
2017-10-09 16:43:51 +03:00
|
|
|
} from 'joyent-ui-toolkit';
|
2017-09-20 12:30:53 +03:00
|
|
|
|
|
|
|
import GetFirewallRules from '@graphql/list-firewall-rules.gql';
|
2017-09-27 17:26:12 +03:00
|
|
|
import { FirewallRule as InstanceFirewallRule } from '@components/instances';
|
|
|
|
|
2017-09-20 12:30:53 +03:00
|
|
|
const Firewall = ({
|
2017-10-03 18:04:54 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
2017-09-20 12:30:53 +03:00
|
|
|
firewallEnabled = false,
|
|
|
|
firewallRules = [],
|
|
|
|
loading,
|
|
|
|
error
|
|
|
|
}) => {
|
2017-09-27 17:26:12 +03:00
|
|
|
const values = forceArray(firewallRules);
|
2017-09-27 17:44:57 +03:00
|
|
|
const _loading = !(loading && !values.length) ? null : <StatusLoader />;
|
2017-09-20 12:30:53 +03:00
|
|
|
|
2017-11-09 13:27:32 +02:00
|
|
|
const _firewall =
|
|
|
|
_loading && !values.length ? null : (
|
|
|
|
<Table>
|
|
|
|
<TableThead>
|
|
|
|
<TableTr>
|
|
|
|
<TableTh left bottom>
|
|
|
|
<P>Rule</P>
|
|
|
|
</TableTh>
|
|
|
|
<TableTh xs="63" center bottom>
|
|
|
|
<P>Global</P>
|
|
|
|
</TableTh>
|
|
|
|
<TableTh xs="75" center bottom>
|
|
|
|
<P>Enabled</P>
|
|
|
|
</TableTh>
|
|
|
|
</TableTr>
|
|
|
|
</TableThead>
|
|
|
|
<TableTbody>
|
|
|
|
{values.map(network => (
|
|
|
|
<InstanceFirewallRule key={network.id} {...network} />
|
|
|
|
))}
|
|
|
|
</TableTbody>
|
|
|
|
</Table>
|
|
|
|
);
|
2017-09-20 12:30:53 +03:00
|
|
|
|
2017-10-04 20:27:55 +03:00
|
|
|
const _error =
|
|
|
|
error && !values.length && !_loading ? (
|
2017-10-09 16:43:51 +03:00
|
|
|
<Message error>
|
|
|
|
<MessageTitle>Ooops!</MessageTitle>
|
|
|
|
<MessageDescription>
|
|
|
|
An error occurred while loading your instance firewall rules
|
|
|
|
</MessageDescription>
|
|
|
|
</Message>
|
2017-10-04 20:27:55 +03:00
|
|
|
) : null;
|
2017-09-20 12:30:53 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ViewContainer center={Boolean(_loading)} main>
|
|
|
|
{_loading}
|
|
|
|
{_error}
|
2017-09-27 17:26:12 +03:00
|
|
|
{_firewall}
|
2017-09-20 12:30:53 +03:00
|
|
|
</ViewContainer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Firewall.propTypes = {
|
|
|
|
loading: PropTypes.bool
|
|
|
|
};
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
graphql(GetFirewallRules, {
|
|
|
|
options: ({ match }) => ({
|
|
|
|
pollInterval: 1000,
|
|
|
|
variables: {
|
|
|
|
name: get(match, 'params.instance')
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
props: ({ data: { loading, error, variables, ...rest } }) => {
|
|
|
|
const machine = find(get(rest, 'machines', []), ['name', variables.name]);
|
2017-10-03 18:04:54 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
const firewallEnabled = get(machine, 'firewall_enabled', false);
|
|
|
|
const firewallRules = get(machine, 'firewall_rules', []);
|
2017-09-20 12:30:53 +03:00
|
|
|
|
2017-10-03 18:04:54 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
2017-09-20 12:30:53 +03:00
|
|
|
return { firewallEnabled, firewallRules, loading, error };
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)(Firewall);
|