grim/hgkeeper

6eec5741c02e
Parents ceeb74cb0ce0
Children 3c290648b1c5
Move the serve command to it's own package
--- a/main.go Thu Apr 18 14:40:37 2019 -0500
+++ b/main.go Thu Apr 18 15:25:12 2019 -0500
@@ -6,13 +6,13 @@
"github.com/alecthomas/kong"
log "github.com/sirupsen/logrus"
+ "bitbucket.org/rw_grim/hgkeeper/serve"
"bitbucket.org/rw_grim/hgkeeper/setup"
- "bitbucket.org/rw_grim/hgkeeper/ssh"
)
type commands struct {
ReposPath string `kong:"flag,name='repos-path',default='repos',help='the directory where the repository are stored'"`
- Serve ssh.ServeCommand `kong:"cmd,help='run the ssh server'"`
+ Serve serve.Command `kong:"cmd,help='run the ssh server'"`
Setup setup.SetupCommand `kong:"cmd,help='inital setup for the server'"`
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/serve/command.go Thu Apr 18 15:25:12 2019 -0500
@@ -0,0 +1,26 @@
+package serve
+
+import (
+ "bitbucket.org/rw_grim/hgkeeper/ssh"
+)
+
+type Command struct {
+ SSHAddr string `kong:"flag,name='ssh-listen-addr',short='l',help='what address to listen on',default=':22222'"`
+ SSHHostKeysPath string `kong:"flag,name='ssh-host-keys-path',short='H',help='the path where host keys are kept',default='host-keys'"`
+}
+
+func (c *Command) Run(reposPath string) error {
+ s := ssh.NewServer()
+
+ err := s.SetHostKeysPath(c.SSHHostKeysPath)
+ if err != nil {
+ return err
+ }
+
+ err = s.Listen(c.SSHAddr)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
--- a/ssh/command.go Thu Apr 18 14:40:37 2019 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-package ssh
-
-type ServeCommand struct {
- Addr string `kong:"flag,name='listen-addr',short='l',help='what address to listen on',default=':22222'"`
- HostKeysPath string `kong:"flag,name='host-keys-path',short='H',help='the path where host keys are kept',default='host-keys'"`
-}
-
-func (c *ServeCommand) Run(reposPath string) error {
- s := NewServer()
-
- err := s.loadHostKeys(c.HostKeysPath)
- if err != nil {
- return err
- }
-
- err = s.Listen(c.Addr)
- if err != nil {
- return err
- }
-
- return nil
-}
--- a/ssh/keys.go Thu Apr 18 14:40:37 2019 -0500
+++ b/ssh/keys.go Thu Apr 18 15:25:12 2019 -0500
@@ -9,7 +9,7 @@
"golang.org/x/crypto/ssh"
)
-func (s *Server) loadHostKeys(hostKeysPath string) error {
+func (s *Server) SetHostKeysPath(hostKeysPath string) error {
files, err := ioutil.ReadDir(hostKeysPath)
if err != nil {
return err