aboutsummaryrefslogtreecommitdiff
path: root/session.go
AgeCommit message (Collapse)Author
2026-02-15all: fix chmod/chown if destination is directoryShulhan
Given the following command #put!+0644 src/file dst/ If the dst is a directory, it would cause the directory permission changes to 0644. This changes fix it by checking if the destination is a directory first. If we cannot stat the dst, skip the chmod/chown command.
2025-10-03all: add option "$noparse" for magic "#put" commandShulhan
The "$noparse" option allow copying file without reading and parsing the input file.
2024-04-06all: comply with linter recommendationsShulhan
2024-03-22all: replace module "share" with "pakakeh.go"Shulhan
The "share" project has been moved to SourceHut with new name "pakakeh.go".
2023-12-22all: support cancellation when running command using SSH clientShulhan
This changes require us to replace golang.org/x/crypto with our fork, since the [ssh.Session.Run] with context is not available yet in upstream. Implements: https://todo.sr.ht/~shulhan/awwan/9
2023-12-22all: add [context.Context] to Local and PlayShulhan
Passing context allow the command Local or Play to be cancelled when running in asynchronous mode, in this case when awwan run with WUI.
2023-12-18all: fix panic due to out of range when running "#require" statementShulhan
2023-12-17all: change the remote temporary directory to "~/.cache/awwan"Shulhan
If the file to be copied contains sensitive data, putting them in "/tmp" considered a security risk, even though it will be moved to destination later. The issue is when the "#put" command failed, the plain file is left on "/tmp" directory. This changes add additional advantage where we did not need to remove the temporary directory on remote when execution completed, since the temporary directory should be accessible by user only. Implements: https://todo.sr.ht/~shulhan/awwan/8
2023-12-16all: make the magic line "#put:" use explicit source for encrypted fileShulhan
Previously, the magic line "#put" detect whether the source file is encrypted or not automatically, so we did not need to put ".vault" suffix in the source path. This changes make it to be always explicit. If we want to copy encrypted file than the source file must be the path to encrypted file. Implements: https://todo.sr.ht/~shulhan/awwan/7
2023-12-14all: make the magic line "#local" works on "local" command tooShulhan
In case we have a script that manage local host and remote server, calling "play" on "#local" lines only always open the connection to remote server. To minimize opening unused connections, let the "#local" command works on both commands. Its up to user which part of lines that they want to execute on remote or local.
2023-12-14all: close the SSH connection once Play finishedShulhan
Previously, we used to run awwan as CLI so each connection is open and closed (forcefully). Since we now use awwan WUI frequently, any command that execute Play does not close the session immediately once finished. This cause many connections open in remote server. This changes close the SSH connections immediately once the Play command finished.
2023-12-14all: changes based on reports from linter reviveShulhan
Better to fix and follow the reported warnings rather than adding configuration file to add an exception.
2023-12-05all: remove duplicate errors logged on Copy, Put, and SudoCopyShulhan
While at it, replace all call of [log.Printf] with [Request.mlog] so error both written to stderr and to [Request.Output].
2023-12-01all: move wrapping BEGIN and END outside of sessionShulhan
2023-11-25all: print non error information using package log instead of fmtShulhan
Although log print to stderr, this allow user to filter between awwan output and command output, for example by piping stderr to /dev/null $ awwan env-get "key" dir/ 2>/dev/null The output env-get is not poluted by other logs.
2023-11-17all: log each time section createdShulhan
2023-11-16all: refactoring, rename Request to ExecRequestShulhan
2023-10-30all: pass Request when creating new SSH clientShulhan
Instead of passing stdout and stderr as "io.Writer", pass the Request, so we can log using the Request mlog. While at it, return error from sshClient rmdirAll so the caller can log the error.
2023-10-30all: add begin and end for each script executionShulhan
When the script executed, log the script and line number to be executed with "=== BEGIN", and when its finished, log the end of it with "=== END". This is to make the log more traceable.
2023-10-30all: log all execution into fileShulhan
For each script execution, a file suffixed with ".log" will be created in the same directory with the same name as script file. For example, if the script is path is "a/b/c.aww" then the log file would named "a/b/c.aww.log". This is to provides history and audit in the future.
2023-10-26all: use "mlog.MultiLogger" to log Request output and errorShulhan
By using "mlog.MultiLogger" every output or error can be written to stdout/stderr and additional log writer that can collect both of them, buffered and returned to the caller. This changes simplify the HttpResponse to use only single output that combine both stdout and stderr.
2023-10-25all: log and simplify error when source file is not existShulhan
Previously, if the source file to be copied is not exist, awwan will output only error for the ".vault" file, twice, for example !!! Copy: <source>.vault: open <source>.vault not exist Local: Copy: <source>.vault: open <source>.vault not exist This changes make the first line output to print the original source file first, the non-ecrypted one, and then followed by encrypted one, ??? loadFileInput "<source>": not exist Local: Copy "<source>.vault": not exist
2023-10-22all: add magic command "#local"Shulhan
The magic command "#local" define the command to be executed using shell in local environment. Its have effect and can only be used in script that executed using "play". In script that is executed using "local" it does nothing.
2023-10-21all: implement remote "#get!" and "#put!" with owner and modeShulhan
When script with magic command "#get!" or "#put!" executed using "play" command, one can changes the owner and/or permission mode by setting the user/group and permission bits after the magic command, for example, #get!user:group+0600 src dst Will changes the owner of dst in local into "user:group" with permission "0600", while #put!user:group+0600 src dst Will changes the owner of dst in remote into "user:group" with permission "0600".
2023-10-21all: set the mode permission first before owner in Copy and SudoCopyShulhan
In case of Copy, the user that run chmod definitely can change the permission but may not have privileged to chown. By setting the permission first, we minimize error during "#get:" or "#put:".
2023-10-21all: implement remote "#get:" and "#put:" with owner and modeShulhan
In remote environment, using magic command "#get:" or "#put:" with owner and mode like "#get:$OWNER+$MODE" or "#put:$OWNER+MODE" will changes the file owner to $USER or $GROUP and/or permission to $MODE. The file owner will not works if user does not have permission.
2023-10-21all: implement local "#get!" and "#put!" with owner and modeShulhan
In local environment, using magic command "#get!" or "#put!" with owner and mode set, like "#get:$USER:$GROUP+$MODE" or "#put:$USER:$GROUP+MODE", will changes the file owner to $USER or $GROUP and/or permission to $MODE.
2023-10-21all: implement local "#get:" and "#put:" with owner and modeShulhan
In local environment, using magic command "#get" or "#put" with mode like "#get:$USER:$GROUP+$MODE" or "#put:$USER:$GROUP+MODE" will changes the file owner to $USER or $GROUP and/or permission to $MODE. The file owner does not works if user does not have permission to changes the owner.
2023-10-17session: use the raw statement when adding "-S" option in ExecLocalShulhan
Previously, when refactoring ExecLocal in bf9c8226b4d to support sudo with -S option, we generate the raw command by concatenating Statement args field. This model does not works if the raw command contains double quote that needs to be executed as is. This changes fix this issue by adding "-S" option to raw command.
2023-10-14all: refactoring ExecLocal to add sudo "-S" option when stdin is not-nilShulhan
Instead of adding the "-S" option before ExecLocal is called, we automatically added inside the ExecLocal, so the caller does not need to check or add the "-S" option. This makes all local statements ("#require", default, "#get!", "#put!") that is sudo works without any modification like we do previously in SudoCopy. While at it, we detach ExecLocal from Session, since the "*Session" receiver is never used inside their body.
2023-10-12all: add integration tests for magic command "#get!"Shulhan
2023-10-12all: return error from executeScriptOnLocalShulhan
Instead of breaking the statement when its failed to execute, return the error to the caller, Local.
2023-10-12all: fix printing the statement to be executedShulhan
This fix missing magic command not printed in stdout.
2023-10-07all: simplify parsing statement for magic command "#put"Shulhan
This changes minimize code duplication when parsing magic command between "#put:" and "#put!" using single function parseStatementGetPut. In the returned Statement, we changes where to store the source argument into args[0] instead of in cmd for better readability and minimize confusion in Copy/SudoCopy.
2023-10-06all: quote the source and destination in SudoCopyShulhan
This is to prevent a source file that contains ";" cause the next string executed as command instead of file.
2023-10-06all: simplify parsing statement for magic command getShulhan
This changes minimize code duplication when parsing magic command between "#get:" and "#get!" using single function parseStatementGetPut. In the returned Statement, we changes where to store the source argument into args[0] instead of in cmd for better readability and minimize confusion in Copy/SudoCopy. While at it, we add unit test for "#get:". Unit test for "#get!" is not possible right now, because it will prompt for password.
2023-09-27all: print any path relative to base directoryShulhan
This is to minimize log length in stdout and stderr, which make it more readable.
2023-09-27all: make .Vars, .Val, and .Vals panic if values is emptyShulhan
This is to prevent copying or executing command with value that are not defined or typo which make the result empty and may result in undefined behaviour. For example if we have "app_dir = /data/app" and command in the script that remove that directory recursively, sudo rm -r {{.Val "::app_dir}}/bin will result removing "/bin" entirely.
2023-09-26all: test local put without encrypted fileShulhan
2023-09-26all: add prefix "awwan." to the name of temporary directoryShulhan
Each time the new session is created in local or remote, it will create new temporary directory. Previously, the name of temporary directory is random 16 characters and numbers. To distinguish this directory with others, we add prefix "awwan." to the name.
2023-09-26all: move ssh and sftp client into separate structShulhan
The sshClient struct wrap the raw SSH connection and SFTP connection, and provide methods get, put, sudoGet, sudoPut, mkdir, and rmdirAll.
2023-09-26all: call loadEnvFromPaths inside newSessionShulhan
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.
2023-09-26all: move fields and methods related to encryption to struct cryptoContextShulhan
The cryptoContext contains the default hash, loaded privateKey, dummy terminal, base directory, and default label; all of those fields are required for encryption and decryption. The cryptoContext have three methods: encrypt, decrypt, and loadPrivateKey. By moving to separate struct the cryptoContext instance can be shared with Session.
2023-09-26all: make the magic word "#put" able to copy encrypted fileShulhan
When issuing "#put:" or "#put!" command in the script, if the input file is not exist it will check for the encrypted file, the one with ".vault" extension. If it exists, the encrypted file will be used as input for copy operation.
2023-09-23all: move the parseTemplate as method of Session generateFileInputShulhan
2023-09-22all: implement reading encrypted awwan environment ".awwan.env.vault"Shulhan
Upon executing "local" or "play" comman, awwan now read the encrypted environment file .awwan.env.vault. The encrypted environment file is generated using "awwan encrypt" command.
2023-09-20all: remove rand.SeedShulhan
The latest ascii.Random use "cryto/rand", so there is no need to call rand.Seed.
2023-09-04go.mod: update share moduleShulhan
The latest update on share module contains refactoring on lib/ssh.
2023-09-04all: fix #require does not get executed on the same start positionShulhan
2023-05-14all: update module share and ciigo to latest versionShulhan
This changes replace share package lib/io with lib/os, since the former has been deprecated.