From 8d4ebe177f279188477376516706a416ba9bb48c Mon Sep 17 00:00:00 2001 From: Anmol Date: Tue, 18 Jun 2024 15:34:55 +0530 Subject: [PATCH] add formatChainID function (#495) --- clients/js/packages/client/src/client.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/clients/js/packages/client/src/client.ts b/clients/js/packages/client/src/client.ts index 7fd4629f..e569a7e2 100644 --- a/clients/js/packages/client/src/client.ts +++ b/clients/js/packages/client/src/client.ts @@ -88,6 +88,18 @@ export interface PodStatus { reason?: string; } +export const formatChainID = (input: string): string => { + // Replace underscores with hyphens + let formattedName = input.replace(/_/g, '-'); + + // Truncate the string to a maximum length of 63 characters + if (formattedName.length > 63) { + formattedName = formattedName.substring(0, 63); + } + + return formattedName; +}; + export class StarshipClient implements StarshipClientI { ctx: StarshipContext; version: string; @@ -434,13 +446,13 @@ export class StarshipClient implements StarshipClientI { if (localPort !== undefined && externalPort !== undefined) { this.exec([ "kubectl", "port-forward", - `pods/${chain.id}-genesis-0`, + `pods/${formatChainID(chain.id)}-genesis-0`, `${localPort}:${externalPort}`, ...this.getArgs(), ">", "/dev/null", "2>&1", "&" ]); - this.log(chalk.yellow(`Forwarded ${chain.id}: local ${localPort} -> target (host) ${externalPort}`)); + this.log(chalk.yellow(`Forwarded ${formatChainID(chain.id)}: local ${localPort} -> target (host) ${externalPort}`)); } } @@ -448,13 +460,13 @@ export class StarshipClient implements StarshipClientI { if (localPort !== undefined && externalPort !== undefined) { this.exec([ "kubectl", "port-forward", - `pods/${chain.id}-cometmock-0`, + `pods/${formatChainID(chain.id)}-cometmock-0`, `${localPort}:${externalPort}`, ...this.getArgs(), ">", "/dev/null", "2>&1", "&" ]); - this.log(chalk.yellow(`Forwarded ${chain.id}: local ${localPort} -> target (host) ${externalPort}`)); + this.log(chalk.yellow(`Forwarded ${formatChainID(chain.id)}: local ${localPort} -> target (host) ${externalPort}`)); } }