Skip to content

Commit

Permalink
feat: add support for powershell format
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Jan 23, 2023
1 parent 4571883 commit 1da1471
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const configureAndListen = async (
)}`,
);

if (req.query.format === 'shell') {
if (req.query.format === 'shell' || req.query.format === 'powershell') {
for (const secretKey of Object.keys(secretsToSend)) {
if (!/^[A-Za-z][A-Za-z0-9_]+$/i.test(secretKey)) {
req.log.error(
Expand All @@ -119,9 +119,16 @@ export const configureAndListen = async (
return reply.status(422).send('');
}
}
return Object.keys(secretsToSend)
.map((secretKey) => `export ${secretKey}=${JSON.stringify(secretsToSend[secretKey])}\n`)
.join('');
if (req.query.format === 'shell') {
return Object.keys(secretsToSend)
.map((secretKey) => `export ${secretKey}=${JSON.stringify(secretsToSend[secretKey])}\n`)
.join('');
}
if (req.query.format === 'powershell') {
return Object.keys(secretsToSend)
.map((secretKey) => `$env:${secretKey} = ${JSON.stringify(secretsToSend[secretKey])}\n`)
.join('');
}
}

return secretsToSend;
Expand Down

0 comments on commit 1da1471

Please sign in to comment.