diff options
| author | Shulhan <ms@kilabit.info> | 2023-09-24 02:45:02 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-09-26 00:24:08 +0700 |
| commit | 0820acb54154205b748bd678edf714840f4ca009 (patch) | |
| tree | 338b17dbee3949a79234d0046dd2e8d6bef0dbf2 | |
| parent | 9ae9a42e37b35e17120045da8bb72b07f6de2a44 (diff) | |
| download | awwan-0820acb54154205b748bd678edf714840f4ca009.tar.xz | |
all: call loadEnvFromPaths inside newSession
Since loadEnvFromPaths always called after NewSession, and it is part
of session initialization, we can move the call inside the NewSession
to minimize duplicate code.
| -rw-r--r-- | awwan.go | 10 | ||||
| -rw-r--r-- | awwan_test.go | 4 | ||||
| -rw-r--r-- | session.go | 7 |
3 files changed, 8 insertions, 13 deletions
@@ -207,11 +207,6 @@ func (aww *Awwan) Local(req *Request) (err error) { return fmt.Errorf("%s: %w", logp, err) } - err = ses.loadEnvFromPaths() - if err != nil { - return fmt.Errorf("%s: %w", logp, err) - } - if len(req.Content) == 0 { req.script, err = NewScript(ses, req.scriptPath) } else { @@ -276,11 +271,6 @@ func (aww *Awwan) Play(req *Request) (err error) { return fmt.Errorf("%s: %w", logp, err) } - err = ses.loadEnvFromPaths() - if err != nil { - return fmt.Errorf("%s: %w", logp, err) - } - if aww.sshConfig == nil { err = aww.loadSshConfig() if err != nil { diff --git a/awwan_test.go b/awwan_test.go index 6438ea2..7973325 100644 --- a/awwan_test.go +++ b/awwan_test.go @@ -265,12 +265,12 @@ func TestAwwanLocalPut_withEncryption(t *testing.T) { tdataOut: `local.aww:3:exp_file_content`, }, { desc: `WithEmptyPrivateKey`, - expError: `Local: loadEnvFromPaths: private key is missing or not loaded`, + expError: `Local: NewSession: loadEnvFromPaths: private key is missing or not loaded`, resetPrivateKey: true, }, { desc: `WithInvalidPassphrase`, passphrase: "invalid\r", - expError: `Local: loadEnvFromPaths: LoadPrivateKeyInteractive: x509: decryption password incorrect`, + expError: `Local: NewSession: loadEnvFromPaths: LoadPrivateKeyInteractive: x509: decryption password incorrect`, resetPrivateKey: true, }} @@ -49,7 +49,7 @@ type Session struct { // directory and the session directory. func NewSession(aww *Awwan, sessionDir string) (ses *Session, err error) { var ( - logp = "newSession" + logp = `NewSession` randomString string ) @@ -67,6 +67,11 @@ func NewSession(aww *Awwan, sessionDir string) (ses *Session, err error) { return nil, fmt.Errorf("%s: %w", logp, err) } + err = ses.loadEnvFromPaths() + if err != nil { + return nil, fmt.Errorf(`%s: %w`, logp, err) + } + randomString = string(ascii.Random([]byte(ascii.LettersNumber), 16)) ses.tmpDir = filepath.Join(defTmpDir, randomString) |
