Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b12a22fc5 | |||
| 283decf747 | |||
| 293932534d | |||
| b3e5c1edcb | |||
| ba8e654b90 | |||
| 62b49cf36c | |||
| 7813db72f1 |
@@ -14,8 +14,6 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup Go installation
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
@@ -25,7 +23,6 @@ jobs:
|
||||
- name: Build
|
||||
run: go build -ldflags "-s -w" -o ./bin/serve main.go
|
||||
- name: Release build artifacts
|
||||
uses: https://gitea.com/actions/release-action@main
|
||||
uses: akkuman/gitea-release-action@v1.3.2
|
||||
with:
|
||||
files: ./bin/serve
|
||||
api_key: '${{secrets.RELEASE_TOKEN}}'
|
||||
|
||||
@@ -4,8 +4,6 @@ on:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
run:
|
||||
@@ -15,8 +13,6 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup Go installation
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
|
||||
2
go.mod
2
go.mod
@@ -6,6 +6,7 @@ require (
|
||||
github.com/charmbracelet/log v0.4.0
|
||||
github.com/charmbracelet/ssh v0.0.0-20240725163421-eb71b85b27aa
|
||||
github.com/charmbracelet/wish v1.4.3
|
||||
github.com/spf13/viper v1.19.0
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -41,7 +42,6 @@ require (
|
||||
github.com/spf13/afero v1.11.0 // indirect
|
||||
github.com/spf13/cast v1.6.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/spf13/viper v1.19.0 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
|
||||
16
go.sum
16
go.sum
@@ -27,17 +27,25 @@ github.com/charmbracelet/x/termios v0.1.0/go.mod h1:H/EVv/KRnrYjz+fCYa9bsKdqF3S8
|
||||
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
|
||||
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
|
||||
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
|
||||
@@ -58,12 +66,14 @@ github.com/muesli/termenv v0.15.3-0.20240509142007-81b8f94111d5 h1:NiONcKK0EV5gU
|
||||
github.com/muesli/termenv v0.15.3-0.20240509142007-81b8f94111d5/go.mod h1:hxSnBBYLK21Vtq/PHd0S2FYCxBXzBua8ov5s1RobyRQ=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
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/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
|
||||
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
|
||||
@@ -109,6 +119,8 @@ golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
|
||||
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
||||
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -34,10 +34,10 @@ func setupLogging() {
|
||||
// all if no user is given) the application `name` with the provided arguments
|
||||
// `args` as the ssh session. The ssh session will always allocate an pty
|
||||
// (necessary for tui applications).
|
||||
func setupSshServer(host string, port string, users map[string]string, name string, args []string) (*ssh.Server, error) {
|
||||
func setupSshServer(host string, port string, host_key_path string, users map[string]string, name string, args []string) (*ssh.Server, error) {
|
||||
return wish.NewServer(
|
||||
wish.WithAddress(net.JoinHostPort(host, port)),
|
||||
wish.WithHostKeyPath(".ssh/ssh_host_ed25519_key"),
|
||||
wish.WithHostKeyPath(host_key_path),
|
||||
wish.WithPublicKeyAuth(func(_ ssh.Context, key ssh.PublicKey) bool {
|
||||
if len(users) == 0 {
|
||||
// no users provided, meaning there is no user authentication, everyone is allowed to connect
|
||||
@@ -69,9 +69,9 @@ func setupSshServer(host string, port string, users map[string]string, name stri
|
||||
}
|
||||
|
||||
// Serve an ssh application using the provided arguments.
|
||||
func Serve(host string, port string, users map[string]string, name string, args []string) {
|
||||
func Serve(host string, port string, host_key_path string, users map[string]string, name string, args []string) {
|
||||
setupLogging()
|
||||
srv, err := setupSshServer(host, port, users, name, args)
|
||||
srv, err := setupSshServer(host, port, host_key_path, users, name, args)
|
||||
if err != nil {
|
||||
log.Error("Could not start server", "error", err)
|
||||
}
|
||||
|
||||
31
main.go
31
main.go
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"yves-biener.de/wish-serve/internal/serve"
|
||||
@@ -12,6 +12,8 @@ func createDefaultConfig() {
|
||||
viper.SetDefault("host", "127.0.0.1")
|
||||
viper.SetDefault("port", "8022")
|
||||
viper.SetDefault("users", map[string]string{})
|
||||
viper.SetDefault("key.dir", ".ssh")
|
||||
viper.SetDefault("key.name", "ssh_ed25519_key")
|
||||
viper.SetDefault("app.name", "echo")
|
||||
viper.SetDefault("app.args", []string{"Hello World"})
|
||||
}
|
||||
@@ -24,18 +26,41 @@ func loadConfig() {
|
||||
viper.SetConfigType("yml")
|
||||
viper.AddConfigPath("$HOME/.config/serve")
|
||||
viper.AddConfigPath(".")
|
||||
if err := viper.ReadInConfig(); err != nil && !errors.Is(err, viper.ConfigFileNotFoundError{}) {
|
||||
panic(fmt.Errorf("fatal error config file: %w", err))
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
||||
panic(fmt.Errorf("fatal error config file: %w", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Overwrite (default) configuration value for the application to serve with
|
||||
// given command line arguments.
|
||||
//
|
||||
// NOTE: This will also overwrite the configuration for the `app` entry from the
|
||||
// configuration file.
|
||||
func overwriteServeCommand() {
|
||||
if len(os.Args) >= 2 {
|
||||
name := os.Args[1]
|
||||
viper.Set("app.name", name)
|
||||
if len(os.Args) >= 3 {
|
||||
args := os.Args[2:]
|
||||
viper.Set("app.args", args)
|
||||
} else {
|
||||
// no arguments provided -> clear app arguments
|
||||
viper.Set("app.args", []string{})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
createDefaultConfig()
|
||||
loadConfig()
|
||||
overwriteServeCommand()
|
||||
|
||||
serve.Serve(
|
||||
viper.GetString("host"),
|
||||
viper.GetString("port"),
|
||||
fmt.Sprintf("%s/%s", viper.GetString("key.dir"), viper.GetString("key.name")),
|
||||
viper.GetStringMapString("users"),
|
||||
viper.GetString("app.name"),
|
||||
viper.GetStringSlice("app.args"),
|
||||
|
||||
Reference in New Issue
Block a user