Skip to content

Commit

Permalink
Merge pull request #289 from mloskot/ml/swdt-cli-fix-fragile-ssh-run-…
Browse files Browse the repository at this point in the history
…on-windows

fix(cli): session.Run is sensitive to quoting on Windows host
  • Loading branch information
k8s-ci-robot authored Jan 19, 2024
2 parents 43a30a9 + 2d48619 commit 990b7ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion experiments/swdt/pkg/connections/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ func (c *SSHConnection) Run(args string) (string, error) {

// Multiline PowerShell commands over SSH trip over newlines - only first one is executed
args = regexp.MustCompile(`\r?\n`).ReplaceAllLiteralString(args, ";")
if err := session.Run("powershell -nologo -noprofile -c " + args); err != nil {
cmd := fmt.Sprintf("powershell -nologo -noprofile -c { %s }", args)
// TODO(mloskot): Log executed commands in --verbose mode
if err := session.Run(cmd); err != nil {
return "", err
}

Expand Down
5 changes: 3 additions & 2 deletions experiments/swdt/pkg/pwsh/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ func (r *SetupRunner) EnableRDP(enable bool) error {
return nil
}

output, err := r.run(`Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0;
klog.Info(resc.Sprintf("Enabling RDP."))
output, err := r.run(`Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -name "fDenyTSConnections" -value 0;
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"`)
if err != nil {
return err
}
klog.Info(resc.Sprintf("Enabling RDP. %s", output))
klog.Info(resc.Sprintf(output))
return nil
}

0 comments on commit 990b7ba

Please sign in to comment.