Merge branch 'lash/ssh-fixes' into lash/purify-more
This commit is contained in:
commit
02823fd64e
@ -35,8 +35,10 @@ func main() {
|
|||||||
var sessionId string
|
var sessionId string
|
||||||
var database string
|
var database string
|
||||||
var engineDebug bool
|
var engineDebug bool
|
||||||
|
var resourceDir string
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
flag.StringVar(&resourceDir, "resourcedir", scriptDir, "resource dir")
|
||||||
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
||||||
flag.StringVar(&connStr, "c", "", "connection string")
|
flag.StringVar(&connStr, "c", "", "connection string")
|
||||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||||
@ -67,7 +69,6 @@ func main() {
|
|||||||
MenuSeparator: menuSeparator,
|
MenuSeparator: menuSeparator,
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceDir := scriptDir
|
|
||||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||||
|
|
||||||
rs, err := menuStorageService.GetResource(ctx)
|
rs, err := menuStorageService.GetResource(ctx)
|
||||||
|
@ -14,7 +14,10 @@ import (
|
|||||||
"git.defalsify.org/vise.git/engine"
|
"git.defalsify.org/vise.git/engine"
|
||||||
"git.defalsify.org/vise.git/logging"
|
"git.defalsify.org/vise.git/logging"
|
||||||
|
|
||||||
|
"git.grassecon.net/urdt/ussd/config"
|
||||||
|
"git.grassecon.net/urdt/ussd/initializers"
|
||||||
"git.grassecon.net/urdt/ussd/internal/ssh"
|
"git.grassecon.net/urdt/ussd/internal/ssh"
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -26,7 +29,14 @@ var (
|
|||||||
build = "dev"
|
build = "dev"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initializers.LoadEnvVariables()
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
config.LoadConfig()
|
||||||
|
|
||||||
|
var connStr string
|
||||||
var dbDir string
|
var dbDir string
|
||||||
var resourceDir string
|
var resourceDir string
|
||||||
var size uint
|
var size uint
|
||||||
@ -34,17 +44,25 @@ func main() {
|
|||||||
var stateDebug bool
|
var stateDebug bool
|
||||||
var host string
|
var host string
|
||||||
var port uint
|
var port uint
|
||||||
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
flag.StringVar(&connStr, "c", "", "connection string")
|
||||||
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
||||||
flag.BoolVar(&engineDebug, "engine-debug", false, "use engine debug output")
|
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||||
flag.BoolVar(&stateDebug, "state-debug", false, "use engine debug output")
|
|
||||||
flag.UintVar(&size, "s", 160, "max size of output")
|
flag.UintVar(&size, "s", 160, "max size of output")
|
||||||
flag.StringVar(&host, "h", "127.0.0.1", "http host")
|
flag.StringVar(&host, "h", "127.0.0.1", "socket host")
|
||||||
flag.UintVar(&port, "p", 7122, "http port")
|
flag.UintVar(&port, "p", 7122, "socket port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if connStr != "" {
|
||||||
|
connStr = config.DbConn
|
||||||
|
}
|
||||||
|
connData, err := storage.ToConnData(config.DbConn)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
sshKeyFile := flag.Arg(0)
|
sshKeyFile := flag.Arg(0)
|
||||||
_, err := os.Stat(sshKeyFile)
|
_, err = os.Stat(sshKeyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "cannot open ssh server private key file: %v\n", err)
|
fmt.Fprintf(os.Stderr, "cannot open ssh server private key file: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -92,10 +110,10 @@ func main() {
|
|||||||
signal.Notify(cterm, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(cterm, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
runner := &ssh.SshRunner{
|
runner := &ssh.SshRunner{
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
Debug: engineDebug,
|
Debug: engineDebug,
|
||||||
FlagFile: pfp,
|
FlagFile: pfp,
|
||||||
DbDir: dbDir,
|
Conn: connData,
|
||||||
ResourceDir: resourceDir,
|
ResourceDir: resourceDir,
|
||||||
SrvKeyFile: sshKeyFile,
|
SrvKeyFile: sshKeyFile,
|
||||||
Host: host,
|
Host: host,
|
||||||
|
@ -71,6 +71,20 @@ func(a *auther) Get(k []byte) (string, error) {
|
|||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SshRunner struct {
|
||||||
|
Ctx context.Context
|
||||||
|
Cfg engine.Config
|
||||||
|
FlagFile string
|
||||||
|
Conn storage.ConnData
|
||||||
|
ResourceDir string
|
||||||
|
Debug bool
|
||||||
|
SrvKeyFile string
|
||||||
|
Host string
|
||||||
|
Port uint
|
||||||
|
wg sync.WaitGroup
|
||||||
|
lst net.Listener
|
||||||
|
}
|
||||||
|
|
||||||
func(s *SshRunner) serve(ctx context.Context, sessionId string, ch ssh.NewChannel, en engine.Engine) error {
|
func(s *SshRunner) serve(ctx context.Context, sessionId string, ch ssh.NewChannel, en engine.Engine) error {
|
||||||
if ch == nil {
|
if ch == nil {
|
||||||
return errors.New("nil channel")
|
return errors.New("nil channel")
|
||||||
@ -128,32 +142,13 @@ func(s *SshRunner) serve(ctx context.Context, sessionId string, ch ssh.NewChanne
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type SshRunner struct {
|
|
||||||
Ctx context.Context
|
|
||||||
Cfg engine.Config
|
|
||||||
FlagFile string
|
|
||||||
DbDir string
|
|
||||||
ResourceDir string
|
|
||||||
Debug bool
|
|
||||||
SrvKeyFile string
|
|
||||||
Host string
|
|
||||||
Port uint
|
|
||||||
wg sync.WaitGroup
|
|
||||||
lst net.Listener
|
|
||||||
}
|
|
||||||
|
|
||||||
func(s *SshRunner) Stop() error {
|
func(s *SshRunner) Stop() error {
|
||||||
return s.lst.Close()
|
return s.lst.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func(s *SshRunner) GetEngine(sessionId string) (engine.Engine, func(), error) {
|
func(s *SshRunner) GetEngine(sessionId string) (engine.Engine, func(), error) {
|
||||||
ctx := s.Ctx
|
ctx := s.Ctx
|
||||||
menuStorageService := storage.NewMenuStorageService(s.DbDir, s.ResourceDir)
|
menuStorageService := storage.NewMenuStorageService(s.Conn, s.ResourceDir)
|
||||||
|
|
||||||
err := menuStorageService.EnsureDbDir()
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
rs, err := menuStorageService.GetResource(ctx)
|
rs, err := menuStorageService.GetResource(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user