platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
73
selective-vpn-api/app/transport_backends.go
Normal file
73
selective-vpn-api/app/transport_backends.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
transportBackendActionTimeout = 20 * time.Second
|
||||
transportBackendHealthTimeout = 5 * time.Second
|
||||
transportBackendProbeTimeout = 900 * time.Millisecond
|
||||
)
|
||||
|
||||
var transportSystemdUnitsDir = "/etc/systemd/system"
|
||||
|
||||
type transportCommandRunner func(timeout time.Duration, name string, args ...string) (string, string, int, error)
|
||||
|
||||
var transportRunCommand transportCommandRunner = runCommandTimeout
|
||||
|
||||
type transportBackendActionResult struct {
|
||||
OK bool
|
||||
Code string
|
||||
Message string
|
||||
ExitCode int
|
||||
Stdout string
|
||||
Stderr string
|
||||
Retryable bool
|
||||
}
|
||||
|
||||
type transportBackendHealthResult struct {
|
||||
OK bool
|
||||
Code string
|
||||
Message string
|
||||
Status TransportClientStatus
|
||||
LatencyMS int
|
||||
Retryable bool
|
||||
}
|
||||
|
||||
type transportBackendAdapter interface {
|
||||
ID() string
|
||||
Action(client TransportClient, action string) transportBackendActionResult
|
||||
Health(client TransportClient) transportBackendHealthResult
|
||||
Provision(client TransportClient) transportBackendActionResult
|
||||
Cleanup(client TransportClient) transportBackendActionResult
|
||||
}
|
||||
|
||||
func selectTransportBackend(client TransportClient) transportBackendAdapter {
|
||||
mode := transportRuntimeMode(client.Config)
|
||||
switch mode {
|
||||
case "exec":
|
||||
// Continue with current runner-based backend selection.
|
||||
case "embedded", "sidecar":
|
||||
return transportUnsupportedRuntimeBackend{mode: mode}
|
||||
default:
|
||||
return transportUnsupportedRuntimeBackend{mode: mode}
|
||||
}
|
||||
|
||||
runner := strings.ToLower(strings.TrimSpace(transportConfigString(client.Config, "runner")))
|
||||
unit := strings.TrimSpace(transportConfigString(client.Config, "unit"))
|
||||
switch runner {
|
||||
case "systemd":
|
||||
return transportSystemdBackend{}
|
||||
case "mock":
|
||||
return transportMockBackend{}
|
||||
case "":
|
||||
if unit != "" {
|
||||
return transportSystemdBackend{}
|
||||
}
|
||||
return transportMockBackend{}
|
||||
default:
|
||||
return transportMockBackend{}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user