Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
avoid prompting for tokenValue if no creds are provided
Browse files Browse the repository at this point in the history
Signed-off-by: zFernand0 <[email protected]>
  • Loading branch information
zFernand0 committed Jul 5, 2023
1 parent 090cbf8 commit d5293d8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/imperative/src/config/cmd/secure/secure.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 63 in packages/imperative/src/config/cmd/secure/secure.handler.ts

View workflow job for this annotation

GitHub Actions / lint

'propValue' is never reassigned. Use 'const' instead
if (propValue === undefined) {
await params.response.console.prompt(`Enter ${propName} - blank to skip: `, {hideText: true});
}

// Save the value in the config securely
if (propValue) {
Expand Down Expand Up @@ -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);
Expand All @@ -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}`,
Expand All @@ -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;
}
}
}
Expand Down

0 comments on commit d5293d8

Please sign in to comment.