Skip to content

Commit

Permalink
refactor: sfError, filterSecrets
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed May 14, 2024
1 parent 6aba25d commit f404ea2
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions src/org/authInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { matchesAccessToken, trimTo15 } from '../util/sfdc';
import { StateAggregator } from '../stateAggregator/stateAggregator';
import { Messages } from '../messages';
import { getLoginAudienceCombos, SfdcUrl } from '../util/sfdcUrl';
import { filterSecrets } from '../logger/filters';
import { Connection, SFDX_HTTP_HEADERS } from './connection';
import { OrgConfigProperties } from './orgConfigProperties';
import { Org, SandboxFields } from './org';
Expand Down Expand Up @@ -1106,22 +1107,13 @@ export class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
this.logger.info(`Exchanging auth code for access token using loginUrl: ${options.loginUrl}`);
authFields = await oauth2.requestToken(ensure(options.authCode));
} catch (err) {
let error: SfError;
let errorMsg: string;
if (err instanceof Error) {
errorMsg = `${err.name}::${err.message}`;
error = SfError.create({
message: errorMsg,
name: 'AuthCodeExchangeError',
cause: err,
});
} else {
error = SfError.wrap(err);
errorMsg = error.message;
}
error.message = messages.getMessage('authCodeExchangeError', [errorMsg]);
error.setData(getRedactedErrData(options));
throw error;
const msg = err instanceof Error ? `${err.name}::${err.message}` : typeof err === 'string' ? err : 'UNKNOWN';
throw SfError.create({
message: messages.getMessage('authCodeExchangeError', [msg]),
name: 'AuthCodeExchangeError',
...(err instanceof Error ? { cause: err } : {}),
data: filterSecrets(options) as JwtOAuth2Config,
});
}

const { orgId } = parseIdUrl(authFields.id);
Expand Down Expand Up @@ -1257,21 +1249,6 @@ export class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
}
}

const getRedactedErrData = (options: JwtOAuth2Config): AnyJson => {
const keysToRedact = ['privateKey', 'privateKeyFile', 'authCode', 'refreshToken', 'username', 'clientSecret'];
const oauth2OptionsKeys = Object.getOwnPropertyNames(options);
return oauth2OptionsKeys.map((k) => {
if (keysToRedact.includes(k)) {
// @ts-expect-error no index signature with a parameter of type 'string' was found on type JwtOAuth2Config
return options[k] ? `${k}:'<REDACTED>'` : `${k}:'<unset>'`;
} else if (k === 'clientId') {
return options[k] === 'PlatformCLI' ? `${k}:${options[k]}` : `${k}:'<REDACTED>'`;
}
// @ts-expect-error no index signature with a parameter of type 'string' was found on type JwtOAuth2Config
return `${k}:${options[k]}`;
});
};

export namespace AuthInfo {
/**
* Constructor options for AuthInfo.
Expand Down

1 comment on commit f404ea2

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: f404ea2 Previous: b2272d6 Ratio
Child logger creation 470736 ops/sec (±1.14%) 480137 ops/sec (±1.16%) 1.02
Logging a string on root logger 778750 ops/sec (±9.51%) 813568 ops/sec (±9.19%) 1.04
Logging an object on root logger 575629 ops/sec (±7.26%) 632667 ops/sec (±7.66%) 1.10
Logging an object with a message on root logger 10508 ops/sec (±200.86%) 6946 ops/sec (±210.39%) 0.66
Logging an object with a redacted prop on root logger 419402 ops/sec (±10.35%) 475913 ops/sec (±9.66%) 1.13
Logging a nested 3-level object on root logger 363645 ops/sec (±6.46%) 384482 ops/sec (±8.02%) 1.06

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.