2020-11-05 16:03:49 +00:00
|
|
|
[
|
|
|
|
${
|
|
|
|
range(
|
|
|
|
env(
|
|
|
|
'CONSUL_NODE_COUNT',
|
|
|
|
Math.floor(
|
|
|
|
(
|
|
|
|
Math.random() * env('CONSUL_NODE_MAX', 10)
|
|
|
|
) + parseInt(env('CONSUL_NODE_MIN', 1))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).map(
|
|
|
|
function(item, i)
|
|
|
|
{
|
|
|
|
const node = `node-${i}`;
|
|
|
|
const service = location.pathname.slice(4);
|
|
|
|
const ip = fake.internet.ip();
|
|
|
|
const proxy = service.indexOf('-proxy')
|
|
|
|
const sidecar = service.indexOf('-sidecar-proxy')
|
|
|
|
const id = (proxy !== -1 ? service.slice(0, -6) + '-with-id-proxy' : service + '-with-id');
|
2021-05-26 16:52:25 +00:00
|
|
|
let kind = '';
|
2020-11-05 16:03:49 +00:00
|
|
|
switch(true) {
|
|
|
|
case service.endsWith('-mesh-gateway'):
|
|
|
|
kind = 'mesh-gateway';
|
|
|
|
break;
|
|
|
|
case service.endsWith('-terminating-gateway'):
|
|
|
|
kind = 'terminating-gateway';
|
|
|
|
break;
|
|
|
|
case service.endsWith('-ingress-gateway'):
|
|
|
|
kind = 'ingress-gateway';
|
|
|
|
break;
|
|
|
|
case service.endsWith('-proxy'):
|
|
|
|
kind = 'connect-proxy';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `
|
|
|
|
{
|
|
|
|
"Node":{
|
|
|
|
"ID":"7037e928-d9e8-3b58-4712-6f5ded209002",
|
|
|
|
"Node":"${node}",
|
|
|
|
"Address":"${ip}",
|
|
|
|
"Datacenter":"dc1",
|
|
|
|
"TaggedAddresses":{"lan":"${ip}","wan":"${ip}"},
|
|
|
|
"Meta":{"${service}-network-segment":""},
|
|
|
|
"CreateIndex":5,
|
|
|
|
"ModifyIndex":6
|
|
|
|
},
|
|
|
|
"Service":{
|
|
|
|
"ID": "${ i === 0 ? id : fake.helpers.randomize([service, service + '-ID'])}",
|
|
|
|
"Service":"${service}",
|
|
|
|
${typeof location.search.ns !== 'undefined' ? `
|
|
|
|
"Namespace": "${location.search.ns}",
|
2021-09-15 18:50:11 +00:00
|
|
|
` : ``}
|
|
|
|
${typeof location.search.partition !== 'undefined' ? `
|
2021-12-06 11:06:33 +00:00
|
|
|
"Partition": "${fake.helpers.randomize([env('CONSUL_PARTITION_EXPORTER', location.search.partition), location.search.partition])}",
|
2020-11-05 16:03:49 +00:00
|
|
|
` : ``}
|
|
|
|
"Tags":[
|
|
|
|
${
|
|
|
|
range(
|
|
|
|
env(
|
|
|
|
'CONSUL_TAG_COUNT',
|
|
|
|
Math.floor(
|
|
|
|
(
|
|
|
|
Math.random() * env('CONSUL_TAG_MAX', 10)
|
|
|
|
) + parseInt(env('CONSUL_TAG_MIN', 1))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).map(
|
|
|
|
function(item, i)
|
|
|
|
{
|
|
|
|
return `"${fake.hacker.noun()}"`;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
],
|
2021-05-26 16:52:25 +00:00
|
|
|
"Weights": {
|
|
|
|
"Passing": 1,
|
|
|
|
"Warning": 1
|
|
|
|
},
|
2020-11-05 16:03:49 +00:00
|
|
|
${ fake.random.number({min: 1, max: 10}) > 2 ? `
|
|
|
|
"Meta": {
|
|
|
|
"consul-dashboard-url": "${fake.internet.protocol()}://${fake.internet.domainName()}/?id={{Service}}",
|
2021-11-10 21:54:12 +00:00
|
|
|
"external-source": "${fake.helpers.randomize(['consul-api-gateway', 'vault', 'consul', 'nomad', 'terraform', 'kubernetes', 'aws', ''])}"
|
2020-11-05 16:03:49 +00:00
|
|
|
},
|
2021-05-26 16:52:25 +00:00
|
|
|
` : `
|
|
|
|
"Meta": null,
|
|
|
|
` }
|
|
|
|
${ false ? `
|
2020-11-05 16:03:49 +00:00
|
|
|
"Address":"${fake.internet.ip()}",
|
|
|
|
"Port":${fake.random.number({min: 0, max: 65535})},
|
2021-05-26 16:52:25 +00:00
|
|
|
` : `
|
|
|
|
"Address":"",
|
|
|
|
"SocketPath": "/${fake.lorem.words(fake.random.number({min: 1, max: 5})).split(' ').join('/')}${fake.random.boolean() ? fake.system.fileName() : ''}",
|
|
|
|
` }
|
|
|
|
"Connect": {},
|
2020-11-05 16:03:49 +00:00
|
|
|
${kind !== '' ? `
|
|
|
|
"Kind": "${kind}",
|
|
|
|
` : `` }
|
|
|
|
"Proxy": {
|
|
|
|
${proxy !== -1 && sidecar === -1 ? `
|
|
|
|
"DestinationServiceName": "${service.substr(0, proxy)}",
|
2021-05-26 16:52:25 +00:00
|
|
|
` : `
|
|
|
|
"Expose": {},
|
|
|
|
"MeshGateway": {},
|
|
|
|
"Mode": "",
|
|
|
|
"TransparentProxy": ""
|
|
|
|
`}
|
2020-11-05 16:03:49 +00:00
|
|
|
${sidecar !== -1 ? `
|
|
|
|
"DestinationServiceName": "${service.substr(0, sidecar)}",
|
|
|
|
"DestinationServiceID": "${service.substr(0, sidecar)}-ID",
|
|
|
|
"LocalServiceAddress": "${fake.internet.ip()}",
|
|
|
|
"LocalServicePort": ${fake.random.number({min: 0, max: 65535})},
|
|
|
|
` : ``}
|
|
|
|
${proxy !== -1 ? `
|
|
|
|
"Expose": {
|
|
|
|
"Checks": true,
|
|
|
|
"Paths": [
|
|
|
|
${range(env('CONSUL_EXPOSED_COUNT', 3)).map((i) => `
|
|
|
|
{
|
|
|
|
"Path": "/${fake.lorem.words(fake.random.number({min: 1, max: 5})).split(' ').join('/')}${fake.random.boolean() ? fake.system.fileName() : ''}",
|
|
|
|
"Protocol": "${fake.helpers.randomize(['http', 'http2', 'grpc'])}",
|
|
|
|
"LocalPathPort": ${fake.random.number({min: 0, max: 65535})},
|
|
|
|
"ListenerPort": ${fake.random.number({min: 0, max: 65535})}
|
|
|
|
}
|
|
|
|
`)}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"Upstreams": [
|
2021-11-16 15:36:54 +00:00
|
|
|
${range(env('CONSUL_UPSTREAM_COUNT', 10)).map((item, j) => `
|
2020-11-05 16:03:49 +00:00
|
|
|
{
|
|
|
|
"Datacenter": "${fake.address.countryCode().toLowerCase()} ${ i % 2 ? "west" : "east"}-${j}",
|
|
|
|
"DestinationName": "${fake.hacker.noun()}",
|
|
|
|
"DestinationNamespace": "${fake.hacker.noun()}",
|
2021-12-06 11:06:33 +00:00
|
|
|
"DestinationPartition": "${fake.hacker.noun()}",
|
2020-11-05 16:03:49 +00:00
|
|
|
"DestinationType": "${fake.helpers.randomize(['service', 'prepared_query'])}",
|
2021-11-16 15:36:54 +00:00
|
|
|
${fake.random.number({min: 1, max: 10}) > 5 ? `
|
2020-11-05 16:03:49 +00:00
|
|
|
"LocalBindAddress": "${fake.internet.ip()}",
|
|
|
|
"LocalBindPort": ${fake.random.number({min: 0, max: 65535})}
|
2021-05-26 16:52:25 +00:00
|
|
|
` : `
|
|
|
|
"LocalBindSocketMode": "0600",
|
|
|
|
"LocalBindSocketPath": "/${fake.lorem.words(fake.random.number({min: 1, max: 5})).split(' ').join('/')}${fake.random.boolean() ? fake.system.fileName() : ''}"
|
|
|
|
` }
|
2020-11-05 16:03:49 +00:00
|
|
|
}
|
2021-11-16 15:36:54 +00:00
|
|
|
`)}
|
2020-11-05 16:03:49 +00:00
|
|
|
]
|
|
|
|
` : ``}
|
|
|
|
},
|
|
|
|
"ProxyDestination": "",
|
|
|
|
"EnableTagOverride":false,
|
|
|
|
"CreateIndex":5,
|
|
|
|
"ModifyIndex":5
|
|
|
|
},
|
|
|
|
"Checks":[
|
|
|
|
${
|
|
|
|
range(env('CONSUL_CHECK_COUNT', 10)).map(
|
|
|
|
function(item, j) {
|
|
|
|
const passing = i > 7 || j > fake.random.number(4);
|
|
|
|
const id = fake.helpers.randomize([service, '']);
|
|
|
|
return `
|
|
|
|
{
|
|
|
|
"Node":"${node}",
|
|
|
|
"CheckID":"${fake.hacker.noun()}Health",
|
|
|
|
"Name":"${fake.hacker.noun()} Status",
|
|
|
|
"Type": "${j === 0 ? 'ttl' : (j === 1 ? 'http' : fake.helpers.randomize(['script', 'http', 'tcp', 'ttl', 'docker', 'grpc', 'alias']))}",
|
|
|
|
"Status":"${j < 2 ? 'critical' : (passing ? "passing" : fake.helpers.randomize(['warning', 'critical']))}",
|
|
|
|
"Notes":"${fake.lorem.paragraph()}",
|
|
|
|
"Output":"${fake.internet.ipv6()} ${fake.internet.protocol()}://${fake.internet.userName()}:${fake.internet.password()}@${fake.internet.domainName()} ${fake.internet.userAgent()}",
|
|
|
|
"ServiceID":"${j < 2 ? service : id}",
|
|
|
|
"ServiceName":"",
|
|
|
|
"ServiceTags":["Tag"],
|
|
|
|
"Definition":{},
|
|
|
|
"CreateIndex":5,
|
|
|
|
"ModifyIndex":5
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
]
|