Compare commits
2 Commits
a0bf51636c
...
417088c32b
Author | SHA1 | Date | |
---|---|---|---|
417088c32b | |||
4fa5efa5b6 |
@ -1,3 +1,3 @@
|
||||
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
|
||||
|
@ -54,7 +54,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
||||
ArgsStr += fmt.Sprintf(" %s", v)
|
||||
}
|
||||
|
||||
if command.Type == User {
|
||||
if command.Type == UserCT {
|
||||
if command.UserOperation == "password" {
|
||||
cmdCtxLogger.Info().Str("password", command.UserPassword).Msg("user password to be updated")
|
||||
}
|
||||
@ -68,7 +68,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
||||
} else {
|
||||
|
||||
// Handle package operations
|
||||
if command.Type == Package && command.PackageOperation == "checkVersion" {
|
||||
if command.Type == PackageCT && command.PackageOperation == "checkVersion" {
|
||||
cmdCtxLogger.Info().Str("package", command.PackageName).Msg("Checking package versions")
|
||||
|
||||
// Execute the package version command
|
||||
@ -85,7 +85,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
||||
}
|
||||
|
||||
var localCMD *exec.Cmd
|
||||
if command.Type == RemoteScript {
|
||||
if command.Type == RemoteScriptCT {
|
||||
script, err := command.Fetcher.Fetch(command.Cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -156,7 +156,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
||||
cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running command %s on local machine", command.Name)).Send()
|
||||
|
||||
// execute package commands in a shell
|
||||
if command.Type == Package {
|
||||
if command.Type == PackageCT {
|
||||
cmdCtxLogger.Info().Str("package", command.PackageName).Msg("Executing package command")
|
||||
ArgsStr = fmt.Sprintf("%s %s", command.Cmd, ArgsStr)
|
||||
localCMD = exec.Command("/bin/sh", "-c", ArgsStr)
|
||||
|
@ -25,29 +25,29 @@ func (i CommandType) String() string {
|
||||
// Re-run the stringer command to generate them again.
|
||||
func _CommandTypeNoOp() {
|
||||
var x [1]struct{}
|
||||
_ = x[Default-(0)]
|
||||
_ = x[Script-(1)]
|
||||
_ = x[ScriptFile-(2)]
|
||||
_ = x[RemoteScript-(3)]
|
||||
_ = x[Package-(4)]
|
||||
_ = x[User-(5)]
|
||||
_ = x[DefaultCT-(0)]
|
||||
_ = x[ScriptCT-(1)]
|
||||
_ = x[ScriptFileCT-(2)]
|
||||
_ = x[RemoteScriptCT-(3)]
|
||||
_ = x[PackageCT-(4)]
|
||||
_ = x[UserCT-(5)]
|
||||
}
|
||||
|
||||
var _CommandTypeValues = []CommandType{Default, Script, ScriptFile, RemoteScript, Package, User}
|
||||
var _CommandTypeValues = []CommandType{DefaultCT, ScriptCT, ScriptFileCT, RemoteScriptCT, PackageCT, UserCT}
|
||||
|
||||
var _CommandTypeNameToValueMap = map[string]CommandType{
|
||||
_CommandTypeName[0:0]: Default,
|
||||
_CommandTypeLowerName[0:0]: Default,
|
||||
_CommandTypeName[0:6]: Script,
|
||||
_CommandTypeLowerName[0:6]: Script,
|
||||
_CommandTypeName[6:16]: ScriptFile,
|
||||
_CommandTypeLowerName[6:16]: ScriptFile,
|
||||
_CommandTypeName[16:28]: RemoteScript,
|
||||
_CommandTypeLowerName[16:28]: RemoteScript,
|
||||
_CommandTypeName[28:35]: Package,
|
||||
_CommandTypeLowerName[28:35]: Package,
|
||||
_CommandTypeName[35:39]: User,
|
||||
_CommandTypeLowerName[35:39]: User,
|
||||
_CommandTypeName[0:0]: DefaultCT,
|
||||
_CommandTypeLowerName[0:0]: DefaultCT,
|
||||
_CommandTypeName[0:6]: ScriptCT,
|
||||
_CommandTypeLowerName[0:6]: ScriptCT,
|
||||
_CommandTypeName[6:16]: ScriptFileCT,
|
||||
_CommandTypeLowerName[6:16]: ScriptFileCT,
|
||||
_CommandTypeName[16:28]: RemoteScriptCT,
|
||||
_CommandTypeLowerName[16:28]: RemoteScriptCT,
|
||||
_CommandTypeName[28:35]: PackageCT,
|
||||
_CommandTypeLowerName[28:35]: PackageCT,
|
||||
_CommandTypeName[35:39]: UserCT,
|
||||
_CommandTypeLowerName[35:39]: UserCT,
|
||||
}
|
||||
|
||||
var _CommandTypeNames = []string{
|
||||
|
@ -569,7 +569,7 @@ func processCmds(opts *ConfigOpts) error {
|
||||
|
||||
if cmd.Dir != nil {
|
||||
|
||||
cmdDir, err := resolveDir(*cmd.Dir)
|
||||
cmdDir, err := getFullPathWithHomeDir(*cmd.Dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -578,7 +578,7 @@ func processCmds(opts *ConfigOpts) error {
|
||||
}
|
||||
|
||||
// Parse package commands
|
||||
if cmd.Type == Package {
|
||||
if cmd.Type == PackageCT {
|
||||
if cmd.PackageManager == "" {
|
||||
return fmt.Errorf("package manager is required for package command %s", cmd.PackageName)
|
||||
}
|
||||
@ -603,7 +603,7 @@ func processCmds(opts *ConfigOpts) error {
|
||||
}
|
||||
|
||||
// Parse user commands
|
||||
if cmd.Type == User {
|
||||
if cmd.Type == UserCT {
|
||||
if cmd.Username == "" {
|
||||
return fmt.Errorf("username is required for user command %s", cmd.Name)
|
||||
}
|
||||
@ -630,7 +630,7 @@ func processCmds(opts *ConfigOpts) error {
|
||||
|
||||
}
|
||||
|
||||
if cmd.Type == RemoteScript {
|
||||
if cmd.Type == RemoteScriptCT {
|
||||
var fetchErr error
|
||||
if !isRemoteURL(cmd.Cmd) {
|
||||
return fmt.Errorf("remoteScript command %s must be a remote resource", cmdName)
|
||||
@ -643,7 +643,7 @@ func processCmds(opts *ConfigOpts) error {
|
||||
}
|
||||
if cmd.OutputFile != "" {
|
||||
var err error
|
||||
cmd.OutputFile, err = resolveDir(cmd.OutputFile)
|
||||
cmd.OutputFile, err = getFullPathWithHomeDir(cmd.OutputFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func (remoteConfig *Host) ConnectToHost(opts *ConfigOpts) error {
|
||||
|
||||
if !remoteConfig.useDefaultConfig {
|
||||
var err error
|
||||
remoteConfig.ConfigFilePath, err = resolveDir(remoteConfig.ConfigFilePath)
|
||||
remoteConfig.ConfigFilePath, err = getFullPathWithHomeDir(remoteConfig.ConfigFilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -63,7 +63,7 @@ func (remoteConfig *Host) ConnectToHost(opts *ConfigOpts) error {
|
||||
return sshConfigFileOpenErr
|
||||
}
|
||||
} else {
|
||||
defaultConfig, _ := resolveDir("~/.ssh/config")
|
||||
defaultConfig, _ := getFullPathWithHomeDir("~/.ssh/config")
|
||||
configFile, sshConfigFileOpenErr = os.Open(defaultConfig)
|
||||
if sshConfigFileOpenErr != nil {
|
||||
return sshConfigFileOpenErr
|
||||
@ -242,7 +242,7 @@ func (remoteHost *Host) GetPrivateKeyFileFromConfig() {
|
||||
identityFile = remoteHost.PrivateKeyPath
|
||||
}
|
||||
|
||||
remoteHost.PrivateKeyPath, _ = resolveDir(identityFile)
|
||||
remoteHost.PrivateKeyPath, _ = getFullPathWithHomeDir(identityFile)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
var knownHostsFileErr error
|
||||
if TS(remotehHost.KnownHostsFile) != "" {
|
||||
remotehHost.KnownHostsFile, knownHostsFileErr = resolveDir(remotehHost.KnownHostsFile)
|
||||
remotehHost.KnownHostsFile, knownHostsFileErr = getFullPathWithHomeDir(remotehHost.KnownHostsFile)
|
||||
return knownHostsFileErr
|
||||
}
|
||||
remotehHost.KnownHostsFile, knownHostsFileErr = resolveDir("~/.ssh/known_hosts")
|
||||
remotehHost.KnownHostsFile, knownHostsFileErr = getFullPathWithHomeDir("~/.ssh/known_hosts")
|
||||
return knownHostsFileErr
|
||||
}
|
||||
|
||||
@ -336,7 +336,7 @@ func GetPrivateKeyPassword(key string, opts *ConfigOpts, log zerolog.Logger) (st
|
||||
var prKeyPassword string
|
||||
if strings.HasPrefix(key, "file:") {
|
||||
privKeyPassFilePath := strings.TrimPrefix(key, "file:")
|
||||
privKeyPassFilePath, _ = resolveDir(privKeyPassFilePath)
|
||||
privKeyPassFilePath, _ = getFullPathWithHomeDir(privKeyPassFilePath)
|
||||
keyFile, keyFileErr := os.Open(privKeyPassFilePath)
|
||||
if keyFileErr != nil {
|
||||
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
|
||||
if strings.HasPrefix(pass, "file:") {
|
||||
passFilePath := strings.TrimPrefix(pass, "file:")
|
||||
passFilePath, _ = resolveDir(passFilePath)
|
||||
passFilePath, _ = getFullPathWithHomeDir(passFilePath)
|
||||
keyFile, keyFileErr := os.Open(passFilePath)
|
||||
if keyFileErr != nil {
|
||||
return "", errors.New("Password file failed to open")
|
||||
@ -440,7 +440,7 @@ func (remoteConfig *Host) GetProxyJumpConfig(hosts map[string]*Host, opts *Confi
|
||||
return sshConfigFileOpenErr
|
||||
}
|
||||
} else {
|
||||
defaultConfig, _ := resolveDir("~/.ssh/config")
|
||||
defaultConfig, _ := getFullPathWithHomeDir("~/.ssh/config")
|
||||
configFile, sshConfigFileOpenErr = os.Open(defaultConfig)
|
||||
if sshConfigFileOpenErr != nil {
|
||||
return sshConfigFileOpenErr
|
||||
@ -531,13 +531,13 @@ func (command *Command) RunCmdSSH(cmdCtxLogger zerolog.Logger, opts *ConfigOpts)
|
||||
|
||||
// Handle command execution based on type
|
||||
switch command.Type {
|
||||
case Script:
|
||||
case ScriptCT:
|
||||
return command.runScript(commandSession, cmdCtxLogger, &cmdOutBuf)
|
||||
case RemoteScript:
|
||||
case RemoteScriptCT:
|
||||
return command.runRemoteScript(commandSession, cmdCtxLogger, &cmdOutBuf)
|
||||
case ScriptFile:
|
||||
case ScriptFileCT:
|
||||
return command.runScriptFile(commandSession, cmdCtxLogger, &cmdOutBuf)
|
||||
case Package:
|
||||
case PackageCT:
|
||||
if command.PackageOperation == "checkVersion" {
|
||||
commandSession.Stderr = nil
|
||||
// Execute the package version command remotely
|
||||
@ -706,7 +706,7 @@ func (command *Command) runRemoteScript(session *ssh.Session, cmdCtxLogger zerol
|
||||
|
||||
// readFileToBuffer reads a file into a buffer.
|
||||
func readFileToBuffer(filePath string) (*bytes.Buffer, error) {
|
||||
resolvedPath, err := resolveDir(filePath)
|
||||
resolvedPath, err := getFullPathWithHomeDir(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -299,10 +299,10 @@ type (
|
||||
|
||||
//go:generate go run github.com/dmarkham/enumer -linecomment -yaml -text -json -type=CommandType
|
||||
const (
|
||||
Default CommandType = iota //
|
||||
Script // script
|
||||
ScriptFile // scriptFile
|
||||
RemoteScript // remoteScript
|
||||
Package // package
|
||||
User // user
|
||||
DefaultCT CommandType = iota //
|
||||
ScriptCT // script
|
||||
ScriptFileCT // scriptFile
|
||||
RemoteScriptCT // remoteScript
|
||||
PackageCT // package
|
||||
UserCT // user
|
||||
)
|
||||
|
@ -91,7 +91,7 @@ func NewOpts(configFilePath string, opts ...BackyOptionFunc) *ConfigOpts {
|
||||
|
||||
func injectEnvIntoSSH(envVarsToInject environmentVars, process *ssh.Session, opts *ConfigOpts, log zerolog.Logger) {
|
||||
if envVarsToInject.file != "" {
|
||||
envPath, envPathErr := resolveDir(envVarsToInject.file)
|
||||
envPath, envPathErr := getFullPathWithHomeDir(envVarsToInject.file)
|
||||
if envPathErr != nil {
|
||||
log.Fatal().Str("envFile", envPath).Err(envPathErr).Send()
|
||||
}
|
||||
@ -125,7 +125,7 @@ errEnvFile:
|
||||
|
||||
func injectEnvIntoLocalCMD(envVarsToInject environmentVars, process *exec.Cmd, log zerolog.Logger) {
|
||||
if envVarsToInject.file != "" {
|
||||
envPath, _ := resolveDir(envVarsToInject.file)
|
||||
envPath, _ := getFullPathWithHomeDir(envVarsToInject.file)
|
||||
|
||||
file, fileErr := os.Open(envPath)
|
||||
if fileErr != nil {
|
||||
@ -192,7 +192,7 @@ func IsCmdStdOutEnabled() bool {
|
||||
return os.Getenv("BACKY_CMDSTDOUT") == "enabled"
|
||||
}
|
||||
|
||||
func resolveDir(path string) (string, error) {
|
||||
func getFullPathWithHomeDir(path string) (string, error) {
|
||||
path = strings.TrimSpace(path)
|
||||
|
||||
if path == "~" {
|
||||
@ -256,7 +256,7 @@ func expandEnvVars(backyEnv map[string]string, envVars []string) {
|
||||
// Returns the modified Command with the package- or userManager command as Cmd and the package- or userOperation as args, plus any additional Args
|
||||
func getCommandTypeAndSetCommandInfo(command *Command) *Command {
|
||||
|
||||
if command.Type == Package && !command.packageCmdSet {
|
||||
if command.Type == PackageCT && !command.packageCmdSet {
|
||||
command.packageCmdSet = true
|
||||
switch command.PackageOperation {
|
||||
case "install":
|
||||
@ -270,7 +270,7 @@ func getCommandTypeAndSetCommandInfo(command *Command) *Command {
|
||||
}
|
||||
}
|
||||
|
||||
if command.Type == User && !command.userCmdSet {
|
||||
if command.Type == UserCT && !command.userCmdSet {
|
||||
command.userCmdSet = true
|
||||
switch command.UserOperation {
|
||||
case "add":
|
||||
|
Loading…
x
Reference in New Issue
Block a user