Skip to content

Commit

Permalink
feat: add support for shell format of secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Jan 16, 2023
1 parent 7013d5a commit c69cc4d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const configureAndListen = async (
});

fastify.post<{
Querystring: { format: string };
Body: { token: string };
}>(
'/exchange',
Expand Down Expand Up @@ -113,6 +114,20 @@ export const configureAndListen = async (
)}`,
);

if (req.query.format === 'shell') {
for (const secretKey of Object.keys(secretsToSend)) {
if (!/^[A-Za-z][A-Za-z0-9]+$/i.test(secretKey)) {
req.log.error(
`Shell format was requested but the "${secretKey}" key is not compatible with shell variable naming`,
);
return reply.status(422).send('');
}
}
return Object.keys(secretsToSend)
.map((secretKey) => `export ${secretKey}=${JSON.stringify(secretsToSend[secretKey])}`)
.join('\n');
}

return secretsToSend;
},
);
Expand Down

0 comments on commit c69cc4d

Please sign in to comment.