added new features
- expanding `environment` vars in cmd section - support for connecting to one proxy/bastion host - better notification text layout - better error message on private key failing to open
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"mvdan.cc/sh/v3/shell"
|
||||
)
|
||||
|
||||
func injectEnvIntoSSH(envVarsToInject environmentVars, process *ssh.Session, log *zerolog.Logger) {
|
||||
@@ -207,3 +209,33 @@ func resolveDir(path string) (string, error) {
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
||||
func (opts *BackyConfigOpts) loadEnv() {
|
||||
envFileInConfigDir := fmt.Sprintf("%s/.env", path.Dir(opts.viper.ConfigFileUsed()))
|
||||
var backyEnv map[string]string
|
||||
backyEnv, envFileErr := godotenv.Read(envFileInConfigDir)
|
||||
if envFileErr != nil {
|
||||
return
|
||||
}
|
||||
|
||||
opts.backyEnv = backyEnv
|
||||
}
|
||||
|
||||
func expandEnvVars(backyEnv map[string]string, envVars []string) {
|
||||
|
||||
env := func(name string) string {
|
||||
name = strings.ToUpper(name)
|
||||
envVar, found := backyEnv[name]
|
||||
if found {
|
||||
return envVar
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
for indx, v := range envVars {
|
||||
if strings.Contains(v, "$") || (strings.Contains(v, "${") && strings.Contains(v, "}")) {
|
||||
out, _ := shell.Expand(v, env)
|
||||
envVars[indx] = out
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user