Closed halalala222 closed 1 month ago
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.
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 64.68%. Comparing base (
3c4f636
) to head (b20c3ab
). Report is 1 commits behind head on main.
export env
func newSSHExec(_ context.Context, step dag.Step) (Executor, error) { // expend env if err = expendExecConfigEnv(step.ExecutorConfig.Config); err != nil { return nil, err }
}