Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added 2 new rules and other changes in db, ingress and deployments #231

Open
wants to merge 11 commits into
base: v0.22.0-old
Choose a base branch
from
1 change: 1 addition & 0 deletions src/components/ingress-routing/IngressRoutingModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const IngressRoutingModal = props => {
form.validateFields().then(values => {
values = Object.assign({}, formInitialValues, values)
try {
values.url = values.url.trim()
if (!values.allowSpecificHosts) values.allowedHosts = ["*"]
if (!values.allowSpecificMethods) values.allowedMethods = ["*"]
if (!values.performRewrite) values.rewrite = undefined
Expand Down
181 changes: 166 additions & 15 deletions src/components/security-rules/configure-rule/ConfigureRule.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,11 @@ const parseNumber = (value) => {
return !isNaN(value) ? Number(value) : value
}

const parseArray = (value, type) => {
if (!value.includes(",")) {
return value
}
return value.split(",").map(value => value.trim()).map(value => parseValue(value, type))
}

const isTypeOfFieldsString = (fields) => {
return typeof fields === "string"
}

const rules = ['allow', 'deny', 'authenticated', 'match', 'and', 'or', 'query', 'webhook', 'force', 'remove', 'encrypt', 'decrypt', 'hash'];
const rules = ['allow', 'deny', 'authenticated', 'match', 'and', 'or', 'query', 'webhook', 'force', 'remove', 'encrypt', 'decrypt', 'hash', 'graphql', 'transform'];

const ConfigureRule = (props) => {
// form
Expand All @@ -165,7 +158,8 @@ const ConfigureRule = (props) => {
const [col, setCol] = useState('');

// Derived properties
const { rule, type, f1, f2, error, fields, field, value, url, store, outputFormat, claims, requestTemplate, db, cache } = props.selectedRule;
const { rule, type, f1, f2, error, field, value, url, store, outputFormat, claims, requestTemplate, db, cache, graphqlQuery, graphqlVariables } = props.selectedRule;
let { fields } = props.selectedRule;
const dbConfigs = useSelector(state => getDbConfigs(state))
const dbList = Object.keys(dbConfigs)
const [selectedDb, setSelectedDb] = useState(db);
Expand All @@ -181,7 +175,10 @@ const ConfigureRule = (props) => {
switch (values.rule) {
case "match":
if (values.eval === 'in' || values.eval === 'notIn') {
values.f2 = parseArray(values.f2, values.type)
values.f2 = values.loadVar ? values.singleInputFields : values.multipleInputFields
delete values["loadVar"]
delete values["singleInputFields"]
delete values["multipleInputFields"]
} else {
values.f1 = parseValue(values.f1, values.type)
values.f2 = parseValue(values.f2, values.type)
Expand Down Expand Up @@ -213,6 +210,15 @@ const ConfigureRule = (props) => {
values.template = "go"
}

delete values["applyTransformations"]
break;
case "graphql":
break;
case "transform":
if (values["applyTransformations"]) {
values.template = "go"
}

delete values["applyTransformations"]
break;
}
Expand All @@ -223,7 +229,7 @@ const ConfigureRule = (props) => {
if (!props.selectedRule.clauses) values.clauses = [];
else values.clauses = props.selectedRule.clauses
}
if (values.rule === "query" || values.rule === "webhook" || values.rule === "force" || values.rule === "remove" || values.rule === "encrypt" || values.rule === "decrypt" || values.rule === "hash") {
if (values.rule === "query" || values.rule === "webhook" || values.rule === "force" || values.rule === "remove" || values.rule === "encrypt" || values.rule === "decrypt" || values.rule === "hash" || values.rule === "graphql" || values.rule === "transform") {
values.clause = props.selectedRule.clause
values.fields = values.loadVar ? values.singleInputFields : values.multipleInputFields
delete values["loadVar"]
Expand Down Expand Up @@ -287,6 +293,7 @@ const ConfigureRule = (props) => {
}

const inheritedDataType = getTypeFromValue(value)
fields = rule === "match" ? f2 : fields
const formInitialValues = {
rule,
type: (rule === "force") ? inheritedDataType : type,
Expand All @@ -312,7 +319,9 @@ const ConfigureRule = (props) => {
error,
cacheResponse: cache ? true : false,
cacheTTL: cache && cache.ttl !== undefined && cache.ttl !== null ? cache.ttl : undefined,
cacheInstantInvalidate: cache && cache.instantInvalidate !== undefined && cache.instantInvalidate !== null ? cache.instantInvalidate : undefined
cacheInstantInvalidate: cache && cache.instantInvalidate !== undefined && cache.instantInvalidate !== null ? cache.instantInvalidate : undefined,
graphqlQuery,
graphqlVariables
}

if (formInitialValues.type === "object") {
Expand Down Expand Up @@ -393,9 +402,80 @@ const ConfigureRule = (props) => {
() => {
const type = form.getFieldValue("type")
return (
<Form.Item name='f2' rules={[{ required: true }, { validator: createValueAndTypeValidator(type, true) }]}>
<ObjectAutoComplete placeholder="Second operand" options={autoCompleteOptions} />
</Form.Item>
<>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

<ConditionalFormBlock
dependency='eval'
condition={() => form.getFieldValue('eval') !== 'in' && form.getFieldValue('eval') !== 'notIn'}
>
<Form.Item name='f2' rules={[{ required: true }, { validator: createValueAndTypeValidator(type, true) }]}>
<ObjectAutoComplete placeholder="Second operand" options={autoCompleteOptions} />
</Form.Item>
</ConditionalFormBlock>
<ConditionalFormBlock
dependency='eval'
condition={() => form.getFieldValue('eval') === 'in' || form.getFieldValue('eval') === 'notIn'}
>
<Form.Item name="loadVar" valuePropName="checked">
<Checkbox>
Load fields from a variable
</Checkbox>
</Form.Item>
<ConditionalFormBlock dependency='loadVar' condition={() => form.getFieldValue('loadVar')}>
<Row>
<Col span={14}>
<Form.Item name="singleInputFields">
<Input placeholder="Variable to load fields from" />
</Form.Item>
</Col>
</Row>
</ConditionalFormBlock>
<ConditionalFormBlock dependency='loadVar' condition={() => !form.getFieldValue('loadVar')}>
<Form.List name='multipleInputFields'>
{(fields, { add, remove }) => {
return (
<>
{fields.map((field, index) => (
<Row key={field.key}>
<Col span={14}>
<Form.Item
name={[field.name]}
key={[field.name]}
rules={[
{ required: true },
{ validator: createValueAndTypeValidator("variable", false), validateTrigger: "onBlur" }
]}
>
<ObjectAutoComplete placeholder="Field" options={autoCompleteOptions} />
</Form.Item>
</Col>
<Col span={2}>
<CloseOutlined
style={{ margin: '0 8px' }}
onClick={() => {
remove(field.name);
}}
/>
</Col>
</Row>
))}
<Form.Item>
<Button
type='dashed'
onClick={() => {
add();
}}
style={{ width: '40%' }}
>
<PlusOutlined /> Add field
</Button>
</Form.Item>
</>
);
}}
</Form.List>
</ConditionalFormBlock>
</ConditionalFormBlock>
</>
)
}
}
Expand Down Expand Up @@ -685,6 +765,77 @@ const ConfigureRule = (props) => {
</ConditionalFormBlock>
</ConditionalFormBlock>
</ConditionalFormBlock>
<ConditionalFormBlock
dependency='rule'
condition={() => form.getFieldValue('rule') === 'graphql'}
>
<FormItemLabel name='Query' style={{ border: '1px solid #D9D9D9' }} />
<Form.Item name="graphqlQuery" rules={[{ required: true }]}>
<JSONCodeMirror />
</Form.Item>
<FormItemLabel name='Variables' style={{ border: '1px solid #D9D9D9' }} />
<Form.Item name="graphqlVariables" rules={[{ required: true }]}>
<JSONCodeMirror />
</Form.Item>
<FormItemLabel name="Store" hint="(Optional)" />
<FormItem name="store" rules={[{ required: false }]}>
<Input placeholder="The variable to store the query response. For example: args.res" />
</FormItem>
</ConditionalFormBlock>
<ConditionalFormBlock
dependency="rule"
condition={() => form.getFieldValue('rule') === "transform"} >
<FormItemLabel name="Store" hint="(Optional)" />
<FormItem name="store" rules={[{ required: false }]}>
<Input placeholder="The variable to store the transform response. For example: args.res" />
</FormItem>
<FormItemLabel name='Apply transformations' />
<Form.Item name='applyTransformations' valuePropName='checked'>
<Checkbox>
Transform the request body using templates
</Checkbox>
</Form.Item>
<ConditionalFormBlock
dependency='applyTransformations'
condition={() => form.getFieldValue('applyTransformations') === true}
>
<Alert
message={<AlertMsgApplyTransformations />}
type='info'
showIcon
style={{ marginBottom: 21 }}
/>
<FormItemLabel name="Template output format" description="Format for parsing the template output" />
<Form.Item name="outputFormat">
<Select style={{ width: 96 }}>
<Option value='yaml'>YAML</Option>
<Option value='json'>JSON</Option>
</Select>
</Form.Item>
<FormItemLabel name="JWT claims template" hint="(Optional)" description="Template to generate the transformed claims of the request" />
<Form.Item name="claims">
<AntCodeMirror style={{ border: "1px solid #D9D9D9" }} options={{
mode: { name: 'go' },
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
autoCloseBrackets: true,
tabSize: 2
}} />
</Form.Item>
<FormItemLabel name="Request template" hint="(Optional)" description="Template to generate the transformed request body" />
<Form.Item name='requestTemplate' >
<AntCodeMirror style={{ border: "1px solid #D9D9D9" }} options={{
mode: { name: 'go' },
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
autoCloseBrackets: true,
tabSize: 2
}} />
</Form.Item>
</ConditionalFormBlock>
</ConditionalFormBlock>
<FormItemLabel name='Customize error message' />
<Form.Item name='errorMsg' valuePropName='checked'>
<Checkbox checked={error ? true : false}>
Expand Down
26 changes: 1 addition & 25 deletions src/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import dotprop from "dot-prop-immutable";

const lorem = new LoremIpsum();

const primitiveTypes = ["ID", "String", "Float", "Integer", "Boolean", "Date", "Time", "DateTime", "JSON", "SmallInteger", "BigInteger", "Decimal", "Char", "Varchar", "DateTimeWithZone"]
const primitiveTypes = ["ID", "String", "Float", "Integer", "Boolean", "Date", "Time", "DateTime", "JSON"]
const getDefType = (type, isArray, required) => {
isArray = isArray ? true : type.kind === "ListType";
required = required ? true : type.kind === "NonNullType";
Expand Down Expand Up @@ -183,18 +183,6 @@ const generateRandomValue = (type) => {
return "2017-11-13T03:15:45.108Z"
case "JSON":
return { foo: "bar" }
case "SmallInteger":
return 12
case "BigInteger":
return 4323
case "Decimal":
return 23.84
case "Char":
return "F919mV2W1ifQy9wlNyYnoOoqUM1"
case "Varchar":
return "7mr8VjGnCCerZUyzC9YDCn8Oxku"
case "DateTimeWithZone":
return "2021-11-22T03:15:45.108"
default:
return type
}
Expand All @@ -218,18 +206,6 @@ const generateRandomValue = (type) => {
return new Date().toISOString()
case "JSON":
return { foo: "bar" }
case "SmallInteger":
return Math.ceil(Math.random() * 100)
case "BigInteger":
return Math.ceil(Math.random() * 10000)
case "Decimal":
return Number((Math.random() * 100).toFixed(2))
case "Char":
return generateId(6)
case "Varchar":
return generateId(6)
case "DateTimeWithZone":
return new Date().toISOString()
default:
return type
}
Expand Down
Loading