-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split config and ability to change api key
- Loading branch information
1 parent
b68d511
commit e01403d
Showing
4 changed files
with
69 additions
and
16 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const types = require('ethernaut-common/src/validation/types') | ||
const output = require('ethernaut-common/src/ui/output') | ||
const storage = require('ethernaut-common/src/io/storage') | ||
const { setEnvVar } = require('ethernaut-common/src/io/env') | ||
|
||
require('../scopes/ai') | ||
.task('key', 'Sets the openai api key') | ||
.addParam('apiKey', 'The openai api key to use', undefined, types.string) | ||
.setAction(async ({ apiKey }, hre) => { | ||
try { | ||
const config = storage.readConfig() | ||
|
||
let summary = [] | ||
|
||
if (apiKey) { | ||
const currentKey = process.env.OPENAI_API_KEY | ||
setEnvVar('OPENAI_API_KEY', apiKey) | ||
summary.push(`- API Key set to ${apiKey} (was ${currentKey})`) | ||
} | ||
|
||
storage.saveConfig(config) | ||
|
||
if (summary.length === 0) { | ||
summary.push('No changes') | ||
} | ||
|
||
return output.resultBox(summary.join('\n')) | ||
} catch (err) { | ||
return output.errorBox(err) | ||
} | ||
}) |
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
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