Skip to content

Commit 171122f

Browse files
commit after resolving bugs
1 parent 059c6d3 commit 171122f

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

src/lib/httpClient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,8 @@ export default class httpClient {
158158
let authResult = 1;
159159
let userName = '';
160160
let passWord = '';
161-
if (ctx.config.tunnel?.user) {
161+
if (ctx.config.tunnel && ctx.config.tunnel?.user && ctx.config.tunnel?.key) {
162162
userName = ctx.config.tunnel.user
163-
}
164-
if (ctx.config.tunnel?.key) {
165163
passWord = ctx.config.tunnel.key
166164
}
167165
if (this.projectToken) {
@@ -191,7 +189,7 @@ export default class httpClient {
191189
}
192190
return { authResult, orgId, userId };
193191
} else {
194-
throw new Error('Authentication failed, project token not received');
192+
throw new Error('Authentication failed, project token not received. Refer to the smartui.log file for more information');
195193
}
196194
}
197195

src/lib/schemaValidation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ const ConfigSchema = {
192192
type: "object",
193193
properties: {
194194
type: {
195-
type: "string",
196-
errorMessage: "Invalid config; type is mandatory of type string"
195+
type: "string",
196+
enum: ["auto", "manual"],
197+
errorMessage: "Invalid config; type is mandatory of type string having value auto or manual",
197198
},
198199
tunnelName: {
199200
type: "string",
@@ -208,7 +209,7 @@ const ConfigSchema = {
208209
errorMessage: "Invalid config; key should be a string value"
209210
},
210211
port: {
211-
type: "number",
212+
type: "string",
212213
errorMessage: "Invalid config; port should be a string value"
213214
},
214215
proxyHost: {

src/lib/snapshotQueue.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Snapshot, Context } from "../types.js";
33
import constants from "./constants.js";
44
import processSnapshot from "./processSnapshot.js"
55
import { v4 as uuidv4 } from 'uuid';
6-
import { startPolling } from "./utils.js";
6+
import { startPolling, stopTunnelHelper } from "./utils.js";
77

88
export default class Queue {
99
private snapshots: Array<Snapshot> = [];
@@ -272,7 +272,7 @@ export default class Queue {
272272
this.processingSnapshot = snapshot?.name;
273273
let drop = false;
274274

275-
if (this.ctx.isStartExec) {
275+
if (this.ctx.isStartExec && !this.ctx.config.tunnel) {
276276
this.ctx.log.info(`Processing Snapshot: ${snapshot?.name}`);
277277
}
278278

@@ -344,6 +344,9 @@ export default class Queue {
344344
useKafkaFlow: resp.data.useKafkaFlow || false,
345345
}
346346
} else {
347+
if (this.ctx.config.tunnel && this.ctx.config.tunnel?.type === 'auto') {
348+
await stopTunnelHelper(this.ctx)
349+
}
347350
throw new Error('SmartUI capabilities are missing in env variables or in driver capabilities');
348351
}
349352
if (this.ctx.options.fetchResults) {

src/lib/utils.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ export async function startTunnelBinary(ctx: Context) {
375375
}
376376
if (tunnelConfig?.v) {
377377
tunnelArguments.v = tunnelConfig.v
378+
tunnelArguments.logLevel = 'debug'
378379
}
379380
if (tunnelConfig?.logFile) {
380381
tunnelArguments.logFile = tunnelConfig.logFile
@@ -394,8 +395,8 @@ export async function startTunnelBinary(ctx: Context) {
394395
if (ctx.config.tunnel?.type === 'auto') {
395396
tunnelInstance = new lambdaTunnel();
396397
const istunnelStarted = await tunnelInstance.start(tunnelArguments);
397-
ctx.log.debug('Tunnel is started Successfully');
398-
const tunnelRunningStatus = tunnelInstance.isRunning();
398+
ctx.log.debug('Tunnel is started Successfully with status ' + istunnelStarted);
399+
const tunnelRunningStatus = await tunnelInstance.isRunning();
399400
ctx.log.debug('Running status of tunnel after start ? ' + tunnelRunningStatus);
400401
}
401402
}
@@ -416,7 +417,7 @@ export async function startPollingForTunnel(ctx: Context, build_id: string, base
416417
ctx.log.info("Error: Build data is null.");
417418
clearInterval(intervalId);
418419

419-
const tunnelRunningStatus = tunnelInstance.isRunning();
420+
const tunnelRunningStatus = await tunnelInstance.isRunning();
420421
ctx.log.debug('Running status of tunnel before stopping ? ' + tunnelRunningStatus);
421422

422423
const status = await tunnelInstance.stop();
@@ -428,7 +429,7 @@ export async function startPollingForTunnel(ctx: Context, build_id: string, base
428429
if (resp.build.build_status_ind === constants.BUILD_COMPLETE || resp.build.build_status_ind === constants.BUILD_ERROR) {
429430
clearInterval(intervalId);
430431

431-
const tunnelRunningStatus = tunnelInstance.isRunning();
432+
const tunnelRunningStatus = await tunnelInstance.isRunning();
432433
ctx.log.debug('Running status of tunnel before stopping ? ' + tunnelRunningStatus);
433434

434435
const status = await tunnelInstance.stop();
@@ -447,5 +448,15 @@ export async function startPollingForTunnel(ctx: Context, build_id: string, base
447448
}, 5000);
448449
}
449450

451+
export async function stopTunnelHelper(ctx: Context) {
452+
const tunnelRunningStatus = await tunnelInstance.isRunning();
453+
ctx.log.debug('Running status of tunnel before stopping ? ' + tunnelRunningStatus);
454+
455+
if (tunnelRunningStatus) {
456+
const status = await tunnelInstance.stop();
457+
ctx.log.debug('Tunnel is Stopped ? ' + status);
458+
}
459+
}
460+
450461

451462

src/tasks/createBuildExec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ListrTask, ListrRendererFactory } from 'listr2';
22
import { Context } from '../types.js'
33
import chalk from 'chalk';
44
import { updateLogContext } from '../lib/logger.js';
5-
import { startTunnelBinary, startPollingForTunnel } from '../lib/utils.js';
5+
import { startTunnelBinary, startPollingForTunnel, stopTunnelHelper } from '../lib/utils.js';
66

77
export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRendererFactory> => {
88
return {
@@ -42,6 +42,9 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
4242
} else {
4343
task.output = chalk.gray(`Empty PROJECT_TOKEN and PROJECT_NAME. Skipping Creation of Build!`)
4444
task.title = 'Skipped SmartUI build creation'
45+
if (ctx.config.tunnel && ctx.config.tunnel?.type === 'auto') {
46+
await stopTunnelHelper(ctx)
47+
}
4548
}
4649

4750
if (ctx.config.tunnel && ctx.config.tunnel?.type === 'auto') {
@@ -72,6 +75,9 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
7275
}
7376
} catch (error: any) {
7477
ctx.log.debug(error);
78+
if (ctx.config.tunnel && ctx.config.tunnel?.type === 'auto') {
79+
await stopTunnelHelper(ctx)
80+
}
7581
if (errorCode === 1) {
7682
task.output = chalk.gray(error.message);
7783
throw new Error('Skipped SmartUI build creation');

0 commit comments

Comments
 (0)