template for easier plugin
This commit is contained in:
parent
5dda30365e
commit
8d56673982
3 changed files with 91 additions and 62 deletions
|
|
@ -1,9 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tg123/sshpiper/libplugin"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
|
@ -11,11 +8,9 @@ import (
|
|||
|
||||
func main() {
|
||||
|
||||
app := &cli.App{
|
||||
Name: "fixed",
|
||||
Usage: "sshpiperd fixed plugin, only password auth is supported",
|
||||
HideHelpCommand: true,
|
||||
HideHelp: true,
|
||||
libplugin.CreateAndRunPluginTemplate(&libplugin.PluginTemplate{
|
||||
Name: "fixed",
|
||||
Usage: "sshpiperd fixed plugin, only password auth is supported",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "target",
|
||||
|
|
@ -24,17 +19,15 @@ func main() {
|
|||
Required: true,
|
||||
},
|
||||
},
|
||||
Writer: os.Stderr,
|
||||
ErrWriter: os.Stderr,
|
||||
Action: func(c *cli.Context) error {
|
||||
CreateConfig: func(c *cli.Context) (*libplugin.SshPiperPluginConfig, error) {
|
||||
target := c.String("target")
|
||||
|
||||
host, port, err := libplugin.SplitHostPortForSSH(target)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config := libplugin.SshPiperPluginConfig{
|
||||
return &libplugin.SshPiperPluginConfig{
|
||||
PasswordCallback: func(conn libplugin.ConnMetadata, password []byte) (*libplugin.Upstream, error) {
|
||||
log.Info("routing to ", target)
|
||||
return &libplugin.Upstream{
|
||||
|
|
@ -43,23 +36,8 @@ func main() {
|
|||
IgnoreHostKey: true,
|
||||
Auth: libplugin.CreatePasswordAuth(password),
|
||||
}, nil
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
p, err := libplugin.NewFromStdio(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
libplugin.ConfigStdioLogrus(p, nil)
|
||||
|
||||
log.Printf("starting fix routing to ssh endpoint %v (password only)", target)
|
||||
return p.Serve()
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot start plugin: %v\n", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue