happy lint
This commit is contained in:
parent
6781e23c3b
commit
ef3e77ac84
19 changed files with 76 additions and 56 deletions
6
.github/workflows/go.yml
vendored
6
.github/workflows/go.yml
vendored
|
|
@ -28,6 +28,12 @@ jobs:
|
|||
set -e
|
||||
go version
|
||||
|
||||
- name: fmt
|
||||
run: |
|
||||
if [ "$(gofmt -s -l libpiper sshpiperd | wc -l)" -gt 0 ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,11 @@ func (l *filePtyLogger) loggingTty(conn ssh.ConnMetadata, msg []byte) ([]byte, e
|
|||
}
|
||||
|
||||
func (l *filePtyLogger) Close() (err error) {
|
||||
_, err = l.typescript.Write([]byte(fmt.Sprintf("Script done on %v\n", time.Now().Format(time.ANSIC))))
|
||||
// if _, err = ; err != nil {
|
||||
// return err
|
||||
// }
|
||||
_, _ = l.typescript.Write([]byte(fmt.Sprintf("Script done on %v\n", time.Now().Format(time.ANSIC))))
|
||||
|
||||
l.typescript.Close()
|
||||
l.timing.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,13 @@ func Test_findAuthyId(t *testing.T) {
|
|||
defer os.Remove(tmpfile.Name())
|
||||
a.Config.File = tmpfile.Name()
|
||||
|
||||
ioutil.WriteFile(tmpfile.Name(), []byte(`
|
||||
if err := ioutil.WriteFile(tmpfile.Name(), []byte(`
|
||||
piper 123
|
||||
hook 456
|
||||
hook 789
|
||||
`), os.ModePerm)
|
||||
`), os.ModePerm); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
{
|
||||
id, err := a.findAuthyID("piper")
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ import (
|
|||
type authyClient struct {
|
||||
Config struct {
|
||||
APIKey string `long:"challenger-authy-apikey" description:"Authy API Key" env:"SSHPIPERD_CHALLENGER_AUTHY_APIKEY" ini-name:"challenger-authy-apikey"`
|
||||
Method string `long:"challenger-authy-method" default:"token" description:"Authy authentication method" env:"SSHPIPERD_CHALLENGER_AUTHY_METHOD" ini-name:"challenger-authy-method" choice:"token" choice:"onetouch"`
|
||||
// Method string `long:"challenger-authy-method" default:"token" description:"Authy authentication method" env:"SSHPIPERD_CHALLENGER_AUTHY_METHOD" ini-name:"challenger-authy-method" choice:"token" choice:"onetouch"`
|
||||
Method string `long:"challenger-authy-method" default:"token" description:"Authy authentication method" env:"SSHPIPERD_CHALLENGER_AUTHY_METHOD" ini-name:"challenger-authy-method" choice:"token"`
|
||||
File string `long:"challenger-authy-idfile" description:"Path to a file with ssh_name [space] authy_id per line (first line win if duplicate)" env:"SSHPIPERD_CHALLENGER_AUTHY_IDFILE" ini-name:"challenger-authy-idfile"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,10 @@ import (
|
|||
|
||||
type authClient struct {
|
||||
Config struct {
|
||||
TenantID string `long:"challenger-azdevicecode-tenantid" description:"Azure AD tenant id" env:"SSHPIPERD_CHALLENGER_AZDEVICECODE_TENANTID" ini-name:"challenger-azdevicecode-tenantid"`
|
||||
ClientID string `long:"challenger-azdevicecode-clientid" description:"Azure AD client id" env:"SSHPIPERD_CHALLENGER_AZDEVICECODE_CLIENTID" ini-name:"challenger-azdevicecode-clientid"`
|
||||
Env string `long:"challenger-azdevicecode-env" default:"AzurePublicCloud" description:"Azure AD Cloud to request" env:"SSHPIPERD_CHALLENGER_AZDEVICECODE_ENV" ini-name:"challenger-azdevicecode-env" choice:"AzureChinaCloud" choice:"AzureGermanCloud" choice:"AzurePublicCloud" choice:"AzureUSGovernmentCloud"`
|
||||
TenantID string `long:"challenger-azdevicecode-tenantid" description:"Azure AD tenant id" env:"SSHPIPERD_CHALLENGER_AZDEVICECODE_TENANTID" ini-name:"challenger-azdevicecode-tenantid"`
|
||||
ClientID string `long:"challenger-azdevicecode-clientid" description:"Azure AD client id" env:"SSHPIPERD_CHALLENGER_AZDEVICECODE_CLIENTID" ini-name:"challenger-azdevicecode-clientid"`
|
||||
// Env string `long:"challenger-azdevicecode-env" default:"AzurePublicCloud" description:"Azure AD Cloud to request" env:"SSHPIPERD_CHALLENGER_AZDEVICECODE_ENV" ini-name:"challenger-azdevicecode-env" choice:"AzureChinaCloud" choice:"AzureGermanCloud" choice:"AzurePublicCloud" choice:"AzureUSGovernmentCloud"`
|
||||
Env string `long:"challenger-azdevicecode-env" default:"AzurePublicCloud" description:"Azure AD Cloud to request" env:"SSHPIPERD_CHALLENGER_AZDEVICECODE_ENV" ini-name:"challenger-azdevicecode-env"`
|
||||
Resource string `long:"challenger-azdevicecode-resource" default:"https://graph.windows.net/" description:"Resource URI to access, default is Graph API" env:"SSHPIPERD_CHALLENGER_AZDEVICECODE_RESOURCE" ini-name:"challenger-azdevicecode-resource"`
|
||||
NoReadGraph bool `long:"challenger-azdevicecode-noreadgraph" description:"Disable query user info from user graph" env:"SSHPIPERD_CHALLENGER_AZDEVICECODE_NOREADGRAPH" ini-name:"challenger-azdevicecode-noreadgraph"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,9 +84,7 @@ func (p *pome) challenge(conn ssh.ConnMetadata, client ssh.KeyboardInteractiveCh
|
|||
return err
|
||||
}
|
||||
|
||||
err = say(fmt.Sprintf("Open %v in browser to login (timeout %v senconds)", url, p.Config.Timeout))
|
||||
|
||||
if err != nil {
|
||||
if err := say(fmt.Sprintf("Open %v in browser to login (timeout %v senconds)", url, p.Config.Timeout)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -98,11 +96,11 @@ func (p *pome) challenge(conn ssh.ConnMetadata, client ssh.KeyboardInteractiveCh
|
|||
pipe := <-c
|
||||
|
||||
if pipe == nil {
|
||||
say(fmt.Sprintf("Login timeout"))
|
||||
_ = say("Login timeout")
|
||||
return nil, fmt.Errorf("timeout")
|
||||
}
|
||||
|
||||
say(fmt.Sprintf("Connecting to %v@%v", pipe.Username, pipe.Address))
|
||||
_ = say(fmt.Sprintf("Connecting to %v@%v", pipe.Username, pipe.Address))
|
||||
|
||||
pipe.say = say
|
||||
return pipe, nil
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ func (plugin) GetOpts() interface{} {
|
|||
}
|
||||
|
||||
func (p *plugin) Init(logger *log.Logger) error {
|
||||
p.logger = logger
|
||||
p.pome.logger = logger
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,15 +19,13 @@ func (p *pome) authWithPipe(conn ssh.ConnMetadata, challengeContext ssh.Addition
|
|||
|
||||
host, port, err := upstream.SplitHostPortForSSH(pipe.Address)
|
||||
if err != nil {
|
||||
pipe.say("Not add Please check your configure")
|
||||
return nil, nil, err
|
||||
return nil, nil, pipe.say("Not add Please check your configure")
|
||||
}
|
||||
|
||||
addr := fmt.Sprintf("%v:%v", host, port)
|
||||
c, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
pipe.say(fmt.Sprintf("Cannot connect to %v, reason: %v", addr, err))
|
||||
return nil, nil, err
|
||||
return nil, nil, pipe.say(fmt.Sprintf("Cannot connect to %v, reason: %v", addr, err))
|
||||
}
|
||||
|
||||
callback := func() (ssh.AuthPipeType, ssh.AuthMethod, error) {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ func addPlugins(group *flags.Group, name string, pluginNames []string, getter fu
|
|||
func populateFromConfig(ini *flags.IniParser, data interface{}, longopt string) error {
|
||||
|
||||
parser := flags.NewParser(data, flags.IgnoreUnknown)
|
||||
parser.Parse()
|
||||
_, _ = parser.Parse()
|
||||
|
||||
o := parser.FindOptionByLongName(longopt)
|
||||
file := o.Value().(flags.Filename)
|
||||
|
|
@ -95,7 +95,7 @@ func main() {
|
|||
ini.ParseAsDefaults = true
|
||||
err := populateFromConfig(ini, configFile, "config")
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprintf("load config file failed %v", err))
|
||||
fmt.Printf("load config file failed %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ func main() {
|
|||
return nil, fmt.Errorf("must provider upstream driver")
|
||||
}
|
||||
|
||||
provider := upstream.Get(config.UpstreamDriver).(upstream.Provider)
|
||||
provider := upstream.Get(config.UpstreamDriver)
|
||||
err := provider.Init(log.New(ioutil.Discard, "", 0))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package main
|
|||
|
||||
import (
|
||||
_ "github.com/tg123/sshpiper/sshpiperd/upstream/database"
|
||||
_ "github.com/tg123/sshpiper/sshpiperd/upstream/grpcupstream"
|
||||
_ "github.com/tg123/sshpiper/sshpiperd/upstream/kubernetes"
|
||||
_ "github.com/tg123/sshpiper/sshpiperd/upstream/workingdir"
|
||||
_ "github.com/tg123/sshpiper/sshpiperd/upstream/yaml"
|
||||
_ "github.com/tg123/sshpiper/sshpiperd/upstream/grpcupstream"
|
||||
|
||||
_ "github.com/tg123/sshpiper/sshpiperd/challenger/authy"
|
||||
_ "github.com/tg123/sshpiper/sshpiperd/challenger/azdevicecode"
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ func createPipeMgr(load func() (upstream.Provider, error)) interface{} {
|
|||
t := template.Must(template.New("").Parse(`{{.Username}} -> {{.UpstreamUsername}}@{{.Host}}:{{.Port}}`))
|
||||
|
||||
for _, pipe := range pipes {
|
||||
t.Execute(os.Stdout, pipe)
|
||||
_ = t.Execute(os.Stdout, pipe)
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -196,8 +196,8 @@ func startPiper(config *piperdConfig, logger *log.Logger) error {
|
|||
go func(c net.Conn) {
|
||||
defer c.Close()
|
||||
|
||||
pipec := make(chan *ssh.PiperConn, 0)
|
||||
errorc := make(chan error, 0)
|
||||
pipec := make(chan *ssh.PiperConn)
|
||||
errorc := make(chan error)
|
||||
|
||||
go func() {
|
||||
p, err := ssh.NewSSHPiperConn(c, piper)
|
||||
|
|
|
|||
|
|
@ -35,9 +35,10 @@ func (p *testplugin) Init(logger *log.Logger) error {
|
|||
}
|
||||
|
||||
func Test_getAndInstall(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// ignore empty
|
||||
getAndInstall("", "", func(n string) registry.Plugin {
|
||||
_ = getAndInstall("", "", func(n string) registry.Plugin {
|
||||
t.Errorf("should not call get")
|
||||
return nil
|
||||
}, func(plugin registry.Plugin) error {
|
||||
|
|
@ -46,7 +47,7 @@ func Test_getAndInstall(t *testing.T) {
|
|||
}, nil)
|
||||
|
||||
// fail when not found
|
||||
err := getAndInstall("", "test", func(n string) registry.Plugin {
|
||||
err = getAndInstall("", "test", func(n string) registry.Plugin {
|
||||
if n != "test" {
|
||||
t.Errorf("plugin name changed")
|
||||
}
|
||||
|
|
@ -338,12 +339,17 @@ func Test_installDriver(t *testing.T) {
|
|||
|
||||
m := []byte{0}
|
||||
|
||||
a.GetUpstreamHook()(nil, m)
|
||||
if _, err := a.GetUpstreamHook()(nil, m); err != nil {
|
||||
t.Errorf("run upstream hook %v", err)
|
||||
}
|
||||
|
||||
if m[0] != 42 {
|
||||
t.Errorf("upstream not handled")
|
||||
}
|
||||
|
||||
a.GetDownstreamHook()(nil, m)
|
||||
if _, err := a.GetDownstreamHook()(nil, m); err != nil {
|
||||
t.Errorf("run downstream hook %v", err)
|
||||
}
|
||||
if m[0] != 100 {
|
||||
t.Errorf("downstream not handled")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,6 +197,6 @@ func createListener(t *testing.T) (net.Listener, error) {
|
|||
if err != nil {
|
||||
t.Fatalf("cant create fake server: %v", err)
|
||||
}
|
||||
go listener.Accept()
|
||||
// go listener.Accept()
|
||||
return listener, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,5 +68,5 @@ func main() {
|
|||
}
|
||||
|
||||
log.Printf("serving on %v", addr)
|
||||
s.Serve(l)
|
||||
panic(s.Serve(l))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ type pipeConfig struct {
|
|||
UpstreamHost string `kubernetes:"upstream_host"`
|
||||
}
|
||||
|
||||
type createPipeCtx struct {
|
||||
pipe pipeConfig
|
||||
conn ssh.ConnMetadata
|
||||
challengeContext ssh.AdditionalChallengeContext
|
||||
}
|
||||
// type createPipeCtx struct {
|
||||
// pipe pipeConfig
|
||||
// conn ssh.ConnMetadata
|
||||
// challengeContext ssh.AdditionalChallengeContext
|
||||
// }
|
||||
|
||||
func (p *plugin) getClientSet() (*sshpipeclientset.Clientset, error) {
|
||||
/*
|
||||
|
|
@ -67,8 +67,7 @@ func (p *plugin) getConfig(clientset *sshpipeclientset.Clientset) ([]pipeConfig,
|
|||
|
||||
var config []pipeConfig
|
||||
for _, pipe := range pipes.Items {
|
||||
var targetHost string
|
||||
targetHost = fmt.Sprintf("%s.%s", pipe.Spec.Target.Name, pipe.ObjectMeta.Namespace)
|
||||
targetHost := fmt.Sprintf("%s.%s", pipe.Spec.Target.Name, pipe.ObjectMeta.Namespace)
|
||||
|
||||
for _, username := range pipe.Spec.Users {
|
||||
config = append(
|
||||
|
|
|
|||
|
|
@ -34,7 +34,9 @@ func buildWorkingDir(users []string, t *testing.T) {
|
|||
config.WorkingDir = dir
|
||||
|
||||
for _, u := range users {
|
||||
os.Mkdir(config.WorkingDir+"/"+u, os.ModePerm)
|
||||
if err := os.Mkdir(config.WorkingDir+"/"+u, os.ModePerm); err != nil {
|
||||
t.Fatalf("mkdir dir:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
t.Logf("switch workingdir to %v", config.WorkingDir)
|
||||
|
|
@ -229,8 +231,11 @@ func TestFindUpstreamFromUserfile(t *testing.T) {
|
|||
t.Errorf("fake server error %v", err)
|
||||
return
|
||||
}
|
||||
io.Copy(c, c)
|
||||
c.Close()
|
||||
defer c.Close()
|
||||
if _, err := io.Copy(c, c); err != nil {
|
||||
t.Errorf("fake server copy error %v", err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
addr := listener.Addr().String()
|
||||
|
|
|
|||
|
|
@ -51,26 +51,26 @@ func (p *plugin) ListPipe() ([]upstream.Pipe, error) {
|
|||
return pipes, nil
|
||||
}
|
||||
|
||||
func findnode(root *yaml.Node, test func(*yaml.Node) bool) *yaml.Node {
|
||||
var q []*yaml.Node
|
||||
// func findnode(root *yaml.Node, test func(*yaml.Node) bool) *yaml.Node {
|
||||
// var q []*yaml.Node
|
||||
|
||||
q = append(q, root)
|
||||
// q = append(q, root)
|
||||
|
||||
for len(q) > 0 {
|
||||
e := q[0]
|
||||
q = q[1:]
|
||||
// for len(q) > 0 {
|
||||
// e := q[0]
|
||||
// q = q[1:]
|
||||
|
||||
if test(e) {
|
||||
return e
|
||||
}
|
||||
// if test(e) {
|
||||
// return e
|
||||
// }
|
||||
|
||||
for _, n := range e.Content {
|
||||
q = append(q, n)
|
||||
}
|
||||
}
|
||||
// for _, n := range e.Content {
|
||||
// q = append(q, n)
|
||||
// }
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func findByMapKey(m *yaml.Node, k string) (*yaml.Node, int) {
|
||||
for i := 1; i < len(m.Content); i += 2 {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ Go Runtime : {{.GOVER}}
|
|||
Git Commit : {{.GITHASH}}
|
||||
`[1:]))
|
||||
|
||||
versionTemplate.Execute(os.Stdout, struct {
|
||||
_ = versionTemplate.Execute(os.Stdout, struct {
|
||||
VER string
|
||||
GOVER string
|
||||
GITHASH string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue