This commit is contained in:
parent
4fa5efa5b6
commit
417088c32b
@ -1,3 +1,3 @@
|
|||||||
kind: Fixed
|
kind: Fixed
|
||||||
body: Local command's `dir` config key resolved to full path
|
body: Local command's `dir` full path is now found with home directory
|
||||||
time: 2025-02-20T14:48:43.475300515-06:00
|
time: 2025-02-20T14:48:43.475300515-06:00
|
||||||
|
@ -569,7 +569,7 @@ func processCmds(opts *ConfigOpts) error {
|
|||||||
|
|
||||||
if cmd.Dir != nil {
|
if cmd.Dir != nil {
|
||||||
|
|
||||||
cmdDir, err := resolveDir(*cmd.Dir)
|
cmdDir, err := getFullPathWithHomeDir(*cmd.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -643,7 +643,7 @@ func processCmds(opts *ConfigOpts) error {
|
|||||||
}
|
}
|
||||||
if cmd.OutputFile != "" {
|
if cmd.OutputFile != "" {
|
||||||
var err error
|
var err error
|
||||||
cmd.OutputFile, err = resolveDir(cmd.OutputFile)
|
cmd.OutputFile, err = getFullPathWithHomeDir(cmd.OutputFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func (remoteConfig *Host) ConnectToHost(opts *ConfigOpts) error {
|
|||||||
|
|
||||||
if !remoteConfig.useDefaultConfig {
|
if !remoteConfig.useDefaultConfig {
|
||||||
var err error
|
var err error
|
||||||
remoteConfig.ConfigFilePath, err = resolveDir(remoteConfig.ConfigFilePath)
|
remoteConfig.ConfigFilePath, err = getFullPathWithHomeDir(remoteConfig.ConfigFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ func (remoteConfig *Host) ConnectToHost(opts *ConfigOpts) error {
|
|||||||
return sshConfigFileOpenErr
|
return sshConfigFileOpenErr
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
defaultConfig, _ := resolveDir("~/.ssh/config")
|
defaultConfig, _ := getFullPathWithHomeDir("~/.ssh/config")
|
||||||
configFile, sshConfigFileOpenErr = os.Open(defaultConfig)
|
configFile, sshConfigFileOpenErr = os.Open(defaultConfig)
|
||||||
if sshConfigFileOpenErr != nil {
|
if sshConfigFileOpenErr != nil {
|
||||||
return sshConfigFileOpenErr
|
return sshConfigFileOpenErr
|
||||||
@ -242,7 +242,7 @@ func (remoteHost *Host) GetPrivateKeyFileFromConfig() {
|
|||||||
identityFile = remoteHost.PrivateKeyPath
|
identityFile = remoteHost.PrivateKeyPath
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteHost.PrivateKeyPath, _ = resolveDir(identityFile)
|
remoteHost.PrivateKeyPath, _ = getFullPathWithHomeDir(identityFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPort checks if the port from the config file is 0
|
// GetPort checks if the port from the config file is 0
|
||||||
@ -324,10 +324,10 @@ func (remoteHost *Host) ConnectThroughBastion(log zerolog.Logger) (*ssh.Client,
|
|||||||
func (remotehHost *Host) GetKnownHosts() error {
|
func (remotehHost *Host) GetKnownHosts() error {
|
||||||
var knownHostsFileErr error
|
var knownHostsFileErr error
|
||||||
if TS(remotehHost.KnownHostsFile) != "" {
|
if TS(remotehHost.KnownHostsFile) != "" {
|
||||||
remotehHost.KnownHostsFile, knownHostsFileErr = resolveDir(remotehHost.KnownHostsFile)
|
remotehHost.KnownHostsFile, knownHostsFileErr = getFullPathWithHomeDir(remotehHost.KnownHostsFile)
|
||||||
return knownHostsFileErr
|
return knownHostsFileErr
|
||||||
}
|
}
|
||||||
remotehHost.KnownHostsFile, knownHostsFileErr = resolveDir("~/.ssh/known_hosts")
|
remotehHost.KnownHostsFile, knownHostsFileErr = getFullPathWithHomeDir("~/.ssh/known_hosts")
|
||||||
return knownHostsFileErr
|
return knownHostsFileErr
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ func GetPrivateKeyPassword(key string, opts *ConfigOpts, log zerolog.Logger) (st
|
|||||||
var prKeyPassword string
|
var prKeyPassword string
|
||||||
if strings.HasPrefix(key, "file:") {
|
if strings.HasPrefix(key, "file:") {
|
||||||
privKeyPassFilePath := strings.TrimPrefix(key, "file:")
|
privKeyPassFilePath := strings.TrimPrefix(key, "file:")
|
||||||
privKeyPassFilePath, _ = resolveDir(privKeyPassFilePath)
|
privKeyPassFilePath, _ = getFullPathWithHomeDir(privKeyPassFilePath)
|
||||||
keyFile, keyFileErr := os.Open(privKeyPassFilePath)
|
keyFile, keyFileErr := os.Open(privKeyPassFilePath)
|
||||||
if keyFileErr != nil {
|
if keyFileErr != nil {
|
||||||
return "", errors.Errorf("Private key password file %s failed to open. \n Make sure it is accessible and correct.", privKeyPassFilePath)
|
return "", errors.Errorf("Private key password file %s failed to open. \n Make sure it is accessible and correct.", privKeyPassFilePath)
|
||||||
@ -368,7 +368,7 @@ func GetPassword(pass string, opts *ConfigOpts, log zerolog.Logger) (string, err
|
|||||||
var password string
|
var password string
|
||||||
if strings.HasPrefix(pass, "file:") {
|
if strings.HasPrefix(pass, "file:") {
|
||||||
passFilePath := strings.TrimPrefix(pass, "file:")
|
passFilePath := strings.TrimPrefix(pass, "file:")
|
||||||
passFilePath, _ = resolveDir(passFilePath)
|
passFilePath, _ = getFullPathWithHomeDir(passFilePath)
|
||||||
keyFile, keyFileErr := os.Open(passFilePath)
|
keyFile, keyFileErr := os.Open(passFilePath)
|
||||||
if keyFileErr != nil {
|
if keyFileErr != nil {
|
||||||
return "", errors.New("Password file failed to open")
|
return "", errors.New("Password file failed to open")
|
||||||
@ -440,7 +440,7 @@ func (remoteConfig *Host) GetProxyJumpConfig(hosts map[string]*Host, opts *Confi
|
|||||||
return sshConfigFileOpenErr
|
return sshConfigFileOpenErr
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
defaultConfig, _ := resolveDir("~/.ssh/config")
|
defaultConfig, _ := getFullPathWithHomeDir("~/.ssh/config")
|
||||||
configFile, sshConfigFileOpenErr = os.Open(defaultConfig)
|
configFile, sshConfigFileOpenErr = os.Open(defaultConfig)
|
||||||
if sshConfigFileOpenErr != nil {
|
if sshConfigFileOpenErr != nil {
|
||||||
return sshConfigFileOpenErr
|
return sshConfigFileOpenErr
|
||||||
@ -706,7 +706,7 @@ func (command *Command) runRemoteScript(session *ssh.Session, cmdCtxLogger zerol
|
|||||||
|
|
||||||
// readFileToBuffer reads a file into a buffer.
|
// readFileToBuffer reads a file into a buffer.
|
||||||
func readFileToBuffer(filePath string) (*bytes.Buffer, error) {
|
func readFileToBuffer(filePath string) (*bytes.Buffer, error) {
|
||||||
resolvedPath, err := resolveDir(filePath)
|
resolvedPath, err := getFullPathWithHomeDir(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ func NewOpts(configFilePath string, opts ...BackyOptionFunc) *ConfigOpts {
|
|||||||
|
|
||||||
func injectEnvIntoSSH(envVarsToInject environmentVars, process *ssh.Session, opts *ConfigOpts, log zerolog.Logger) {
|
func injectEnvIntoSSH(envVarsToInject environmentVars, process *ssh.Session, opts *ConfigOpts, log zerolog.Logger) {
|
||||||
if envVarsToInject.file != "" {
|
if envVarsToInject.file != "" {
|
||||||
envPath, envPathErr := resolveDir(envVarsToInject.file)
|
envPath, envPathErr := getFullPathWithHomeDir(envVarsToInject.file)
|
||||||
if envPathErr != nil {
|
if envPathErr != nil {
|
||||||
log.Fatal().Str("envFile", envPath).Err(envPathErr).Send()
|
log.Fatal().Str("envFile", envPath).Err(envPathErr).Send()
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ errEnvFile:
|
|||||||
|
|
||||||
func injectEnvIntoLocalCMD(envVarsToInject environmentVars, process *exec.Cmd, log zerolog.Logger) {
|
func injectEnvIntoLocalCMD(envVarsToInject environmentVars, process *exec.Cmd, log zerolog.Logger) {
|
||||||
if envVarsToInject.file != "" {
|
if envVarsToInject.file != "" {
|
||||||
envPath, _ := resolveDir(envVarsToInject.file)
|
envPath, _ := getFullPathWithHomeDir(envVarsToInject.file)
|
||||||
|
|
||||||
file, fileErr := os.Open(envPath)
|
file, fileErr := os.Open(envPath)
|
||||||
if fileErr != nil {
|
if fileErr != nil {
|
||||||
@ -192,7 +192,7 @@ func IsCmdStdOutEnabled() bool {
|
|||||||
return os.Getenv("BACKY_CMDSTDOUT") == "enabled"
|
return os.Getenv("BACKY_CMDSTDOUT") == "enabled"
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveDir(path string) (string, error) {
|
func getFullPathWithHomeDir(path string) (string, error) {
|
||||||
path = strings.TrimSpace(path)
|
path = strings.TrimSpace(path)
|
||||||
|
|
||||||
if path == "~" {
|
if path == "~" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user