6 Commits

Author SHA1 Message Date
6e7d912fa2 v0.7.0 bump version
Some checks failed
ci/woodpecker/push/go-lint Pipeline failed
ci/woodpecker/tag/publish-docs Pipeline is pending
ci/woodpecker/tag/gitea Pipeline failed
ci/woodpecker/push/publish-docs Pipeline failed
2025-02-11 21:19:57 -06:00
b90d1958b2 [WIP] v0.7.0 fix comments
Some checks failed
ci/woodpecker/push/go-lint Pipeline failed
2025-02-11 12:19:09 -06:00
c187fbb735 [WIP] v0.7.0 almost ready to release
Some checks failed
ci/woodpecker/push/go-lint Pipeline failed
2025-02-10 17:00:02 -06:00
c3de4386ab [WIP] v0.7.0 almost ready to release
Some checks failed
ci/woodpecker/push/go-lint Pipeline failed
2025-02-10 16:55:54 -06:00
e20141043c Merge branch 'remoteResources' into develop
Some checks failed
ci/woodpecker/push/go-lint Pipeline failed
2025-02-08 16:14:37 -06:00
5d3c265ce9 add comments
Some checks failed
ci/woodpecker/push/go-lint Pipeline failed
2025-01-23 16:47:43 -06:00
5 changed files with 32 additions and 11 deletions

View File

@ -0,0 +1,3 @@
kind: Changed
body: Hosts passed to `exec host` now checked against default SSH config files
time: 2025-02-10T16:55:32.936776556-06:00

View File

@ -15,14 +15,16 @@ var (
} }
) )
// Holds command list to run // Holds list of hosts to run commands on
var hostsList []string var hostsList []string
// Holds command list to run
var cmdList []string var cmdList []string
func init() { func init() {
hostExecCommand.Flags().StringArrayVarP(&hostsList, "hosts", "m", nil, "Accepts space-separated names of hosts.") hostExecCommand.Flags().StringArrayVarP(&hostsList, "hosts", "m", nil, "Accepts space-separated names of hosts. Specify multiple times for multiple hosts.")
hostExecCommand.Flags().StringArrayVarP(&cmdList, "command", "c", nil, "Accepts space-separated names of commands.") hostExecCommand.Flags().StringArrayVarP(&cmdList, "command", "c", nil, "Accepts space-separated names of commands. Specify multiple times for multiple commands.")
parseS3Config() parseS3Config()
} }
@ -42,13 +44,18 @@ func Host(cmd *cobra.Command, args []string) {
if hostsList == nil { if hostsList == nil {
logging.ExitWithMSG("error: hosts must be specified", 1, &backyConfOpts.Logger) logging.ExitWithMSG("error: hosts must be specified", 1, &backyConfOpts.Logger)
} }
// host is only checked when we read the SSH File
// so a check may not be needed here
// but we can check if the host is in the config file
for _, h := range hostsList { for _, h := range hostsList {
// check if h exists in the config file
_, hostFound := backyConfOpts.Hosts[h] _, hostFound := backyConfOpts.Hosts[h]
if !hostFound { if !hostFound {
logging.ExitWithMSG("host "+h+" not found", 1, &backyConfOpts.Logger) // check if h exists in the SSH config file
hostFoundInConfig, s := backy.CheckIfHostHasHostName(h)
if !hostFoundInConfig {
logging.ExitWithMSG("host "+h+" not found", 1, &backyConfOpts.Logger)
}
// create host with hostname and host
backyConfOpts.Hosts[h] = &backy.Host{Host: h, HostName: s}
} }
} }
if cmdList == nil { if cmdList == nil {

View File

@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
const versionStr = "0.6.1" const versionStr = "0.7.0"
var ( var (
versionCmd = &cobra.Command{ versionCmd = &cobra.Command{

View File

@ -34,15 +34,17 @@ var Sprintf = fmt.Sprintf
func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([]string, error) { func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([]string, error) {
var ( var (
outputArr []string ArgsStr string // concatenating the arguments
ArgsStr string
cmdOutBuf bytes.Buffer cmdOutBuf bytes.Buffer
cmdOutWriters io.Writer cmdOutWriters io.Writer
errSSH error
envVars = environmentVars{ envVars = environmentVars{
file: command.Env, file: command.Env,
env: command.Environment, env: command.Environment,
} }
outputArr []string // holds the output strings returned by processes
) )
// Get the command type // Get the command type
@ -53,13 +55,13 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
ArgsStr += fmt.Sprintf(" %s", v) ArgsStr += fmt.Sprintf(" %s", v)
} }
// print the user's password if it is updated
if command.Type == "user" { if command.Type == "user" {
if command.UserOperation == "password" { if command.UserOperation == "password" {
cmdCtxLogger.Info().Str("password", command.UserPassword).Msg("user password to be updated") cmdCtxLogger.Info().Str("password", command.UserPassword).Msg("user password to be updated")
} }
} }
var errSSH error
// is host defined // is host defined
if command.Host != nil { if command.Host != nil {
outputArr, errSSH = command.RunCmdSSH(cmdCtxLogger, opts) outputArr, errSSH = command.RunCmdSSH(cmdCtxLogger, opts)

View File

@ -757,3 +757,12 @@ func (h *Host) DetectOS(opts *ConfigOpts) (string, error) {
osName := string(output) osName := string(output)
return osName, nil return osName, nil
} }
func CheckIfHostHasHostName(host string) (bool, string) {
HostName, err := ssh_config.DefaultUserSettings.GetStrict(host, "HostName")
if err != nil {
return false, ""
}
println(HostName)
return HostName != "", HostName
}