Rust scaffold system with Lua embedded applets.

Overview

brickpack-2022

Build Status MSRV

Demo

Powered by Github Actions CI/CD (Heroku)

https://demo-1642622230.herokuapp.com/#/users

Frontent

Frontend screenshot

Runner

Rendered sample code (Lua 5.1 - luajit)

Sample code rendered screenshot

Sample source code

Sample code screenshot

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&param2=value - query_string
  • POST /api/runner/:applet_id?param1=value&param2=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)

Sample code screenshot

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
You might also like...
A super-lightweight Lua microservice (toy) framework.

Hive A super-lightweight microservice (toy) framework written in Rust. It uses Lua as interface to provide simple, fun developing experience and fast

🐱‍👤 Cross-language static library for accessing the Lua state in Garry's Mod server plugins

gmserverplugin This is a utility library for making Server Plugins that access the Lua state in Garry's Mod. Currently, accessing the Lua state from a

This tool converts Lua code to TS automatically, including the conversion of common standards to their TS equivalents.

lua-to-ts This tool converts Lua code to TS automatically, including the conversion of common standards to their TS equivalents. Code that fails to be

Another cursed Garry's Mod module. This time, it adds the C preprocessor to Lua scripts

gm_cpreprocessor Another cursed Garry's Mod module. This time, it adds the C preprocessor to Lua scripts. It works by detouring RunStringEx and overri

Node.js bindings to Lua

Node.js bindings to Lua

libc - Raw FFI bindings to platforms' system libraries

libc provides all of the definitions necessary to easily interoperate with C code (or "C-like" code) on each of the platforms that Rust supports. This includes type definitions (e.g. c_int), constants (e.g. EINVAL) as well as function headers (e.g. malloc).

Slitter is a C- and Rust-callable slab allocator implemented primarily in Rust, with some C for performance or to avoid unstable Rust features.

Slitter is a less footgunny slab allocator Slitter is a classically structured thread-caching slab allocator that's meant to help write reliable long-

A Rust crate for automatically generating C header files from Rust source file.

Please be aware that this crate is no longer actively maintained, please look into the much more feature rich cbindgen instead. rusty-cheddar rusty-ch

Rust-ffi-guide - A guide for doing FFI using Rust

Using unsafe for Fun and Profit A guide to traversing the FFI boundary between Rust and other languages. A rendered version is available here. This gu

Releases(v0.6.3)
Owner
null
Lua 5.3 bindings for Rust

rust-lua53 Aims to be complete Rust bindings for Lua 5.3 and beyond. Currently, master is tracking Lua 5.3.3. Requires a Unix-like environment. On Win

J.C. Moyer 150 Dec 14, 2022
Safe Rust bindings to Lua 5.1

rust-lua Copyright 2014 Lily Ballard Description This is a set of Rust bindings to Lua 5.1. The goal is to provide a (relatively) safe interface to Lu

Lily Ballard 124 Jan 5, 2023
Zero-cost high-level lua 5.3 wrapper for Rust

td_rlua This library is a high-level binding for Lua 5.3. You don't have access to the Lua stack, all you can do is read/write variables (including ca

null 47 May 4, 2022
Rust library to interface with Lua

hlua This library is a high-level binding for Lua 5.2. You don't have access to the Lua stack, all you can do is read/write variables (including callb

Pierre Krieger 488 Dec 26, 2022
Pure Rust Lua implementation

purua Pure Rust Lua implementation Usage $ bat lua_examples/defun.lua ───────┬────────────────────────────────────────── │ File: lua_examples/d

Kondo Uchio 35 Dec 28, 2021
A script language like Python or Lua written in Rust, with exactly the same syntax as Go's.

A script language like Python or Lua written in Rust, with exactly the same syntax as Go's.

null 1.4k Jan 1, 2023
A parser, compiler, and virtual machine evaluator for a minimal subset of Lua; written from scratch in Rust.

lust: Lua in Rust This project implements a parser, compiler, and virtual machine evaluator for a minimal subset of Lua. It is written from scratch in

Phil Eaton 146 Dec 16, 2022
⚡ Fast Web Security Scanner written in Rust based on Lua Scripts 🌖 🦀

⚡ Fast Web Security Scanner written in Rust based on Lua Scripts ?? ??

Rusty Sec 14 Nov 28, 2022
📦 Pack hundreds of Garry's Mod Lua files into just a handful

?? gluapack gluapack is a program that can pack hundreds of Garry's Mod Lua files into just a handful. Features Quick, easy and portable - perfect for

null 11 Aug 10, 2021
A memory safe Lua interpreter

Hematita Da Lua Hematita Da Lua is an interpreter for the scripting language Lua, written entirely in 100% safe Rust. Hematita is the portugese word f

Daniel 149 Dec 29, 2022