get config from .env, persist ssh host key
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Wojciech Kwolek 2021-10-18 16:20:00 +02:00
parent e3a1e9573e
commit 1e1bc3594c
5 changed files with 18 additions and 2 deletions

3
.env.sample Normal file
View File

@ -0,0 +1,3 @@
SSH_KEY=./id_ed25519
SSH_ADDR=:2222
HTTP_ADDR=:8080

2
.gitignore vendored
View File

@ -1 +1,3 @@
dist/
.env
id_*

1
go.mod
View File

@ -11,6 +11,7 @@ require (
require (
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/joho/godotenv v1.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect

2
go.sum
View File

@ -4,6 +4,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gliderlabs/ssh v0.3.3 h1:mBQ8NiOgDkINJrZtoizkC3nDNYgSaWtxyem6S2XHBtA=
github.com/gliderlabs/ssh v0.3.3/go.mod h1:ZSS+CUoKHDrqVakTfTWUlKSr9MtMFkC4UvtQKD7O914=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

12
main.go
View File

@ -5,10 +5,13 @@ import (
"fmt"
"io"
"log"
"os"
"strings"
"time"
"github.com/gliderlabs/ssh"
"github.com/joho/godotenv"
terminal "golang.org/x/term"
)
@ -60,6 +63,11 @@ func CheckString(s string) bool {
}
func main() {
godotenv.Load()
sshKey := ssh.HostKeyFile(os.Getenv("SSH_KEY"))
sshAddr := os.Getenv("SSH_ADDR")
httpAddr := os.Getenv("HTTP_ADDR")
m := NewMessageList(10)
pkAuth := ssh.PublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) bool {
return true
@ -163,6 +171,6 @@ func main() {
web := Web{
Messages: m,
}
go web.ListenAndServe(":8080")
log.Fatal(ssh.ListenAndServe(":2222", nil, pkAuth))
go web.ListenAndServe(httpAddr)
log.Fatal(ssh.ListenAndServe(sshAddr, nil, pkAuth, sshKey))
}