aboutsummaryrefslogtreecommitdiff
path: root/http_server.go
AgeCommit message (Collapse)Author
2026-02-12all: change Serve parameters to struct `ServeOptions`Shulhan
In case we needs to add another parameter, which will do later, the argument will be too long. Using parameters is acceptable only for 2 to 3 arguments.
2026-02-06all: improve the Server-Sent Events (SSE) outputShulhan
In the ExecResponse, store the event in the Output instead of message data, so the server can iterate the Output directly and pass it to WriteEvent directly. The event ID now start at 1 with type "begin". This is to minimize confusion when comparing empty Last-Event-ID from client, which is equal to 0.
2026-02-03all: fix data race in tests and [httpServer.ExecuteTail]Shulhan
In the test for AwwanLocal, use buffer with lock, so each write and read is safe. In the httpServer, the test found data race during ExecuteTail when accessing [ExecResponse.EndAt]. We fix it by locking the resource during call to end() and when accessing the EndAt field.
2026-02-03cmd/awwan: implement socket based activation on serve commandShulhan
The "awwan serve" command now can run based on socket activation under systemd.
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: delete the execution response and context cancellation on finishedShulhan
Once the ExecResponse EndAt is not empty or event queue has been closed, clear the map that store the execution response and context cancellation to minimize resources usage.
2023-12-22all: implement HTTP API to stop local or play executionShulhan
The HTTP API for stopping execution have the following signature, DELETE /awwan/api/execute?id=<string> If the ID is exist, the execution will be cancelled and return HTTP status 200 with the following body, Content-Type: application/json { "code": 200, } Otherwise it will return HTTP status 404 with error message. References: 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-14all: fix memfs excludes regexShulhan
Previously, the regex does not contains "^" and "$" which makes file like "multi-user.target.wants" considered as ".tar" file and being excluded.
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-09all: reduce the response on HTTP endpoint on GET fsShulhan
Previously, the HTTP endpoint for "GET /awwan/api/fs" return the content of files when the requested node is a directory. This is cause unnecessary load because when requesting directory we only need list of file names not the content. This changes reduce the response by returning only list of node child without its content, which require update on share module on [Node.JSON].
2023-12-01all: handle reconnecting when streaming executionShulhan
In "/awwan/api/execute/tail" SSE endpoint, in order for client to be able to reconnect and start streaming from the last know output, we need to send the ID for each message that we send. The ID is the index of Output in slice. If client does not send Last-Event-ID, we send all Output from beginning, otherwise, we send only message start from index in Last-Event-ID.
2023-12-01all: implement HTTP API to fetch execution output by IDShulhan
The new API is "GET /awwan/api/execute/tail" that implement Server-sent events, not a normal GET request. Its accept the query parameter "id" with value is the execution ID from "/awwan/api/execute". Once called with valid ID, it will streaming the command output to client. By using this new API, the WUI can receive the output of command immediately without waiting for all commands to be completed. Implements: https://todo.sr.ht/~shulhan/awwan/5 Signed-off-by: Shulhan <ms@kilabit.info>
2023-12-01all: refactoring HTTP endpoint for ExecuteShulhan
Previously, the Execute endpoint wait for command execution to finish. In case the command takes longer than proxy or server write timeout, it will return with an timeout error to client. In this changes, we generate an execution ID for each request and return it immediately. The next commit will implement HTTP endpoint to fetch the latest status and/or output by execution ID. References: https://todo.sr.ht/~shulhan/awwan/5
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-20all: do not changes the Script path in the response of HTTP ExecuteShulhan
Previously, the ExecRequest from HTTP Execute endpoint changes the Script value to the absolute script path in the system. This changes fix this issue to minimize inconsistency between request and response.
2023-11-19all: fix excludes on HTTP server related to .gitShulhan
The HTTP server should excludes ".git" directory only, not the other files, like .gitignore or .gitconfig.
2023-11-19all: return 403 Forbidden when requesting awwan.key and awwan.passShulhan
When user run "awwan serve", using web-user interface, any request to fetch the content of "awwan.key" and "awwan.pass" should not allowed for security reason, in case user want to serve awwan with others.
2023-11-16all: refactoring, rename HttpResponse to ExecResponseShulhan
2023-11-16all: refactoring, rename Request to ExecRequestShulhan
2023-11-16all: implement HTTP API to decrypt fileShulhan
Similar to the CLI, the HTTP API accept the path of vault file and return the path to decrypted file.
2023-11-15_wui: implement EncryptShulhan
In the right side of Save button we now have a button Encrypt that allow user to Encrypt openend file. This require the workspace has been setup with private key (.ssh/awwan.key) and pass file (.ssh/awwan.pass).
2023-11-15all: implement HTTP API to encrypt fileShulhan
Similar to the CLI, the HTTP API accept the path of file and return the path to encrypted file.
2023-11-09all: on file save, make sure file end with line-feedShulhan
On some application, like haproxy configuration, line-feed (LF or "\n") are required, otherwise the application would not start.
2023-11-09cmd/awwan: add option "-address" to command serveShulhan
The "-address" option allow defining the HTTP server address to serve the web-user interface.
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-30all: return the error as reponse in HTTP API executeShulhan
Previously, when the command execution failed, we check the error and return it as HTTP status code 500. In this way, user cannot view the log and actual error. In this changes, if the command failed, we store the error in separate field "Error" and return to the caller with HTTP status code 200.
2023-10-29all: rename directory "_www" to "_wui"Shulhan
Since we now have website, the directory name "_www" become misleading. The actual website files is located under "_www/doc", the "_www" directory is for web-user interface which includes documentation that has the same content as our websites.
2023-10-29all: remove the node when requested from HTTP API /awwan/api/fsShulhan
Previously, the HTTP API for deleting node only remove the file but not the node in the memfs. This changes remove the child node from memfs, so the next refresh on directory will not contains the removed file.
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-09-28all: move field bufout and buferr out of httpServer structShulhan
Those fields are used on each HTTP request to /awwan/api/execute, which make them not safe if two or more requests processed at the same time.
2023-09-28all: create struct to handle HTTP serverShulhan
All fields that use to serve HTTP API now moved inside one struct, including memfsBase, bufout, and buferr.
2023-09-28all: split type fsRequest to its separate fileShulhan
2023-09-28all: rename http_api.go to http_server.goShulhan
We will move all fields related to HTTP server into one struct later.