From d5293d855bcbd55eab055ca10c90e615870d934e Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Wed, 5 Jul 2023 13:51:30 +0000 Subject: [PATCH] avoid prompting for tokenValue if no creds are provided Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../src/config/cmd/secure/secure.handler.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/imperative/src/config/cmd/secure/secure.handler.ts b/packages/imperative/src/config/cmd/secure/secure.handler.ts index a4fc69bd4..5ffe2efb6 100644 --- a/packages/imperative/src/config/cmd/secure/secure.handler.ts +++ b/packages/imperative/src/config/cmd/secure/secure.handler.ts @@ -60,8 +60,10 @@ export default class SecureHandler implements ICommandHandler { for (const propName of secureProps) { if (propName.endsWith(".tokenValue")) { params.response.console.log(`Processing secure properties for profile: ${config.api.profiles.getProfileNameFromPath(propName)}`); - const propValue = await this.handlePromptForAuthToken(config, propName) || + let propValue = await this.handlePromptForAuthToken(config, propName); + if (propValue === undefined) { await params.response.console.prompt(`Enter ${propName} - blank to skip: `, {hideText: true}); + } // Save the value in the config securely if (propValue) { @@ -97,7 +99,7 @@ export default class SecureHandler implements ICommandHandler { if (authHandlerClass != null) { const api = authHandlerClass.getAuthHandlerApi(); if (api.promptParams.serviceDescription != null) { - this.params.response.console.log(`Logging in to ${api.promptParams.serviceDescription}`); + this.params.response.console.log(`Logging in to ${api.promptParams.serviceDescription} - blank to skip:`); } const profile = config.api.profiles.get(profilePath.replace(/profiles\./g, ""), false); @@ -108,7 +110,9 @@ export default class SecureHandler implements ICommandHandler { if (ConnectionPropsForSessCfg.sessHasCreds(sessCfgWithCreds)) { try { - return await api.sessionLogin(new Session(sessCfgWithCreds)); + const tokenValue = await api.sessionLogin(new Session(sessCfgWithCreds)); + this.params.response.console.log("Logged in successfully"); + return tokenValue; } catch (error) { throw new ImperativeError({ msg: `Failed to fetch ${profile.tokenType} for ${propPath}: ${error.message}`, @@ -117,6 +121,8 @@ export default class SecureHandler implements ICommandHandler { } } else { this.params.response.console.log("No credentials provided."); + // return null to avoid propting for .tokenValue for this profile + return null; } } }