5 Commits
v1.6 ... v2.2

Author SHA1 Message Date
19f80c7262 mod(workflow): add CGO_ENABLED=0 and GOOS=linux when building release
All checks were successful
Go Project Action / Spell-check and test go project (push) Successful in 2m10s
Release Go Application / Release go project (release) Successful in 37s
2024-11-01 15:09:16 +01:00
1b12a22fc5 mod: add configuration for key.dir and key.name
All checks were successful
Go Project Action / Spell-check and test go project (push) Successful in 34s
Release Go Application / Release go project (release) Successful in 30s
2024-10-07 16:47:02 +02:00
283decf747 add(command): overwrite arguments for app entry with provided arguments
All checks were successful
Go Project Action / Spell-check and test go project (push) Successful in 32s
Release Go Application / Release go project (release) Successful in 30s
2024-10-06 14:28:38 +02:00
293932534d rem(action): depth 0 configuration
All checks were successful
Go Project Action / Spell-check and test go project (push) Successful in 33s
There is no benefit in doing this at all
2024-10-06 11:43:17 +02:00
b3e5c1edcb mod(action): remove release trigger action for test.yaml
All checks were successful
Go Project Action / Spell-check and test go project (push) Successful in 33s
2024-10-06 11:39:51 +02:00
4 changed files with 29 additions and 11 deletions

View File

@@ -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:
@@ -23,7 +21,7 @@ jobs:
- name: Install dependencies
run: go get .
- name: Build
run: go build -ldflags "-s -w" -o ./bin/serve main.go
run: CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" -o ./bin/serve main.go
- name: Release build artifacts
uses: akkuman/gitea-release-action@v1.3.2
with:

View File

@@ -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:

View File

@@ -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)
}

24
main.go
View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"os"
"github.com/spf13/viper"
"yves-biener.de/wish-serve/internal/serve"
@@ -11,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"})
}
@@ -30,13 +33,34 @@ func loadConfig() {
}
}
// 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"),