happy lint
This commit is contained in:
parent
93da136a94
commit
bc9875c4b5
7 changed files with 39 additions and 27 deletions
|
|
@ -90,6 +90,8 @@ func createNetGrpcPlugin(args []string) (grpcPlugin *plugin.GrpcPlugin, err erro
|
|||
return err
|
||||
}
|
||||
|
||||
grpcPlugin.Name = fmt.Sprintf("grpc://%s", c.String("endpoint"))
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
"net"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
|
@ -17,9 +16,11 @@ import (
|
|||
"github.com/tg123/sshpiper/libplugin/ioconn"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
type GrpcPlugin struct {
|
||||
Name string
|
||||
OnNextPlugin func(conn ssh.ChallengeContext, upstream *libplugin.UpstreamNextPluginAuth) error
|
||||
|
||||
grpcconn *grpc.ClientConn
|
||||
|
|
@ -249,7 +250,7 @@ func (g *GrpcPlugin) UpstreamAuthFailureCallbackRemote(conn ssh.ConnMetadata, me
|
|||
}
|
||||
}
|
||||
|
||||
g.client.UpstreamAuthFailureNotice(context.Background(), &libplugin.UpstreamAuthFailureNoticeRequest{
|
||||
_, _ = g.client.UpstreamAuthFailureNotice(context.Background(), &libplugin.UpstreamAuthFailureNoticeRequest{
|
||||
Meta: toMeta(challengeCtx, conn),
|
||||
Method: method,
|
||||
Error: err.Error(),
|
||||
|
|
@ -396,8 +397,9 @@ func (g *GrpcPlugin) KeyboardInteractiveCallback(conn ssh.ConnMetadata, client s
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer stream.CloseSend()
|
||||
defer func() {
|
||||
_ = stream.CloseSend()
|
||||
}()
|
||||
|
||||
for {
|
||||
msg, err := stream.Recv()
|
||||
|
|
@ -497,7 +499,9 @@ func DialCmd(cmd *exec.Cmd) (*CmdPlugin, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
go io.Copy(log.StandardLogger().Out, stderr)
|
||||
go func() {
|
||||
_, _ = io.Copy(log.StandardLogger().Out, stderr)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
err := cmd.Wait()
|
||||
|
|
@ -506,7 +510,7 @@ func DialCmd(cmd *exec.Cmd) (*CmdPlugin, error) {
|
|||
}
|
||||
}()
|
||||
|
||||
conn, err := grpc.Dial("", grpc.WithInsecure(), grpc.WithDialer(func(_ string, _ time.Duration) (net.Conn, error) {
|
||||
conn, err := grpc.Dial("", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(func(_ context.Context, _ string) (net.Conn, error) {
|
||||
return cmdconn, nil
|
||||
}))
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ func createPlugin(args []string) (*plugin.GrpcPlugin, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
p.Name = exe
|
||||
|
||||
return &p.GrpcPlugin, nil
|
||||
}
|
||||
}
|
||||
|
|
@ -157,7 +159,11 @@ func main() {
|
|||
return err
|
||||
}
|
||||
|
||||
go p.RecvLogs(log.StandardLogger().Out)
|
||||
go func() {
|
||||
if err := p.RecvLogs(log.StandardLogger().Out); err != nil {
|
||||
log.Errorf("plugin %v recv logs error: %v", p.Name, err)
|
||||
}
|
||||
}()
|
||||
plugins = append(plugins, p)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,11 +49,17 @@ func runCmd(cmd string, args ...string) (*exec.Cmd, io.Writer, io.Reader, error)
|
|||
|
||||
var buf bytes.Buffer
|
||||
r := io.TeeReader(f, &buf)
|
||||
go io.Copy(os.Stdout, r)
|
||||
go func() {
|
||||
_, _ = io.Copy(os.Stdout, r)
|
||||
}()
|
||||
|
||||
log.Printf("starting %v", c.Args)
|
||||
|
||||
go c.Wait()
|
||||
go func() {
|
||||
if err := c.Wait(); err != nil {
|
||||
log.Printf("wait %v returns %v", c.Args, err)
|
||||
}
|
||||
}()
|
||||
|
||||
return c, f, &buf, nil
|
||||
}
|
||||
|
|
@ -65,7 +71,7 @@ func enterPassword(stdin io.Writer, stdout io.Reader, password string) {
|
|||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if strings.Contains(line, "'s password") {
|
||||
stdin.Write([]byte(fmt.Sprintf("%v\n", password)))
|
||||
_, _ = stdin.Write([]byte(fmt.Sprintf("%v\n", password)))
|
||||
log.Printf("got password prompt, sending password")
|
||||
return
|
||||
}
|
||||
|
|
@ -96,7 +102,7 @@ func checkSharedFileContent(t *testing.T, targetfie string, expected string) {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
runCmd("ssh", "-V")
|
||||
_, _, _, _ = runCmd("ssh", "-V")
|
||||
|
||||
for _, ep := range []string{
|
||||
"host-password:2222",
|
||||
|
|
@ -132,7 +138,14 @@ func TestFixed(t *testing.T) {
|
|||
t.Errorf("failed to ssh to piper-fixed, %v", err)
|
||||
}
|
||||
|
||||
defer c.Process.Kill()
|
||||
defer func() {
|
||||
if c.Process != nil {
|
||||
if err = c.Process.Kill(); err != nil {
|
||||
log.Printf("failed to kill ssh process, %v", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
enterPassword(stdin, stdout, "pass")
|
||||
|
||||
time.Sleep(time.Second) // wait for file flush
|
||||
|
|
|
|||
|
|
@ -2,25 +2,12 @@ package libplugin
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func WriterToFile(writer io.Writer) (*os.File, error) {
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go io.Copy(writer, r)
|
||||
|
||||
return w, nil
|
||||
}
|
||||
|
||||
func AuthMethodTypeToName(a AuthMethod) string {
|
||||
switch a {
|
||||
case AuthMethod_NONE:
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ func main() {
|
|||
CreateConfig: func(_ *cli.Context) (*libplugin.SshPiperPluginConfig, error) {
|
||||
return &libplugin.SshPiperPluginConfig{
|
||||
KeyboardInteractiveCallback: func(conn libplugin.ConnMetadata, client libplugin.KeyboardInteractiveChallenge) (*libplugin.Upstream, error) {
|
||||
client("", "lets do math", "", false)
|
||||
_, _ = client("", "lets do math", "", false)
|
||||
|
||||
for {
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ func main() {
|
|||
|
||||
var upstream *libplugin.Upstream
|
||||
|
||||
filepath.Walk(userdir, func(path string, info os.FileInfo, err error) error {
|
||||
_ = filepath.Walk(userdir, func(path string, info os.FileInfo, err error) error {
|
||||
|
||||
log.Infof("search public key in path: %v", path)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue