mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-10 09:28:36 +00:00
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import checkOverrides from './checkOverrides';
|
|
|
|
|
|
interface SecretDataProps {
|
|
type: 'personal' | 'shared';
|
|
pos: number;
|
|
key: string;
|
|
value: string;
|
|
id: string;
|
|
comment: string;
|
|
}
|
|
|
|
/**
|
|
* This function downloads the secrets as a .env file
|
|
* @param {object} obj
|
|
* @param {SecretDataProps[]} obj.data - secrets that we want to download
|
|
* @param {string} obj.env - the environment which we're downloading (used for naming the file)
|
|
*/
|
|
const downloadDotEnv = async ({ data, env }: { data: SecretDataProps[]; env: string; }) => {
|
|
if (!data) return;
|
|
const secrets = await checkOverrides({ data });
|
|
|
|
const file = secrets!
|
|
.map(
|
|
(item: SecretDataProps) =>
|
|
`${
|
|
item.comment
|
|
? item.comment
|
|
.split('\n')
|
|
.map((comment) => '# '.concat(comment))
|
|
.join('\n') + '\n'
|
|
: ''
|
|
}` + [item.key, item.value].join('=')
|
|
)
|
|
.join('\n');
|
|
|
|
const blob = new Blob([file]);
|
|
const fileDownloadUrl = URL.createObjectURL(blob);
|
|
const alink = document.createElement('a');
|
|
alink.href = fileDownloadUrl;
|
|
alink.download = env + '.env';
|
|
alink.click();
|
|
}
|
|
|
|
export default downloadDotEnv;
|