Skip to content

Commit

Permalink
fix: various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 22, 2020
1 parent 6f082ad commit 3effb85
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 19 deletions.
3 changes: 2 additions & 1 deletion messages/list.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"description": "list auth connection information"
"description": "list auth connection information",
"noResultsFound": "No results found"
}
2 changes: 1 addition & 1 deletion messages/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"instanceUrl": "the login URL of the instance the org lives on",
"authorizeCommandSuccess": "Successfully authorized %s with org ID %s",
"authorizeCommandCloseBrowser": "You may now close the browser",
"warnAuth": "Logging in to a business or production org is not recommended on a demo or shared machine. Please run \"sfdx auth:logout --targetusername <your username> --noprompt\" when finished using this org, which is similar to logging out of the org in the browser.\n\nDo you want to authorize this org, %s, for use with the Salesforce CLI (y/n)?",
"warnAuth": "Logging in to a business or production org is not recommended on a demo or shared machine. Please run \"sfdx auth:logout --targetusername <your username> --noprompt\" when finished using this org, which is similar to logging out of the org in the browser.\n\nDo you want to authorize this org for use with the Salesforce CLI (y/n)?",
"noPromptAuth": "do not prompt for auth confirmation in demo mode",
"disableMasking": "disable masking of user input (for use with problematic terminals)",
"clientSecretStdin": "OAuth client secret of personal connected app?"
Expand Down
2 changes: 1 addition & 1 deletion messages/sfdxurl.store.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "authorize an org using an SFDX auth URL\nThe file must have the format \"%s\" or \"%s\".\nThe file must contain only the URL or be a JSON file that has a top-level property named sfdxAuthUrl.\nUse this command to get the SFDX auth URL for a Dev Hub org you have already authorized:\n\n $ sfdx force:org:display -u <DevHub> --verbose",
"description": "authorize an org using an SFDX auth URL\nAuthorize a Salesforce org using an SFDX auth URL stored within a file. The file must have the format \"%s\" or \"%s\".\nThe file must contain only the URL or be a JSON file that has a top-level property named sfdxAuthUrl.\nUse this command to get the SFDX auth URL for a Dev Hub org you have already authorized:\n\n $ sfdx force:org:display -u <DevHub> --verbose",
"file": "path to a file containing the sfdx url",
"examples": [
"sfdx auth:sfdxurl:store -f <path to sfdxAuthUrl file>",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"dependencies": {
"@oclif/config": "^1.17.0",
"@salesforce/command": "^3.0.3",
"@salesforce/core": "^2.13.0",
"@salesforce/core": "^2.14.0",
"@salesforce/kit": "^1.3.3",
"chalk": "^4.1.0",
"open": "^7.3.0",
"tslib": "^1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/commands/auth/device/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class Login extends SfdxCommand {
if (approval) {
const authInfo = await deviceOauthService.authorizeAndSave(approval);
await Common.handleSideEffects(authInfo, this.flags);
const fields = authInfo.getFields();
const fields = authInfo.getFields(true);
const successMsg = messages.getMessage('success', [fields.username]);
this.ux.log(successMsg);
return fields;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/auth/jwt/grant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class Grant extends SfdxCommand {
try {
const authInfo = await this.initAuthInfo();
await Common.handleSideEffects(authInfo, this.flags);
result = authInfo.getFields();
result = authInfo.getFields(true);
} catch (err) {
throw SfdxError.create('@salesforce/plugin-auth', 'jwt.grant', 'JwtGrantError', [err.message]);
}
Expand Down
21 changes: 13 additions & 8 deletions src/commands/auth/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ export default class List extends SfdxCommand {
public static readonly description = messages.getMessage('description');
public static readonly flagsConfig: FlagsConfig = {};
public async run(): Promise<Authorization[]> {
const auths = await AuthInfo.listAllAuthorizations();
const hasErrors = auths.filter((auth) => !!auth.error).length > 0;
const columns = ['alias', 'username', 'orgId', 'instanceUrl', 'oauthMethod'];
if (hasErrors) {
columns.push('error');
try {
const auths = await AuthInfo.listAllAuthorizations();
const hasErrors = auths.filter((auth) => !!auth.error).length > 0;
const columns = ['alias', 'username', 'orgId', 'instanceUrl', 'oauthMethod'];
if (hasErrors) {
columns.push('error');
}
this.ux.styledHeader('authenticated orgs');
this.ux.table(auths, columns);
return auths;
} catch (err) {
this.ux.log(messages.getMessage('noResultsFound'));
return [];
}
this.ux.styledHeader('authenticated orgs');
this.ux.table(auths, columns);
return auths;
}
}
2 changes: 1 addition & 1 deletion src/commands/auth/sfdxurl/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class Store extends SfdxCommand {

await Common.handleSideEffects(authInfo, this.flags);

const result = authInfo.getFields();
const result = authInfo.getFields(true);
const successMsg = commonMessages.getMessage('authorizeCommandSuccess', [result.username, result.orgId]);
this.ux.log(successMsg);
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/auth/web/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class Login extends SfdxCommand {
try {
const authInfo = await this.executeLoginFlow(oauthConfig);
await Common.handleSideEffects(authInfo, this.flags);
const fields = authInfo.getFields();
const fields = authInfo.getFields(true);
const successMsg = commonMessages.getMessage('authorizeCommandSuccess', [fields.username, fields.orgId]);
this.ux.log(successMsg);
return fields;
Expand Down
14 changes: 11 additions & 3 deletions src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@
*/
import { Messages, Global, Mode } from '@salesforce/core';
import { UX } from '@salesforce/command';
import * as chalk from 'chalk';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'messages');

function dimMessage(message: string): string {
return chalk.dim(message);
}

export class Prompts {
public static async shouldExitCommand(ux: UX, noPrompt?: boolean, message?: string): Promise<boolean> {
if (noPrompt || Global.getEnvironmentMode() !== Mode.DEMO) {
return false;
} else {
const answer = await ux.prompt(message || messages.getMessage('warnAuth'));
const msg = dimMessage(message || messages.getMessage('warnAuth'));
const answer = await ux.prompt(msg);
return Prompts.answeredNo(answer);
}
}
Expand All @@ -24,13 +30,15 @@ export class Prompts {
if (noPrompt || Global.getEnvironmentMode() === Mode.DEMO) {
return true;
} else {
const answer = await ux.prompt(message || messages.getMessage('warnAuth'));
const msg = dimMessage(message || messages.getMessage('warnAuth'));
const answer = await ux.prompt(msg);
return Prompts.answeredYes(answer);
}
}

public static async askForClientSecret(ux: UX, disableMasking: false): Promise<string> {
return ux.prompt(messages.getMessage('clientSecretStdin'), {
const msg = dimMessage(messages.getMessage('clientSecretStdin'));
return ux.prompt(msg, {
type: disableMasking ? 'normal' : 'hide',
});
}
Expand Down

0 comments on commit 3effb85

Please sign in to comment.