import React, { Fragment } from 'react'; import { withTheme } from 'styled-components'; import { Margin } from 'styled-components-spacing'; import Flex, { FlexItem } from 'styled-flex-component'; import { compose, graphql } from 'react-apollo'; import { Link } from 'react-router-dom'; import ReduxForm from 'declarative-redux-form'; import { connect } from 'react-redux'; import { change } from 'redux-form'; import get from 'lodash.get'; import forceArray from 'force-array'; import Step, { Header as StepHeader, Description as StepDescription, Preview as StepPreview, Outlet as StepOutlet } from 'joyent-ui-resource-step'; import { H3, Button, P, FirewallIcon } from 'joyent-ui-toolkit'; import { TagRules, DefaultRules, ToggleFirewallForm, ToggleInactiveForm, Empty } from 'joyent-ui-resource-widgets'; import { Forms, Values } from '../constants'; import { Preview } from './components'; import ListFwRules from '../graphql/list-fw-rules.gql'; const { IR_FW_F_ENABLED, IR_FW_F_INACTIVE } = Forms; const { IR_TAG_V_TAGS } = Values; const Firewall = ({ handleGetValue, preview = {}, defaultRules = [], tagRules = [], loading = false, enabled = false, showInactiveRules = null, showInactive = false, theme = {}, ...props }) => { const mobile = theme.screen === 'mobile'; return ( }>Firewall rules Cloud firewall rules secure instances by defining network traffic rules, controlling incoming and outgoing traffic. Enabling the firewall applies only rules which match your instance. Although these rules are created in the firewall console, the addition of tags can alter the firewall rules. {({ next }) => ( {props => ( )} {props => enabled && !loading ? ( ) : null } {enabled && !loading && !defaultRules.length && !tagRules.length ? (

No Firewall rules found

Try viewing inactive rules instead to see firewalls that can potentially affect your instance

) : null} {!loading && enabled && defaultRules.length ? ( ) : null} {!loading && enabled && tagRules.length ? ( ) : null} {!loading && enabled && (tagRules.length || defaultRules.length) ? (

*Other firewall rules may apply as defined by wildcard(s), IP(s), subnet(s), tag(s) or VM(s). Please see{' '} firewall rule list {' '} for more details.

) : null}
)}
); }; export default compose( connect(({ form, values }, ownProps) => ({ ...ownProps, enabled: get(form, `${IR_FW_F_ENABLED}.values.enabled`, false), showInactive: get(form, `${IR_FW_F_INACTIVE}.values.inactive`, false), tags: get(values, IR_TAG_V_TAGS, []) })), graphql(ListFwRules, { options: ({ tags, expanded, enabled }) => ({ ssr: false, fetchPolicy: expanded && enabled ? 'cache-first' : 'cache-only', variables: { tags: tags.map(({ name, value }) => ({ name, value })) } }), props: ({ ownProps, data }) => { const { enabled, showInactive } = ownProps; const { firewall_rules_create_machine = [], loading, error, refetch } = data; const rules = forceArray(firewall_rules_create_machine).filter( ({ enabled }) => enabled || showInactive ); const defaultRules = rules.filter( ({ rule_obj = {} }) => rule_obj.isWildcard ); const tagRules = rules.filter( ({ rule_obj = {} }) => rule_obj.tags.length ); return { defaultRules, tagRules, loading, error, refetch, handleGetValue: () => ({ enabled, defaultRules, tagRules }) }; } }), connect(null, (dispatch, { ...args }) => ({ showInactiveRules: () => dispatch(change(IR_FW_F_INACTIVE, 'inactive', true)) })) )(withTheme(({ ...rest }) => ));