-
Notifications
You must be signed in to change notification settings - Fork 4
Allow exporting all environment variables by default for secrets env
#312
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
Conversation
cafaf3e
to
4a04a9c
Compare
We have run into a roadblock with the implementation of command = [
'secrets',
'env',
'-np',
dataDir,
'--env-format',
'unix',
'--',
`${vaultName}:dir1=SECRET_NEW`,
'node',
'-e',
'console.log(JSON.stringify(process.env))',
]; The parser for this command first tries to parse each argument as a secret path. The previous implementation would disallow This doesn't allow for the additional commands to be accumulated, as we can no longer differentiate between the command and the vault paths. Until a solution for handling this is discussed, this PR is essentially blocked. (Brian's commentary on this)
We might be able to add a separate option which might take variadic parameters for entering the command, or maybe takes a string as the command. This needs some discussion and inputs before we can move ahead with this PR. |
We can use an option with variadic arguments as such: class CommandEnv extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('env');
this.argument(
'<args...>',
'arguments formatted as [envPaths...]',
binParsers.parseEnvArgs,
);
this.option(
'--command <args...>
'command formatted as [cmd][cmdArgs...]',
);
this.action(async (args: Array<string>, options) => {
console.log(options.command); // Example: ['node', '-e', 'console.log(JSON.stringify(process.env))']
... So, the new command invocation can look like this: [aryanj@matrix-34xx:~]$ polykey secrets env vault --command node -e console.log("hello world") Should this be implemented in this PR, or is there another approach to this? |
I want it to work like env in the default case so |
The |
const { Command } = require('commander');
const program = new Command();
program
.command('secrets env [vaults...]')
.description('Set environment with vaults and execute a command')
.allowUnknownOption(true) // Allows capturing anything after `--` as unknown options
.action((vaults, options) => {
// Find the `--` separator in the arguments to capture everything after it.
const indexOfDoubleDash = process.argv.indexOf('--');
let command = [];
// If `--` is found, get all arguments after it.
if (indexOfDoubleDash !== -1) {
command = process.argv.slice(indexOfDoubleDash + 1);
}
console.log('vaults:', vaults);
console.log('command:', command);
});
program.parse(process.argv); This is what ChatGPT gave me as a possible implementation. I will use this for reference when implementing this. It also gave me this regex to match vault names: ^[\p{Print}&&[^/\p{Cc}]]+$ This will match all printable UTF-8 characters (from the As we are not currently dealing with local file systems, this can be kept simple while retaining possibility of updates. |
I have realised that commander doesn't provide the location of And if we are already requiring the users to put the command after The |
Nevermind, I got it working. Commander by default parses options positionlessly. Meaning, For example, Some more testing on this is needed, but from what I can tell, it seems to work pretty well. |
I have noticed that for all the tests, we are checking for the exact expected error code (like 64 for usage). For my secrets commands, I have just been testing if the exit code is not zero. Does this need to change? If so, I can track this change in some issue somewhere. |
feat: fixed secrets env to allow vault names without secret path fix: actually allow vault to export all secrets by default fix: build chore: changed vaultName:. to vaultName in tests
5f0265c
to
1ec36ab
Compare
The required change for allowing dots in vault names and defaulting the path to vault root has been implemented. This change isn't meant to be a complete and bulletproof change, but meant to be enough to allow env migration work to be done. This PR can now be merged. The other features are being tracked in #305 |
Description
This is a child PR of #305 which only implements the required changes to allow the
secrets env
to use the vault name only without needing to specify the secrets.Currently, we do this:
polykey secrets env vault:.
to export all secrets from a vault.After this, we can do
polykey secrets env vault
to automatically export all the secrets in the vault.This PR will also allow using dots in vault names. More robust checks will be implemented as a part of the parent PR.
Issues Fixed
.
character when creating them, but they aren't valid paths for secrets commands #251Tasks
secrets env
to export all secrets if no secret path is specifiedFinal checklist