-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add -a, --active-only to export secrets #119
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,31 +8,22 @@ import { | |
| stopProgressIndicator, | ||
| updateProgressIndicator, | ||
| } from '../utils/Console'; | ||
| import { esvToEnv } from '../utils/FrConfig'; | ||
|
|
||
| const { getFilePath, saveJsonToFile } = frodo.utils; | ||
| const { readSecrets, exportSecret } = frodo.cloud.secret; | ||
| const { readSecrets, exportSecret, readVersionsOfSecret } = frodo.cloud.secret; | ||
|
|
||
| /** | ||
| * Export all secrets to individual files in fr-config-manager format | ||
| * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true | ||
| * @param {boolean} includeActiveValues include active value of secret (default: false) | ||
| * @param {string} target Host URL of target environment to encrypt secret value for | ||
| * @returns {Promise<boolean>} true if successful, false otherwise | ||
| */ | ||
| type FrConfigSecret = SecretSkeleton & { | ||
| valueBase64: string; | ||
| }; | ||
|
|
||
|
Comment on lines
16
to
19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this type either, so I would just remove it. If you delete all the places we are using it you shouldn't run into any errors |
||
| async function getFrConfigSecrets(): Promise<FrConfigSecret[]> { | ||
| const originalSecrets = await readSecrets(); | ||
| return originalSecrets.map((secret) => ({ | ||
| ...secret, | ||
| valueBase64: `\${${secret._id.toUpperCase().replace(/-/g, '_')}}`, | ||
| })); | ||
| } | ||
|
|
||
| /** | ||
| * Export all secrets to individual files in fr-config-manager format | ||
| * @param {boolean} activeOnly true to export only active secrets, false will export all active or not | ||
| * @returns {Promise<boolean>} true if successful, false otherwise | ||
| */ | ||
| export async function configManagerExportSecrets( | ||
| target?: string | ||
| activeOnly?: boolean | ||
| ): Promise<boolean> { | ||
| let secrets: FrConfigSecret[] = []; | ||
| const spinnerId = createProgressIndicator( | ||
|
|
@@ -41,7 +32,7 @@ export async function configManagerExportSecrets( | |
| `Reading secrets...` | ||
| ); | ||
| try { | ||
| secrets = await getFrConfigSecrets(); | ||
| secrets = (await readSecrets()) as FrConfigSecret[]; | ||
| secrets.sort((a, b) => a._id.localeCompare(b._id)); | ||
| stopProgressIndicator( | ||
| spinnerId, | ||
|
|
@@ -56,18 +47,31 @@ export async function configManagerExportSecrets( | |
| for (const secret of secrets) { | ||
| const exportData: SecretsExportInterface = await exportSecret( | ||
| secret._id, | ||
| false, | ||
| target | ||
| false | ||
| ); | ||
| const [secretKey] = Object.keys(exportData.secret); | ||
| const fullSecret = exportData.secret[secretKey] as FrConfigSecret; | ||
| const cleanSecret = { | ||
| const cleanSecret: Partial<SecretSkeleton> = { | ||
| _id: fullSecret._id, | ||
| description: fullSecret.description, | ||
| encoding: fullSecret.encoding, | ||
| useInPlaceholders: fullSecret.useInPlaceholders, | ||
| valueBase64: `\${${secret._id.toUpperCase().replace(/-/g, '_')}}`, | ||
| }; | ||
| if (activeOnly) { | ||
| cleanSecret.valueBase64 = `\${${esvToEnv(secret._id)}}`; | ||
| } else { | ||
| const versionsResponse = await readVersionsOfSecret(fullSecret._id); | ||
| const versions = versionsResponse.filter( | ||
| (version) => version.status !== 'DESTROYED' | ||
| ); | ||
| const versionInfo = versions.map((version) => ({ | ||
| version: version.version, | ||
| status: version.status, | ||
| valueBase64: `\${${esvToEnv(`${secret._id}_${version.version}`)}}`, | ||
| })); | ||
|
Comment on lines
+67
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After thinking about it, I think you should change the version number to be |
||
| cleanSecret.versions = versionInfo; | ||
| } | ||
|
|
||
| saveJsonToFile( | ||
| cleanSecret, | ||
| getFilePath(`esvs/secrets/${secret._id}.json`, true), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should only have it say
Export only active secret versions.It's implied that if it's not provided all secret versions will be exported.