-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e632036
commit 0b08431
Showing
3 changed files
with
61 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package befehl | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
func (instance *Instance) getSshUser() string { | ||
if instance.options.SshUser != "" { | ||
return instance.options.SshUser | ||
} | ||
return "root" | ||
} | ||
|
||
func (instance *Instance) getSshClientConfig() *ssh.ClientConfig { | ||
return &ssh.ClientConfig{ | ||
User: instance.getSshUser(), | ||
Auth: []ssh.AuthMethod{ | ||
ssh.PublicKeys(instance.sshKey), | ||
}, | ||
Timeout: time.Duration(10) * time.Second, | ||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), | ||
} | ||
} | ||
|
||
func (instance *Instance) getLogDir() string { | ||
if instance.options.LogDir != "" { | ||
return instance.options.LogDir | ||
} | ||
return os.Getenv("HOME") + "/befehl/logs" | ||
} | ||
|
||
func (instance *Instance) getLogFilePath(host string) string { | ||
return instance.getLogDir() + "/" + host | ||
} | ||
|
||
func (instance *Instance) getPrivKeyFile() string { | ||
if instance.options.PrivateKeyFile != "" { | ||
return instance.options.PrivateKeyFile | ||
} | ||
|
||
return os.Getenv("HOME") + "/.ssh/id_rsa" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package befehl | ||
|
||
import ( | ||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
type Options struct { | ||
PrivateKeyFile string | ||
SshUser string | ||
LogDir string | ||
} | ||
|
||
type Instance struct { | ||
options *Options | ||
sshKey ssh.Signer | ||
} |