aboutsummaryrefslogtreecommitdiff
path: root/awwan.go
diff options
context:
space:
mode:
Diffstat (limited to 'awwan.go')
-rw-r--r--awwan.go24
1 files changed, 11 insertions, 13 deletions
diff --git a/awwan.go b/awwan.go
index 32da73f..6a5b5b3 100644
--- a/awwan.go
+++ b/awwan.go
@@ -68,9 +68,6 @@ const defTmpDirPlay = `~/.cache/awwan`
type Awwan struct {
cryptoc *cryptoContext
- // All the Host values from SSH config files.
- sshConfig *sshconfig.Config
-
httpd *httpServer
BaseDir string
@@ -407,6 +404,7 @@ func (aww *Awwan) Play(ctx context.Context, req *ExecRequest) (err error) {
sessionDir = filepath.Dir(req.scriptPath)
ses *Session
+ sshConfig *sshconfig.Config
sshSection *sshconfig.Section
pos linePosition
)
@@ -424,12 +422,12 @@ func (aww *Awwan) Play(ctx context.Context, req *ExecRequest) (err error) {
// Always load the SSH config, in case we run on "serve" and
// .ssh/config changed by user.
- err = aww.loadSSHConfig()
+ sshConfig, err = aww.loadSSHConfig()
if err != nil {
goto out
}
- sshSection = aww.sshConfig.Get(ses.hostname)
+ sshSection = sshConfig.Get(ses.hostname)
if sshSection == nil {
err = fmt.Errorf(`can not find Host %q in SSH config`, ses.hostname)
goto out
@@ -507,7 +505,7 @@ func (aww *Awwan) Stop() (err error) {
// loadSSHConfig load all SSH config from user's home and the awwan base
// directory.
-func (aww *Awwan) loadSSHConfig() (err error) {
+func (aww *Awwan) loadSSHConfig() (sshConfig *sshconfig.Config, err error) {
var (
logp = `loadSSHConfig`
@@ -518,27 +516,27 @@ func (aww *Awwan) loadSSHConfig() (err error) {
homeDir, err = os.UserHomeDir()
if err != nil {
- return fmt.Errorf("%s: %w", logp, err)
+ return nil, fmt.Errorf(`%s: %w`, logp, err)
}
configFile = filepath.Join(homeDir, defSSHDir, defSSHConfig)
- aww.sshConfig, err = sshconfig.Load(configFile)
+ sshConfig, err = sshconfig.Load(configFile)
if err != nil {
- return fmt.Errorf("%s: %w", logp, err)
+ return nil, fmt.Errorf(`%s: %w`, logp, err)
}
configFile = filepath.Join(aww.BaseDir, defSSHDir, defSSHConfig)
baseDirConfig, err = sshconfig.Load(configFile)
if err != nil {
- return fmt.Errorf("%s: %w", logp, err)
+ return nil, fmt.Errorf(`%s: %w`, logp, err)
}
if baseDirConfig == nil {
- return nil
+ return nil, nil
}
- aww.sshConfig.Merge(baseDirConfig)
+ sshConfig.Merge(baseDirConfig)
- return nil
+ return sshConfig, nil
}
// lookupBaseDir find the directory that contains ".ssh" directory from