mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
deadcode: SSH.StartProcess, SSH.createCmd, SSH.quote
This commit is contained in:
@ -3,12 +3,7 @@
|
|||||||
package backend
|
package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/juju/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// sshSession exists so we don't create a hard dependency on crypto/ssh.
|
// sshSession exists so we don't create a hard dependency on crypto/ssh.
|
||||||
@ -25,45 +20,45 @@ type SSH struct {
|
|||||||
Session sshSession
|
Session sshSession
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *SSH) StartProcess(cmd string, args ...string) (Waiter, io.Writer, io.Reader, io.Reader, error) {
|
// func (b *SSH) StartProcess(cmd string, args ...string) (Waiter, io.Writer, io.Reader, io.Reader, error) {
|
||||||
stdin, err := b.Session.StdinPipe()
|
// stdin, err := b.Session.StdinPipe()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the SSH session's stdin stream")
|
// return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the SSH session's stdin stream")
|
||||||
}
|
// }
|
||||||
|
|
||||||
stdout, err := b.Session.StdoutPipe()
|
// stdout, err := b.Session.StdoutPipe()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the SSH session's stdout stream")
|
// return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the SSH session's stdout stream")
|
||||||
}
|
// }
|
||||||
|
|
||||||
stderr, err := b.Session.StderrPipe()
|
// stderr, err := b.Session.StderrPipe()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the SSH session's stderr stream")
|
// return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the SSH session's stderr stream")
|
||||||
}
|
// }
|
||||||
|
|
||||||
err = b.Session.Start(b.createCmd(cmd, args))
|
// err = b.Session.Start(b.createCmd(cmd, args))
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, nil, nil, nil, errors.Annotate(err, "Could not spawn process via SSH")
|
// return nil, nil, nil, nil, errors.Annotate(err, "Could not spawn process via SSH")
|
||||||
}
|
// }
|
||||||
|
|
||||||
return b.Session, stdin, stdout, stderr, nil
|
// return b.Session, stdin, stdout, stderr, nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
func (b *SSH) createCmd(cmd string, args []string) string {
|
// func (b *SSH) createCmd(cmd string, args []string) string {
|
||||||
parts := []string{cmd}
|
// parts := []string{cmd}
|
||||||
simple := regexp.MustCompile(`^[a-z0-9_/.~+-]+$`)
|
// simple := regexp.MustCompile(`^[a-z0-9_/.~+-]+$`)
|
||||||
|
|
||||||
for _, arg := range args {
|
// for _, arg := range args {
|
||||||
if !simple.MatchString(arg) {
|
// if !simple.MatchString(arg) {
|
||||||
arg = b.quote(arg)
|
// arg = b.quote(arg)
|
||||||
}
|
// }
|
||||||
|
|
||||||
parts = append(parts, arg)
|
// parts = append(parts, arg)
|
||||||
}
|
// }
|
||||||
|
|
||||||
return strings.Join(parts, " ")
|
// return strings.Join(parts, " ")
|
||||||
}
|
// }
|
||||||
|
|
||||||
func (b *SSH) quote(s string) string {
|
// func (b *SSH) quote(s string) string {
|
||||||
return fmt.Sprintf(`"%s"`, s)
|
// return fmt.Sprintf(`"%s"`, s)
|
||||||
}
|
// }
|
||||||
|
Reference in New Issue
Block a user