Infisical / infisical

♾ Infisical is the open-source secret management platform: Sync secrets across your team/infrastructure, prevent secret leaks, and manage internal PKI
https://infisical.com
Other
13k stars 677 forks source link

Feature Request - allow alias to be run using infisical run #457

Open fmancardi opened 1 year ago

fmancardi commented 1 year ago

Feature description

I would like to be able to using: infisical run to run an alias

infisical run -- rcxx-preprod blind

rccno-prepod is the following alias:

alias rcxx-preprod='./runners/runit.chrome.cxx-preprod.sh'

When running rcnno-preprod, it will be expanded to: testcafe 'chrome --start-fullscreen' --cfg=cxx-preprod.json ./test/blind-man-navigation.js

Why would it be useful?

To have shortcut to long commands

Right now what you get is this error:

Injecting 2 Infisical secrets into your application process Hmm, we ran into an error: exec: "rcxx-preprod": executable file not found in %PATH%Unable to execute your single command

Environment

gitbash on windows 11

maidul98 commented 1 year ago

Great idea!

quinton11 commented 1 year ago

Hey @maidul98, I looked into this. A quick fix would be to check if the command exists in %PATH% (alias check), get the 'SHELL' environment variable and run the command as a sub command. ( In https://github.com/Infisical/infisical/blob/a3093de55b28b3e5a0bd56b794a59b7f2794c342/cli/packages/cmd/run.go#L188)

Eg: '[SHELL] -c [aliasCmd]' for git bash: '[/path/to/bash] -c [aliasCmd]'

However aliases aren't passed to sub processes. As a work around, in substitute for aliases, you could create a function in your .bashrc / bash_profile.sh which returns the cmd you're aliasing and export it.

See https://askubuntu.com/a/98791

parthvnp commented 1 year ago

Is help still needed on this issue? I would love to work on it!

maidul98 commented 1 year ago

@quinton11 that makes sense and to source the file you can also just point to a script file. This way we can do something like this which already works out of the box

infisical run --command="source ./myfunctions.sh && ll"

where myfunctions.sh is

#!/bin/sh

ll() {
  ls -l "$@"
}

I think adding this to the documentation should help others become aware of this. What do you think @parthvnp @quinton11

quinton11 commented 1 year ago

Yep, sounds great... would you handle updating the documentation? I can pick it up if not. Or perhaps @parthvnp ?

parthvnp commented 1 year ago

I can handle the updating documentation !

maidul98 commented 1 year ago

Cool, we use https://mintlify.com/ so feed free to cd into the docs folder and start up mintlify with mintlify dev command after you install it

parthvnp commented 1 year ago

@maidul98 Added PR 564 to showcase this feature in documentation.