2020-11-05 16:03:49 +00:00
|
|
|
${range(1).map(item => {
|
|
|
|
const ID = fake.random.uuid();
|
|
|
|
const legacy = ID.indexOf('%3A') === -1;
|
|
|
|
const source = location.search.source.split('/');
|
|
|
|
const destination = location.search.destination.split('/');
|
2022-06-23 13:16:26 +00:00
|
|
|
const sourceIsPeered = !!source[0].match(/^peer:/)?.length
|
|
|
|
|
|
|
|
const sourcePeerString = `"SourcePeer": "${source[0].split(':')[1]}",`
|
|
|
|
const sourcePartitionString = `"SourcePartition": "${source[0]}",`
|
2020-11-05 16:03:49 +00:00
|
|
|
return `
|
|
|
|
{
|
|
|
|
"ID": "${legacy ? ID : ''}"
|
|
|
|
${ http.method !== "PUT" ? `
|
|
|
|
,"Description": "${fake.lorem.sentence()}",
|
2021-09-24 16:31:58 +00:00
|
|
|
"SourceName": "${source[2]}",
|
|
|
|
"DestinationName": "${destination[2]}",
|
|
|
|
"SourceNS": "${source[1]}",
|
|
|
|
"DestinationNS": "${destination[1]}",
|
2022-06-23 13:16:26 +00:00
|
|
|
${sourceIsPeered ? sourcePeerString : sourcePartitionString}
|
2021-09-24 16:31:58 +00:00
|
|
|
"DestinationPartition": "${destination[0]}",
|
2020-11-05 16:03:49 +00:00
|
|
|
"SourceType": "${fake.helpers.randomize(['consul', 'externaluri'])}",
|
|
|
|
${legacy ? `
|
|
|
|
"Action": "${fake.helpers.randomize(['allow', 'deny'])}",
|
|
|
|
`:``}
|
|
|
|
${!legacy ? `
|
|
|
|
"Permissions": [
|
|
|
|
${range(
|
|
|
|
env(
|
|
|
|
'CONSUL_INTENTION_PERMISSION_COUNT',
|
|
|
|
Math.floor(
|
|
|
|
(
|
|
|
|
Math.random() * env('CONSUL_INTENTION_PERMISSION_MAX', 10)
|
|
|
|
) + parseInt(env('CONSUL_INTENTION_PERMISSION_MIN', 1))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).map((item, i) => {
|
|
|
|
const headerCount = env(
|
|
|
|
'CONSUL_HEADER_COUNT',
|
|
|
|
Math.floor(
|
|
|
|
(
|
|
|
|
Math.random() * env('CONSUL_HEADER_MAX', 3)
|
|
|
|
) + parseInt(env('CONSUL_HEADER_MIN', 1))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const path = fake.helpers.randomize(['PathExact', 'PathPrefix', 'PathRegex', '']);
|
|
|
|
return `
|
|
|
|
{
|
|
|
|
"Action": "${fake.helpers.randomize(['allow', 'deny'])}",
|
|
|
|
"HTTP": {
|
|
|
|
${path !== '' ? `
|
|
|
|
"${path}": "${path === 'PathRegex' ? `${fake.helpers.randomize(['^[0-9]{1,3}?$', '(\w+)\s(\w+)'])}` : `/${fake.lorem.words(fake.random.number({min: 1, max: 5})).split(' ').join('/')}${fake.random.boolean() ? fake.system.fileName() : ''}`}",
|
|
|
|
`:``}
|
|
|
|
|
|
|
|
${ fake.random.boolean() ? `
|
|
|
|
"Methods": [
|
|
|
|
${
|
|
|
|
fake.helpers.shuffle(
|
|
|
|
["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"]
|
|
|
|
).filter(item => fake.random.boolean()).map(item => `
|
|
|
|
"${item}"
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
],
|
|
|
|
` : ``}
|
|
|
|
"Header": [
|
|
|
|
${range(headerCount).map(item => `
|
|
|
|
{
|
|
|
|
"Name": "X-${fake.hacker.noun().split(' ').map(item => `${item.substr(0, 1).toUpperCase()}${item.substr(1)}`).join('-')}",
|
|
|
|
${fake.random.boolean() ? `
|
|
|
|
"Invert": true,
|
|
|
|
` : ``}
|
|
|
|
${fake.helpers.randomize([
|
|
|
|
'"Present": true',
|
|
|
|
'"Exact": "abc"',
|
|
|
|
'"Prefix": "abc"',
|
|
|
|
'"Suffix": "xyz"',
|
|
|
|
'"Regex": "[abc]"'
|
|
|
|
])}
|
|
|
|
}
|
|
|
|
`)}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`})}
|
|
|
|
],
|
|
|
|
`:``}
|
|
|
|
"Precedence": ${fake.random.number({min: 1, max: 100})},
|
2021-12-13 15:02:36 +00:00
|
|
|
${ (!legacy || source[1] === "external-source") && fake.random.number({min: 1, max: 10}) > 2 ? `
|
2020-11-05 16:03:49 +00:00
|
|
|
"Meta": {
|
2021-11-10 21:54:12 +00:00
|
|
|
"external-source": "${fake.helpers.randomize(['kubernetes', 'consul-api-gateway'])}"
|
2020-11-05 16:03:49 +00:00
|
|
|
},
|
|
|
|
` : `` }
|
|
|
|
"CreatedAt": "2018-05-21T16:41:27.977155457Z",
|
|
|
|
"UpdatedAt": "2018-05-21T16:41:27.977157724Z",
|
|
|
|
"CreateIndex": 11,
|
|
|
|
"ModifyIndex": 11
|
|
|
|
` : ``}
|
|
|
|
}
|
|
|
|
`})}
|