You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The pk secrets env command should operate similar to the unix env command
We can use pk secrets env to do double duty: inject environment variables into a new subcommand, or allow sourcing of environment variables into an existing subshell
Now when we want to start development on the project, we have 2 options:
Open up a shell with Polykey sourcing the environment variables
Use Polykey to inject environment variables into a sub-shell
Either result is the same, because you'll be running a shell with environment variables set so that your test runs of your software can inherit this environment configuration. Let's demonstrate both.
In the first case, we will reuse the source command and ask pk to constuct the equivalent of the .env file but entirely in-memory and only for this specific usage. We must also use process substitution <(...) so that the pk command output can be redirected into a temporary file descriptor that is read by the source command.
# one secretsource<(pk secrets env my-software-project:AWS_ACCESS_KEY_ID)# multiple secretssource<(pk secrets env my-software-project:AWS_ACCESS_KEY_ID my-software-project:GOOGLE_MAPS_API_KEY)# globbing style (you can use globstar as well, this will only export immediate files)source<(pk secrets env my-software-project:*)# use the -e flag to export all variablessource<(pk secrets env -e my-software-project:*)# use the -- to separate so you can export just one out of manysource<(pk secrets env -- my-software-project:AWS_ACCESS_KEY_ID -e my-software-project:GOOGLE_MAPS_API_KEY)source<(pk secrets env -e -- my-software-project:AWS_ACCESS_KEY_ID my-software-project:GOOGLE_MAPS_API_KEY)
Now your shell has the relevant environment variables set by Polykey, and they will exist for as long as this current shell is alive.
In the second case, we ill use pk secrets env command to run a subshell, it can run any subprogram, but in the context of a development environment, you usually want a shell.
# one secret
pk secrets env my-software-project:AWS_ACCESS_KEY_ID bash
# multiple secrets
pk secrets env my-software-project:AWS_ACCESS_KEY_ID my-software-project:GOOGLE_MAPS_API_KEY bash
# globbing style
pk secrets env my-software-project:* bash
# the -e flag has no effect when using it this way# this is because the subprogram determines whether to export variable or not# it usually exports the variable
pk secrets env -e my-software-project:* bash
Now you have a subshell that has the environment variables configured, it will also automatically export it to child programs. When you have finished your development, you can just exit the shell, and the environment variables are gone!
Tasks
Ensure that pk secrets env can be used to inject environment variables and run a subprocess
Ensure that pk secrets env can be used to source environment variables and output something that can be used as a file to be sourced by a shell
Specification
pk secrets envcommand should operate similar to the unixenvcommandpk secrets envto do double duty: inject environment variables into a new subcommand, or allow sourcing of environment variables into an existing subshellpk secrets env someprogram arg1 arg2should do a proper process replacement when possibleAdditional context
Copied excerpt:
Tasks
pk secrets envcan be used to inject environment variables and run a subprocesspk secrets envcan be used to source environment variables and output something that can be used as a file to be sourced by a shell