brickpack-2022
Demo
Powered by Github Actions CI/CD (Heroku)
https://demo-1642622230.herokuapp.com/#/users
Frontent
Runner
Rendered sample code (Lua 5.1 - luajit)
Sample source code
Endpoints
-
GET /
- Frontend w/Editor - Lua 5.1 support (Under development)
Applets (runner) - Lua 5.1 Interpreter (modPHP-Like)
-
GET /api/runner/:applet_id?param1=value¶m2=value
- query_string -
POST /api/runner/:applet_id?param1=value¶m2=value
- query_string and Form URL encoded
API
Default tables:
-
request_form
(POST) -
request_query_string
(GET,POST) -
request_cookies
(GET,POST)
Functions:
-
echo
(Render HTML like PHP)
Sample code
function debug_api()
local html_header = [[
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
]]
local html_footer = [[
</body>
</html>
]]
echo(html_header)
if request_form
then
local table_header = [[
<h2>Logon - (request_form)</h2>
<table>
<thead>
<tr><th>Key</th><th>Value</th></tr>
</thead><tbody>
]]
echo(table_header)
for k,v in pairs(request_form) do
echo("<tr>")
local key_column = "<td>" .. k .. "</td>"
local value_column = "<td>" .. v .. "</td>"
echo(key_column)
echo(value_column)
echo("</tr>")
end
echo ("</tbody></table>")
end
if request_query_string
then
local table_header = [[
<h2>Logon - (request_query_string)</h2>
<table>
<thead>
<tr><th>Key</th><th>Value</th></tr>
</thead><tbody>
]]
echo(table_header)
for k,v in pairs(request_query_string ) do
echo("<tr>")
local key_column = "<td>" .. k .. "</td>"
local value_column = "<td>" .. v .. "</td>"
echo(key_column)
echo(value_column)
echo("</tr>")
end
echo ("</tbody></table>")
end
if request_cookies
then
local table_header = [[
<h2>Logon - (request_cookies)</h2>
<table>
<thead>
<tr><th>Key</th><th>Value</th></tr>
</thead><tbody>
]]
echo(table_header)
for k,v in pairs(request_cookies) do
echo("<tr>")
local key_column = "<td>" .. k .. "</td>"
local value_column = "<td>" .. v .. "</td>"
echo(key_column)
echo(value_column)
echo("</tr>")
end
echo ("</tbody></table>")
end
echo(html_footer)
end
function main()
debug_api()
end
main()
Sample code(rendered)
Applets
-
HEAD /api/applets
- Read (Count) -
GET /api/applets
- Read (All) -
GET /api/applets/:id
- Read (One) -
POST /api/applets
- Create (One) -
PATCH /api/applets/:id
- Update (One) -
DELETE /api/applets/:id
- Delete (One)
Users
-
HEAD /api/users
- Read (Count) -
GET /api/users
- Read (All) -
GET /api/users/:id
- Read (One) -
POST /api/users
- Create (One) -
PATCH /api/users/:id
- Update (One) -
DELETE /api/users/:id
- Delete (One)
Departments
-
HEAD /api/departments
- Read (Count) -
GET /api/departments
- Read (All) -
GET /api/departments/:id
- Read (One) -
POST /api/departments
- Create (One) -
PATCH /api/departments/:id
- Update (One) -
DELETE /api/departments/:id
- Delete (One)
Persmissions
-
HEAD /api/permissions
- Read (Count) -
GET /api/permissions
- Read (All) -
GET /api/permissions/:id
- Read (One) -
POST /api/permissions
- Create (One) -
PATCH /api/permissions/:id
- Update (One) -
DELETE /api/permissions/:id
- Delete (One)
Help
$ make
Makefile Help
======== ====
make - This message!
make help - This message!
make prep - Prepare project to open inside vscode
make release - Generate release artifact
make debug - Generate debug artifact
make tests - Compile and run tests
make audit - Check dependencies licenses and disclosured vulnerabilities
make clean - Clean compilation files and artifact folder: './dist'
If you don't know what to choose, type:
make release
CLI help
$ ./brickpack-2022 --help
BrickPack 0.1.0
USAGE:
brickpack-2022 [OPTIONS]
OPTIONS:
--auto-tls-for-hostname=<HOSTNAME>
Hostname for auto-generated TLS cert [env: AUTO_TLS_FOR_HOSTNAME=]
-e, --endpoints
Show endpoint names
--enable-tokio-console
Enable tokio-console [env: ENABLE_TOKIO_CONSOLE=]
-h, --help
Print help information
--ipv4-address=<IPV4_ADDRESS>
IPv4 address to listen [env: IPV4_ADDRESS=]
--ipv4-port=<IPV4_PORT>
Port number to listen [env: IPV4_PORT=]
--tls-cert-path=<CERT_PATH>
TLS certificate file [env: TLS_CERT_PATH=]
--tls-key-path=<KEY_PATH>
TLS private key file [env: TLS_KEY_PATH=]
-V, --version
Print version information
Getting started
Install dependencies:
# Ubuntu Linux
sudo apt-get install build-essential make musl-tools -y
Install Rust:
# Install Rust compiler
$ curl https://sh.rustup.rs -sSf | sh
.
.
.
# Clone repo
$ git clone --depth=1 --recursive https://gitlab.com/brickpack/brickpack
# Build project(Release) and Run
$ cd ./brickpack
$ make release
$ cd ./dist/release
$ ./brickpack-2022
Lean artifact (< 12 MB)
The whole artifact is built with static compiling using musl target.
$ ls -lh
total 11M
-rwxrwxr-x 1 user user 11M jan 15 00:34 brickpack-2022
-rw-r--r-- 1 user user 48K jan 15 00:24 database.sqlite3
$ ldd ./dist/release/brickpack-2022
statically linked
Startup message
$ ./brickpack-2022
2022-01-07T20:49:32.820952Z INFO web_server: Starting App [Brickpack v0.1.0]:
2022-01-07T20:49:32.820969Z INFO web_server: Tracing started successfully
2022-01-07T20:49:32.820977Z INFO web_server: RUST_LOG was not set. Setting default value: RUST_LOG=info
2022-01-07T20:49:32.820988Z INFO web_server: File `.env` not found!
2022-01-07T20:49:32.821499Z INFO application_models::database: Bootstraping database...
2022-01-07T20:49:32.821675Z INFO application_models::database: Database bootstrapped!
2022-01-07T20:49:32.821748Z INFO web_server: Webserver started!
2022-01-07T20:49:32.821759Z INFO web_server: Listening on http://127.0.0.1:8000
Show endpoints
$ ./tide-crud-users -e
Internal Endpoints:
/ - index_page
/maintenance - maintenance
/auth - check_auth
Endpoints:
# TODO
Running with all options
RUST_LOG=trace ./brickpack-2022 --ipv4-address=127.0.0.1 --ipv4-port=8000 --enable-tokio-console --tls-cert-path ./some-test-ca/ecdsa/end.cert --tls-key-path ./some-test-ca/ecdsa/end.key