@autofleet/cli 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import yargs from 'yargs';
3
3
  import { hideBin } from 'yargs/helpers';
4
- import { connectAndGetPrefix, terminalCommand } from './utils/index.js';
4
+ import path from 'path';
5
+ import { connectAndGetPrefix, parseIps, terminalCommand } from './utils/index.js';
5
6
 
6
7
  yargs(hideBin(process.argv))
7
8
  .command({
@@ -22,16 +23,14 @@ yargs(hideBin(process.argv))
22
23
  command: 'getIps',
23
24
  describe: '--service=driver-ms --variationId=${yourVariationUuid} --cluster=dev1/e2eManager',
24
25
  async handler(argv) {
25
- const { cluster, variationId, service } = argv;
26
+ const { cluster, variationId } = argv;
26
27
  const prefix = await connectAndGetPrefix({
27
28
  clusterName: cluster,
28
29
  variationId,
29
30
  });
30
31
  await terminalCommand(`kubectl ${prefix} get services > ips`);
31
- const CAT_IPS = 'cat ips';
32
- const getServicesCommand = service ? `${CAT_IPS} | grep ${service}` : CAT_IPS;
33
- const serviceLine = await terminalCommand(getServicesCommand);
34
- console.log(serviceLine);
32
+ const ips = parseIps(`${path.resolve()}/ips`);
33
+ ips.forEach((ip) => console.log(ip));
35
34
  },
36
35
  })
37
36
  .command({
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { promisify } from 'util';
3
3
  import { exec } from 'child_process';
4
+ import fs from 'fs';
4
5
 
5
6
  const asyncExec = promisify(exec);
6
-
7
+ const SERVICE_NAME_INDEX = 0;
8
+ const EXTERNAL_IP_INDEX = 6;
9
+ const IP_LINE_SUFFIX = 'SERVICE_HOST';
7
10
  const CLUSTER_TO_CMD_MAP = {
8
11
  dev1: 'gcloud container clusters get-credentials dev-cluster-2 --region europe-west1 --project dev1-experiment-manager',
9
12
  e2eManager: 'gcloud container clusters get-credentials e2e-cluster-1 --region europe-west1 --project e2e-manager',
@@ -20,3 +23,17 @@ export const connectAndGetPrefix = async ({ clusterName, variationId }) => {
20
23
  await connectToCluster(clusterName);
21
24
  return `--namespace=${variationId}`;
22
25
  };
26
+ export const parseIps = (ipsFilePath) => {
27
+ const ipLines = fs.readFileSync(ipsFilePath, 'utf-8').split('\n');
28
+ ipLines.shift();
29
+
30
+ let formattedIps = ipLines.map((ipLine) => {
31
+ const splittedLine = ipLine.split(/(\s+)/);
32
+ const serviceName = splittedLine[SERVICE_NAME_INDEX].replace(/-/g, '_').toUpperCase();
33
+ const loadBalancerIp = splittedLine[EXTERNAL_IP_INDEX];
34
+ const formattedLine = `${serviceName}_${IP_LINE_SUFFIX}=${loadBalancerIp}`;
35
+ return formattedLine;
36
+ });
37
+ formattedIps = formattedIps.filter((formattedIp) => !formattedIp.includes('none') && !formattedIp.includes('undefined'));
38
+ return formattedIps;
39
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/cli",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {