-
Notifications
You must be signed in to change notification settings - Fork 156
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
[ISSUE #674] feat: Add support for env variables in executor config #677
Conversation
Hi @halalala222, thank you very much for your great work! After reviewing the code, I noticed that it's replacing specific environment variables. I apologize for not being clear about this earlier, but we need to expand all environment variables included in the Config. For example, it should work like this: steps:
- name: step1
executor:
type: ssh
config:
user: "${SSH_USER}"
ip: "${SSH_HOST}"
port: "${SSH_PORT}"
key: "${HOME}/.ssh/id_rsa"
command: /usr/sbin/ifconfig I think we can achieve this using the following approach: // expandEnvHook is a mapstructure decode hook that expands environment variables in string fields
func expandEnvHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) {
if f.Kind() != reflect.String || t.Kind() != reflect.String {
return data, nil
}
return os.ExpandEnv(data.(string)), nil
}
func newSSHExec(_ context.Context, step dag.Step) (Executor, error) {
cfg := new(sshExecConfig)
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: cfg,
DecodeHook: expandEnvHook,
})
// ... omitted ...
} Additionally, if possible, it would be great if you could add some tests for this functionality. Thank you very much for your help. It's really appreciated! |
Hi ! @yohamta Thank you ! I know ! I will try to work on it. |
Hi @halalala222, I understand you might be busy right now. Would you mind if I take over the task? If you'd prefer to continue working on it, that's great too. |
Hi @yohamta ,I'm really sorry, but I have some matters to attend to recently and may not be able to cover this task anymore. I apologize for the inconvenience. |
Hi @halalala222, no worries at all! Thank you so much for all the wonderful work you've done on developing Dagu, it was incredibly helpful. I'm closing this for now. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #677 +/- ##
=======================================
Coverage 64.68% 64.68%
=======================================
Files 53 53
Lines 4315 4315
=======================================
Hits 2791 2791
Misses 1269 1269
Partials 255 255 Continue to review full report in Codecov by Sentry.
|
export env
func newSSHExec(_ context.Context, step dag.Step) (Executor, error) {
// expend env
if err = expendExecConfigEnv(step.ExecutorConfig.Config); err != nil {
return nil, err
}
}