Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow stdin for sfdx-url #886

Merged
8 changes: 6 additions & 2 deletions messages/sfdxurl.store.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# summary

Authorize an org using a Salesforce DX authorization URL stored in a file.
Authorize an org using a Salesforce DX authorization URL stored in a file or through stdin.
k-capehart marked this conversation as resolved.
Show resolved Hide resolved

# description

Expand All @@ -20,7 +20,7 @@ You can also create a JSON file that has a top-level property named sfdxAuthUrl

# flags.sfdx-url-file.summary

Path to a file that contains the Salesforce DX authorization URL.
Path to a file that contains the Salesforce DX authorization URL. Use the '-' character to pipe through stdin.
k-capehart marked this conversation as resolved.
Show resolved Hide resolved

# examples

Expand All @@ -31,3 +31,7 @@ Path to a file that contains the Salesforce DX authorization URL.
- Similar to previous example, but set the org as your default and give it an alias MyDefaultOrg:

<%= config.bin %> <%= command.id %> --sfdx-url-file files/authFile.json --set-default --alias MyDefaultOrg

- Pipe the SFDX authorization url from stdin by providing the '-' value.
k-capehart marked this conversation as resolved.
Show resolved Hide resolved

$ echo $url | <%= config.bin %> <%= command.id %> --sfdx-url-file -
k-capehart marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 12 additions & 4 deletions src/commands/org/login/sfdx-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class LoginSfdxUrl extends AuthBaseCommand<AuthFields> {
required: true,
deprecateAliases: true,
aliases: ['sfdxurlfile'],
allowStdin: true,
}),
'set-default-dev-hub': Flags.boolean({
char: 'd',
Expand Down Expand Up @@ -71,11 +72,18 @@ export default class LoginSfdxUrl extends AuthBaseCommand<AuthFields> {
const { flags } = await this.parse(LoginSfdxUrl);
if (await this.shouldExitCommand(flags['no-prompt'])) return {};

const authFile = flags['sfdx-url-file'];
const authFile: string = flags['sfdx-url-file'];
let sfdxAuthUrl: string;

const sfdxAuthUrl = authFile.endsWith('.json')
? await getUrlFromJson(authFile)
: await fs.readFile(authFile, 'utf8');
const match = authFile.match(
/^force:\/\/([a-zA-Z0-9._-]+={0,2}):([a-zA-Z0-9._-]*={0,2}):([a-zA-Z0-9._-]+={0,2})@([a-zA-Z0-9._-]+)/
);

if (match) {
sfdxAuthUrl = authFile;
} else {
sfdxAuthUrl = authFile.endsWith('.json') ? await getUrlFromJson(authFile) : await fs.readFile(authFile, 'utf8');
}

if (!sfdxAuthUrl) {
throw new Error(
Expand Down