Skip to content

Commit db18d71

Browse files
crisbetojosephperrott
authored andcommitted
fix(ng-dev): avoid exposing the API key in help text (#2869)
The API key from the environment was set as the default in `yargs` which means that it was being logged when the user doesn't type out the command properly. PR Close #2869
1 parent 2f7d6fb commit db18d71

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

ng-dev/ai/fix.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ function builder(argv: Argv): Argv<Options> {
7979

8080
/** Yargs command handler for the command. */
8181
async function handler(options: Arguments<Options>) {
82+
const apiKey = options.apiKey || DEFAULT_API_KEY;
83+
8284
assert(
83-
options.apiKey,
85+
apiKey,
8486
[
8587
'No API key configured. A Gemini API key must be set as the `GEMINI_API_KEY` environment ' +
8688
'variable, or passed in using the `--api-key` flag.',
@@ -89,7 +91,7 @@ async function handler(options: Arguments<Options>) {
8991
);
9092

9193
const fixedContents = await fixFilesWithAI(
92-
options.apiKey,
94+
apiKey,
9395
options.files,
9496
options.error,
9597
options.model,

ng-dev/ai/migrate.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,16 @@ function builder(argv: Argv): Argv<Options> {
7272
.option('apiKey', {
7373
type: 'string',
7474
alias: 'a',
75-
default: DEFAULT_API_KEY,
7675
description: 'API key used when making calls to the Gemini API',
7776
});
7877
}
7978

8079
/** Yargs command handler for the command. */
8180
async function handler(options: Arguments<Options>) {
81+
const apiKey = options.apiKey || DEFAULT_API_KEY;
82+
8283
assert(
83-
options.apiKey,
84+
apiKey,
8485
[
8586
'No API key configured. A Gemini API key must be set as the `GEMINI_API_KEY` environment ' +
8687
'variable, or passed in using the `--api-key` flag.',
@@ -98,7 +99,7 @@ async function handler(options: Arguments<Options>) {
9899
process.exit(1);
99100
}
100101

101-
const ai = new GoogleGenAI({apiKey: options.apiKey});
102+
const ai = new GoogleGenAI({apiKey});
102103
const progressBar = new SingleBar({}, Presets.shades_grey);
103104
const failures: {name: string; error: string}[] = [];
104105
const running = new Set<Promise<void>>();

0 commit comments

Comments
 (0)