From a28b8b5da5abc74d2e5a23c8447c21909fb64d98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=92=D0=BE=D1=80=D0=BE=D0=B1=D1=8C=D0=B5=D0=B2=20=D0=9F?=
=?UTF-8?q?=D0=B0=D0=B2=D0=B5=D0=BB?=
Date: Tue, 15 Sep 2020 16:43:54 +0300
Subject: [PATCH] configure ssh options
---
cli/cli.go | 1 +
config/config.go | 18 ++++++++++++++++++
remote/ssh.go | 7 +++++++
3 files changed, 26 insertions(+)
diff --git a/cli/cli.go b/cli/cli.go
index b4f4cbf..727e1ff 100644
--- a/cli/cli.go
+++ b/cli/cli.go
@@ -139,6 +139,7 @@ func New(cfg *config.XCConfig, backend store.Backend) (*Cli, error) {
remote.SetNumThreads(cli.sshThreads)
remote.SetSSHCommand(cfg.SSHCommand)
remote.SetRemoteEnvironment(cfg.RemoteEnvironment)
+ remote.ApplyConfiguredOptions(cfg.SSHOptions)
// interpreter
cli.setInterpreter("none", cfg.Interpreter)
diff --git a/config/config.go b/config/config.go
index 260374d..ed3e5b2 100644
--- a/config/config.go
+++ b/config/config.go
@@ -37,6 +37,14 @@ interpreter = bash
interpreter_sudo = sudo bash
interpreter_su = su -
+[ssh]
+PasswordAuthentication = no
+PubkeyAuthentication = yes
+StrictHostKeyChecking = no
+TCPKeepAlive = yes
+ServerAliveCountMax = 12
+ServerAliveInterval = 5
+
[backend]
type = conductor
url = http://c.inventoree.ru
@@ -71,6 +79,7 @@ type XCConfig struct {
SSHThreads int
SSHConnectTimeout int
SSHCommand string
+ SSHOptions map[string]string
RemoteTmpdir string
Mode string
RaiseType string
@@ -165,6 +174,7 @@ func read(filename string, secondPass bool) (*XCConfig, error) {
cfg.BackendCfg = &BackendConfig{Type: BTIni, Options: make(map[string]string)}
cfg.LocalEnvironment = make(map[string]string)
cfg.RemoteEnvironment = make(map[string]string)
+ cfg.SSHOptions = make(map[string]string)
hf, err := props.GetString("main.history_file")
if err != nil {
@@ -298,6 +308,14 @@ func read(filename string, secondPass bool) (*XCConfig, error) {
}
cfg.PrependHostnames = phn
+ sshOptsKeys, err := props.Subkeys("ssh")
+ if err == nil {
+ for _, key := range sshOptsKeys {
+ nsKey := fmt.Sprintf("ssh.%s", key)
+ cfg.SSHOptions[key], _ = props.GetString(nsKey)
+ }
+ }
+
bkeys, err := props.Subkeys("backend")
if err != nil {
return nil, fmt.Errorf("Backend configuration error: %s", err)
diff --git a/remote/ssh.go b/remote/ssh.go
index c985cdf..a1b2094 100644
--- a/remote/ssh.go
+++ b/remote/ssh.go
@@ -15,6 +15,13 @@ var (
}
)
+// ApplyConfiguredOptions merges default options and configured ones
+func ApplyConfiguredOptions(cfgOptions map[string]string) {
+ for k, v := range cfgOptions {
+ sshOptions[k] = v
+ }
+}
+
func sshOpts() (params []string) {
params = make([]string, 0)
for opt, value := range sshOptions {