-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (62 loc) · 1.49 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"log"
"os"
"github.com/recode-sh/agent/constants"
"github.com/recode-sh/agent/internal/grpcserver"
"github.com/recode-sh/agent/internal/sshserver"
"github.com/recode-sh/agent/internal/system"
)
var (
SSHServerAuthorizedUsers = []sshserver.AuthorizedUser{
{
UserName: constants.DevEnvRecodeUserName,
AuthorizedKeysFilePath: constants.DevEnvRecodeUserAuthorizedSSHKeysFilePath,
},
}
)
func main() {
// Prevent "bind: address already in use" error
err := ensureOldGRPCServerSocketRemoved(constants.GRPCServerAddr)
if err != nil {
log.Fatalf("%v", err)
}
go func() {
log.Printf(
"GRPC server listening at %s",
constants.GRPCServerAddr,
)
err = grpcserver.ListenAndServe(
constants.GRPCServerAddrProtocol,
constants.GRPCServerAddr,
)
if err != nil {
log.Fatalf("%v", err)
}
}()
sshServerAuth := sshserver.NewAuth(
system.NewFileManager(),
sshserver.NewPrivateKeyManager(),
sshserver.NewAuthorizedKeyManager(),
constants.SSHServerHostKeyFilePath,
SSHServerAuthorizedUsers,
)
sshServerBuilder := sshserver.NewServerBuilder(
sshServerAuth,
constants.SSHServerListenAddr,
)
sshServer, err := sshServerBuilder.Build()
if err != nil {
log.Fatalf("%v", err)
}
log.Printf(
"SSH server listening at %s",
sshServer.Addr,
)
if err = sshServer.ListenAndServe(); err != nil {
log.Fatalf("%v", err)
}
}
func ensureOldGRPCServerSocketRemoved(socketPath string) error {
return os.RemoveAll(socketPath)
}