Skip to content

Commit

Permalink
align log level across plugins
Browse files Browse the repository at this point in the history
happy lint

happy lint
  • Loading branch information
tg123 committed Aug 5, 2022
1 parent d3ec47f commit 319824e
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 230 deletions.
3 changes: 1 addition & 2 deletions cmd/sshpiperd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"net"
"os"
"path"
Expand Down Expand Up @@ -39,7 +38,7 @@ func newDaemon(ctx *cli.Context) (*daemon, error) {
log.Infof("found host keys %v", privateKeys)
for _, privateKey := range privateKeys {
log.Infof("loading host key %v", privateKey)
privateBytes, err := ioutil.ReadFile(privateKey)
privateBytes, err := os.ReadFile(privateKey)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/sshpiperd/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"os"

"github.com/tg123/sshpiper/cmd/sshpiperd/internal/plugin"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -65,7 +65,7 @@ func createNetGrpcPlugin(args []string) (grpcPlugin *plugin.GrpcPlugin, err erro

cacert := c.String("cacert")
if cacert != "" {
ca, err := ioutil.ReadFile(cacert)
ca, err := os.ReadFile(cacert)
if err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion cmd/sshpiperd/internal/plugin/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,16 @@ func (g *GrpcPlugin) BannerCallback(conn ssh.ConnMetadata, challengeCtx ssh.Chal
}

func (g *GrpcPlugin) RecvLogs(writer io.Writer) error {
stream, err := g.client.Logs(context.Background(), &libplugin.StartLogRequest{})
uid, err := uuid.NewRandom()
if err != nil {
return err
}

stream, err := g.client.Logs(context.Background(), &libplugin.StartLogRequest{
UniqId: uid.String(),
Level: log.GetLevel().String(),
Tty: checkIfTerminal(log.StandardLogger().Out),
})
if err != nil {
return err
}
Expand Down
25 changes: 25 additions & 0 deletions cmd/sshpiperd/internal/plugin/tty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package plugin

import (
"io"
"os"

"golang.org/x/sys/unix"
)

const ioctlReadTermios = unix.TCGETS

func isTerminal(fd int) bool {
_, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
return err == nil
}

// code from logrus
func checkIfTerminal(w io.Writer) bool {
switch v := w.(type) {
case *os.File:
return isTerminal(int(v.Fd()))
default:
return false
}
}
Binary file removed cmd/sshpiperd/sshpiperd
Binary file not shown.
5 changes: 2 additions & 3 deletions e2e/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package e2e_test

import (
"fmt"
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -69,7 +68,7 @@ func TestDocker(t *testing.T) {

keyfile := path.Join(keyfiledir, "key")

if err := ioutil.WriteFile(keyfile, []byte(`-----BEGIN OPENSSH PRIVATE KEY-----
if err := os.WriteFile(keyfile, []byte(`-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEA2cC73MsqoV11Xy0Elw7wDdU9HnduBEQ2lD4FSpWITZRkzufLjJpr
F//RuCU7HYlR6qBqDR+rpBfHUjNJoGYDDhjLtek8HsJY8DBayvikmGuWXOOlcue2s9GRJ4
Expand Down Expand Up @@ -111,7 +110,7 @@ BdCjPlHSdvg+TNAAAADWJvbGlhbkB1YnVudHUBAgMEBQ==
t.Errorf("failed to write to test key: %v", err)
}

if err := ioutil.WriteFile("/sshconfig_publickey/.ssh/authorized_keys", []byte(`ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDVzohqdRTuT6+SvaccRc9emivp74CyVrO1beiWrGOu0gWy6cocCkodFQXa0qi5vcYO5TX40+PvgwMlNYvQwLbntvnUxHI2H7UymBKQK2jy6Fjt+hBEvFBRbCiL029YRiJE3ffGMY2gs4rkv5lzXqMJmg2HqnwAns5oJWV1TpFV2FBo8NGvAOXcUa3Nuk/nCKtVurnap7GoZD2/CAhJxuxbW+7Y2cGst87EX4Esk8p8QF+Bi5RlD9As2ublc5bIMpXA4rrQKc5gRrDtqHojfWqtdrQqQlg1pBOLHye7lSRcfxhG7qY7xzvYnkWx23KO2tLb5WCupG+V7QRJFosYwutBAqppMpNS60WflE+mymUVf+ptLn3oRDFEalo1kJkymd6uyp+BPZgrGSTt+DzHTIwoJ9RowwBVTU2sKz13WhP+6TKf82IhyjOspeKjbOjLUII/tL4647/7X9VaOvvJ5Qt5sPAdcwk7nSPfkJEr/U9ChnUNKEn6H1eNm26dZpk7hiU=`), 0400); err != nil {
if err := os.WriteFile("/sshconfig_publickey/.ssh/authorized_keys", []byte(`ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDVzohqdRTuT6+SvaccRc9emivp74CyVrO1beiWrGOu0gWy6cocCkodFQXa0qi5vcYO5TX40+PvgwMlNYvQwLbntvnUxHI2H7UymBKQK2jy6Fjt+hBEvFBRbCiL029YRiJE3ffGMY2gs4rkv5lzXqMJmg2HqnwAns5oJWV1TpFV2FBo8NGvAOXcUa3Nuk/nCKtVurnap7GoZD2/CAhJxuxbW+7Y2cGst87EX4Esk8p8QF+Bi5RlD9As2ublc5bIMpXA4rrQKc5gRrDtqHojfWqtdrQqQlg1pBOLHye7lSRcfxhG7qY7xzvYnkWx23KO2tLb5WCupG+V7QRJFosYwutBAqppMpNS60WflE+mymUVf+ptLn3oRDFEalo1kJkymd6uyp+BPZgrGSTt+DzHTIwoJ9RowwBVTU2sKz13WhP+6TKf82IhyjOspeKjbOjLUII/tL4647/7X9VaOvvJ5Qt5sPAdcwk7nSPfkJEr/U9ChnUNKEn6H1eNm26dZpk7hiU=`), 0400); err != nil {
t.Errorf("failed to write to authorized_keys: %v", err)
}

Expand Down
9 changes: 4 additions & 5 deletions e2e/workingdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package e2e_test

import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
Expand Down Expand Up @@ -51,7 +50,7 @@ func TestWorkingDirectory(t *testing.T) {
t.Errorf("failed to create working directory %s: %v", userdir, err)
}

if err := ioutil.WriteFile(path.Join(userdir, "sshpiper_upstream"), []byte("user@host-password:2222"), 0400); err != nil {
if err := os.WriteFile(path.Join(userdir, "sshpiper_upstream"), []byte("user@host-password:2222"), 0400); err != nil {
t.Errorf("failed to write upstream file: %v", err)
}
}
Expand All @@ -68,7 +67,7 @@ func TestWorkingDirectory(t *testing.T) {
t.Errorf("failed to run ssh-keyscan: %v", err)
}

if err := ioutil.WriteFile(path.Join(userdir, "known_hosts"), b, 0400); err != nil {
if err := os.WriteFile(path.Join(userdir, "known_hosts"), b, 0400); err != nil {
t.Errorf("failed to write known_hosts: %v", err)
}
}
Expand Down Expand Up @@ -112,7 +111,7 @@ func TestWorkingDirectory(t *testing.T) {
t.Errorf("failed to create working directory %s: %v", userdir, err)
}

if err := ioutil.WriteFile(path.Join(userdir, "sshpiper_upstream"), []byte("user@host-publickey:2222"), 0400); err != nil {
if err := os.WriteFile(path.Join(userdir, "sshpiper_upstream"), []byte("user@host-publickey:2222"), 0400); err != nil {
t.Errorf("failed to write upstream file: %v", err)
}

Expand All @@ -128,7 +127,7 @@ func TestWorkingDirectory(t *testing.T) {
t.Errorf("failed to run ssh-keyscan: %v", err)
}

if err := ioutil.WriteFile(path.Join(userdir, "known_hosts"), b, 0400); err != nil {
if err := os.WriteFile(path.Join(userdir, "known_hosts"), b, 0400); err != nil {
t.Errorf("failed to write known_hosts: %v", err)
}
}
Expand Down
Loading

0 comments on commit 319824e

Please sign in to comment.