2018-02-01 12:38:12 +02:00
|
|
|
|
/* eslint-disable camelcase */
|
2018-01-09 17:59:04 +02:00
|
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
|
import { compose, graphql } from 'react-apollo';
|
|
|
|
|
import ReduxForm from 'declarative-redux-form';
|
|
|
|
|
import { set } from 'react-redux-values';
|
|
|
|
|
import { connect } from 'react-redux';
|
2018-01-30 18:04:03 +02:00
|
|
|
|
import { Margin } from 'styled-components-spacing';
|
|
|
|
|
import Flex, { FlexItem } from 'styled-flex-component';
|
2018-01-09 17:59:04 +02:00
|
|
|
|
import get from 'lodash.get';
|
|
|
|
|
import forceArray from 'force-array';
|
|
|
|
|
|
2018-01-30 18:04:03 +02:00
|
|
|
|
import { FirewallIcon, H3, Button, P } from 'joyent-ui-toolkit';
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
ToggleFirewallForm,
|
|
|
|
|
ToggleInactiveForm,
|
|
|
|
|
TagRules,
|
|
|
|
|
DefaultRules
|
|
|
|
|
} from '@components/firewall';
|
2018-01-23 14:20:36 +02:00
|
|
|
|
|
2018-01-09 17:59:04 +02:00
|
|
|
|
import Title from '@components/create-instance/title';
|
2018-01-23 14:20:36 +02:00
|
|
|
|
import Description from '@components/description';
|
2018-01-30 18:04:03 +02:00
|
|
|
|
import Empty from '@components/empty';
|
2018-01-09 17:59:04 +02:00
|
|
|
|
import ListFwRules from '@graphql/list-fw-rules.gql';
|
2018-03-01 16:32:55 +02:00
|
|
|
|
import { Forms, Values } from '@root/constants';
|
2018-01-09 17:59:04 +02:00
|
|
|
|
|
2018-03-01 16:32:55 +02:00
|
|
|
|
const { IC_FW_F_ENABLED, IC_FW_F_INACTIVE } = Forms;
|
|
|
|
|
const { IC_FW_V_PROCEEDED, IC_TAG_V_TAGS } = Values;
|
2018-01-09 17:59:04 +02:00
|
|
|
|
|
|
|
|
|
const Firewall = ({
|
|
|
|
|
defaultRules = [],
|
|
|
|
|
tagRules = [],
|
|
|
|
|
expanded = false,
|
|
|
|
|
proceeded = false,
|
|
|
|
|
loading = false,
|
|
|
|
|
enabled = false,
|
|
|
|
|
handleNext,
|
2018-01-30 18:27:01 +02:00
|
|
|
|
handleEdit,
|
|
|
|
|
step
|
2018-01-09 17:59:04 +02:00
|
|
|
|
}) => (
|
|
|
|
|
<Fragment>
|
2018-01-18 16:46:49 +02:00
|
|
|
|
<Title
|
2018-01-30 18:27:01 +02:00
|
|
|
|
id={step}
|
2018-01-18 16:46:49 +02:00
|
|
|
|
onClick={!expanded && !proceeded && handleEdit}
|
2018-01-30 18:04:03 +02:00
|
|
|
|
collapsed={!expanded && !proceeded}
|
2018-02-01 17:33:58 +02:00
|
|
|
|
icon={<FirewallIcon />}
|
|
|
|
|
>
|
2018-01-18 16:46:49 +02:00
|
|
|
|
Firewall
|
|
|
|
|
</Title>
|
2018-01-09 17:59:04 +02:00
|
|
|
|
{expanded ? (
|
2018-01-15 19:23:32 +02:00
|
|
|
|
<Description>
|
2018-02-01 17:33:58 +02:00
|
|
|
|
Cloud Firewall rules control traffic across instances. Enabling the
|
|
|
|
|
firewall adds a default set of rules and rules defined by your chosen
|
|
|
|
|
tags.{' '}
|
2018-01-15 19:23:32 +02:00
|
|
|
|
<a
|
|
|
|
|
target="__blank"
|
|
|
|
|
href="https://docs.joyent.com/public-cloud/network/firewall"
|
2018-02-01 17:33:58 +02:00
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
>
|
2018-01-15 19:23:32 +02:00
|
|
|
|
Read more
|
|
|
|
|
</a>
|
|
|
|
|
</Description>
|
2018-01-09 17:59:04 +02:00
|
|
|
|
) : null}
|
2018-01-30 18:04:03 +02:00
|
|
|
|
<Flex>
|
|
|
|
|
<FlexItem>
|
2018-01-16 13:54:22 +02:00
|
|
|
|
<ReduxForm
|
2018-03-01 16:32:55 +02:00
|
|
|
|
form={IC_FW_F_ENABLED}
|
2018-01-16 13:54:22 +02:00
|
|
|
|
destroyOnUnmount={false}
|
2018-02-01 17:33:58 +02:00
|
|
|
|
forceUnregisterOnUnmount={true}
|
|
|
|
|
>
|
2018-01-16 13:54:22 +02:00
|
|
|
|
{props =>
|
|
|
|
|
expanded ? (
|
2018-01-30 18:04:03 +02:00
|
|
|
|
<Margin right={4}>
|
|
|
|
|
<ToggleFirewallForm {...props} submitting={loading} left />
|
|
|
|
|
</Margin>
|
2018-02-01 17:33:58 +02:00
|
|
|
|
) : null
|
|
|
|
|
}
|
2018-01-30 18:04:03 +02:00
|
|
|
|
</ReduxForm>
|
|
|
|
|
</FlexItem>
|
|
|
|
|
<FlexItem>
|
|
|
|
|
<ReduxForm
|
2018-03-01 16:32:55 +02:00
|
|
|
|
form={IC_FW_F_INACTIVE}
|
2018-01-30 18:04:03 +02:00
|
|
|
|
destroyOnUnmount={false}
|
2018-02-01 17:33:58 +02:00
|
|
|
|
forceUnregisterOnUnmount={true}
|
|
|
|
|
>
|
|
|
|
|
{props =>
|
|
|
|
|
enabled && expanded && !loading ? (
|
|
|
|
|
<ToggleInactiveForm {...props} />
|
|
|
|
|
) : null
|
|
|
|
|
}
|
2018-01-16 13:54:22 +02:00
|
|
|
|
</ReduxForm>
|
2018-01-30 18:04:03 +02:00
|
|
|
|
</FlexItem>
|
|
|
|
|
</Flex>
|
2018-02-01 17:33:58 +02:00
|
|
|
|
{enabled &&
|
|
|
|
|
expanded &&
|
|
|
|
|
!loading &&
|
|
|
|
|
!defaultRules.length &&
|
|
|
|
|
!tagRules.length ? (
|
2018-01-30 18:04:03 +02:00
|
|
|
|
<Margin top={4}>
|
2018-02-26 15:47:37 +02:00
|
|
|
|
<Empty borderTop>
|
|
|
|
|
Sorry, but we weren’t able to find any firewall rules.
|
|
|
|
|
</Empty>
|
2018-01-30 18:04:03 +02:00
|
|
|
|
</Margin>
|
|
|
|
|
) : null}
|
|
|
|
|
{!loading && expanded && enabled && defaultRules.length ? (
|
|
|
|
|
<Margin top={4}>
|
|
|
|
|
<DefaultRules rules={defaultRules} />
|
|
|
|
|
</Margin>
|
|
|
|
|
) : null}
|
|
|
|
|
{!loading && expanded && enabled && tagRules.length ? (
|
|
|
|
|
<Margin top={4}>
|
|
|
|
|
<TagRules rules={tagRules} />
|
|
|
|
|
</Margin>
|
|
|
|
|
) : null}
|
2018-02-01 17:33:58 +02:00
|
|
|
|
{!loading &&
|
|
|
|
|
expanded &&
|
|
|
|
|
enabled &&
|
|
|
|
|
(tagRules.length || defaultRules.length) ? (
|
2018-01-30 18:04:03 +02:00
|
|
|
|
<Margin TOP={4}>
|
|
|
|
|
<P>
|
2018-02-01 17:33:58 +02:00
|
|
|
|
*Other firewall rules may apply as defined by wildcard(s), IP(s),
|
|
|
|
|
subnet(s), tag(s) or VM(s). Please see{' '}
|
2018-01-30 18:04:03 +02:00
|
|
|
|
<a
|
|
|
|
|
href="https://apidocs.joyent.com/cloudapi/#firewall-rule-syntax"
|
|
|
|
|
target="_blank"
|
2018-02-01 17:33:58 +02:00
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
>
|
2018-01-30 18:04:03 +02:00
|
|
|
|
firewall rule list
|
|
|
|
|
</a>{' '}
|
|
|
|
|
for more details.
|
|
|
|
|
</P>
|
|
|
|
|
</Margin>
|
|
|
|
|
) : null}
|
|
|
|
|
{proceeded && !expanded ? (
|
|
|
|
|
<Margin bottom={4}>
|
2018-02-01 17:33:58 +02:00
|
|
|
|
<H3>{enabled ? 'Firewall enabled' : 'Firewall not enabled'}</H3>
|
2018-01-30 18:04:03 +02:00
|
|
|
|
</Margin>
|
|
|
|
|
) : null}
|
|
|
|
|
{expanded ? (
|
|
|
|
|
<Margin top={4} bottom={7}>
|
|
|
|
|
<Button type="button" onClick={handleNext}>
|
|
|
|
|
Next
|
|
|
|
|
</Button>
|
|
|
|
|
</Margin>
|
|
|
|
|
) : proceeded ? (
|
|
|
|
|
<Margin top={4} bottom={7}>
|
|
|
|
|
<Button type="button" onClick={handleEdit} secondary>
|
|
|
|
|
Edit
|
|
|
|
|
</Button>
|
|
|
|
|
</Margin>
|
|
|
|
|
) : null}
|
2018-01-09 17:59:04 +02:00
|
|
|
|
</Fragment>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
|
connect(
|
|
|
|
|
({ form, values }, ownProps) => ({
|
|
|
|
|
...ownProps,
|
2018-03-01 16:32:55 +02:00
|
|
|
|
proceeded: get(values, IC_FW_V_PROCEEDED, false),
|
|
|
|
|
enabled: get(form, `${IC_FW_F_ENABLED}.values.enabled`, false),
|
|
|
|
|
showInactive: get(form, `${IC_FW_F_INACTIVE}.values.inactive`, false),
|
|
|
|
|
tags: get(values, IC_TAG_V_TAGS, [])
|
2018-01-09 17:59:04 +02:00
|
|
|
|
}),
|
|
|
|
|
(dispatch, { history }) => ({
|
|
|
|
|
handleNext: () => {
|
2018-03-01 16:32:55 +02:00
|
|
|
|
dispatch(set({ name: IC_FW_V_PROCEEDED, value: true }));
|
2018-02-15 16:37:59 +02:00
|
|
|
|
return history.push(`/~create/cns${history.location.search}`);
|
2018-01-09 17:59:04 +02:00
|
|
|
|
},
|
|
|
|
|
handleEdit: () => {
|
2018-03-01 16:32:55 +02:00
|
|
|
|
dispatch(set({ name: IC_FW_V_PROCEEDED, value: true }));
|
2018-02-15 16:37:59 +02:00
|
|
|
|
return history.push(`/~create/firewall${history.location.search}`);
|
2018-01-09 17:59:04 +02:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
graphql(ListFwRules, {
|
|
|
|
|
options: ({ tags, expanded, enabled }) => ({
|
2018-02-20 02:35:31 +02:00
|
|
|
|
ssr: false,
|
2018-01-09 17:59:04 +02:00
|
|
|
|
fetchPolicy: expanded && enabled ? 'cache-first' : 'cache-only',
|
|
|
|
|
variables: {
|
|
|
|
|
tags: tags.map(({ name, value }) => ({ name, value }))
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
props: ({ ownProps, data }) => {
|
2018-01-17 21:10:39 +02:00
|
|
|
|
const { showInactive } = ownProps;
|
2018-01-09 17:59:04 +02:00
|
|
|
|
|
2018-02-01 17:33:58 +02:00
|
|
|
|
const {
|
|
|
|
|
firewall_rules_create_machine = [],
|
|
|
|
|
loading,
|
|
|
|
|
error,
|
|
|
|
|
refetch
|
|
|
|
|
} = data;
|
2018-01-09 17:59:04 +02:00
|
|
|
|
|
2018-01-25 00:40:43 +02:00
|
|
|
|
const rules = forceArray(firewall_rules_create_machine).filter(
|
|
|
|
|
({ enabled }) => enabled || showInactive
|
|
|
|
|
);
|
2018-01-09 17:59:04 +02:00
|
|
|
|
|
|
|
|
|
return {
|
2018-01-25 00:40:43 +02:00
|
|
|
|
defaultRules: rules.filter(({ rule_obj = {} }) => rule_obj.isWildcard),
|
|
|
|
|
tagRules: rules.filter(({ rule_obj = {} }) => rule_obj.tags.length),
|
2018-01-09 17:59:04 +02:00
|
|
|
|
loading,
|
|
|
|
|
error,
|
|
|
|
|
refetch
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
)(Firewall);
|