mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
add ssh destination to connection config
This commit is contained in:
@@ -6,6 +6,6 @@ type Cluster struct {
|
|||||||
Name string `toml:"-"`
|
Name string `toml:"-"`
|
||||||
Machines []MachineConnection `toml:"machines"`
|
Machines []MachineConnection `toml:"machines"`
|
||||||
Secret secret.Secret `toml:"secret"`
|
Secret secret.Secret `toml:"secret"`
|
||||||
// UserKey is the user's WireGuard private key used to connect to cluster machines.
|
// UserPrivateKey is the user's WireGuard private key used to connect to cluster machines.
|
||||||
UserKey secret.Secret `toml:"user_key"`
|
UserPrivateKey secret.Secret `toml:"user_private_key"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,45 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"uncloud/internal/secret"
|
"uncloud/internal/secret"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultSSHUser = "root"
|
||||||
|
DefaultSSHPort = 22
|
||||||
|
)
|
||||||
|
|
||||||
type MachineConnection struct {
|
type MachineConnection struct {
|
||||||
Host string `toml:"host"`
|
SSH SSHDestination `toml:"ssh,omitempty"`
|
||||||
PublicKey secret.Secret `toml:"public_key"`
|
Host string `toml:"host,omitempty"`
|
||||||
|
PublicKey secret.Secret `toml:"public_key,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SSHDestination string
|
||||||
|
|
||||||
|
func NewSSHDestination(user, host string, port int) SSHDestination {
|
||||||
|
dst := host
|
||||||
|
if port != 0 && port != DefaultSSHPort {
|
||||||
|
dst = net.JoinHostPort(host, strconv.Itoa(port))
|
||||||
|
}
|
||||||
|
if user == "" {
|
||||||
|
user = DefaultSSHUser
|
||||||
|
}
|
||||||
|
dst = user + "@" + dst
|
||||||
|
return SSHDestination(dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d SSHDestination) Parse() (user string, host string, port int, err error) {
|
||||||
|
if strings.Contains(string(d), "@") {
|
||||||
|
user, host, _ = strings.Cut(string(d), "@")
|
||||||
|
}
|
||||||
|
h, p, sErr := net.SplitHostPort(host)
|
||||||
|
if sErr == nil {
|
||||||
|
host = h
|
||||||
|
port, err = strconv.Atoi(p)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user