-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
13 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import * as os from 'os'; | ||
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; | ||
import { AuthFields, AuthInfo, fs, Messages } from '@salesforce/core'; | ||
import { AnyJson } from '@salesforce/ts-types'; | ||
import { Prompts } from '../../../prompts'; | ||
import { Common } from '../../../common'; | ||
|
||
|
@@ -18,6 +19,10 @@ const commonMessages = Messages.loadMessages('@salesforce/plugin-auth', 'message | |
const AUTH_URL_FORMAT1 = 'force://<refreshToken>@<instanceUrl>'; | ||
const AUTH_URL_FORMAT2 = 'force://<clientId>:<clientSecret>:<refreshToken>@<instanceUrl>'; | ||
|
||
type AuthJson = AnyJson & { | ||
result?: AnyJson & { sfdxAuthUrl: string }; | ||
sfdxAuthUrl: string; | ||
}; | ||
export default class Store extends SfdxCommand { | ||
public static readonly description = messages.getMessage('description', [AUTH_URL_FORMAT1, AUTH_URL_FORMAT2]); | ||
public static readonly examples = messages.getMessage('examples').split(os.EOL); | ||
|
@@ -71,13 +76,7 @@ export default class Store extends SfdxCommand { | |
} | ||
|
||
private async getUrlFromJson(authFile: string): Promise<string> { | ||
const authFileJson = (await fs.readJson(authFile)) as Record<string, string>; | ||
|
||
if (authFileJson.result) { | ||
// Do a bunch of casting to get TSC to recognize the `sfdxAuthUrl` property as a string | ||
return ((authFileJson as unknown) as Record<string, Record<string, string>>).result.sfdxAuthUrl; | ||
} | ||
|
||
return authFileJson.sfdxAuthUrl; | ||
const authFileJson = (await fs.readJson(authFile)) as AuthJson; | ||
return authFileJson.result?.sfdxAuthUrl || authFileJson.sfdxAuthUrl; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
RodEsp
Author
Contributor
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,9 +61,9 @@ describe('auth:sfdxurl:store', async () => { | |
test | ||
.do(async () => { | ||
await prepareStubs({ fileDoesNotExist: true }); | ||
$$.SANDBOX.stub(fs, 'readFile').callsFake( | ||
async () => '{"sfdxAuthUrl": "force://PlatformCLI::[email protected]"}' | ||
); | ||
$$.SANDBOX.stub(fs, 'readJson').callsFake(async () => ({ | ||
sfdxAuthUrl: 'force://PlatformCLI::[email protected]', | ||
})); | ||
}) | ||
.stdout() | ||
.command(['auth:sfdxurl:store', '-f', 'path/to/key.json', '--json']) | ||
|
@@ -77,9 +77,9 @@ describe('auth:sfdxurl:store', async () => { | |
test | ||
.do(async () => { | ||
await prepareStubs({ fileDoesNotExist: true }); | ||
$$.SANDBOX.stub(fs, 'readFile').callsFake( | ||
async () => '{"result": {"sfdxAuthUrl": "force://PlatformCLI::[email protected]"}}' | ||
); | ||
$$.SANDBOX.stub(fs, 'readJson').callsFake(async () => ({ | ||
result: { sfdxAuthUrl: 'force://PlatformCLI::[email protected]' }, | ||
})); | ||
}) | ||
.stdout() | ||
.command(['auth:sfdxurl:store', '-f', 'path/to/key.json', '--json']) | ||
|
There is a chance that both might be undefined. Will that condition be handled elsewhere?