Skip to content

Commit ec3470c

Browse files
authored
Merge pull request #2 from ProcessMaker/feature/1
Add the pm4-sdk-lua package and client to the lua executor
2 parents 18915f8 + 641f569 commit ec3470c

11 files changed

Lines changed: 112 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sdk-repo

Dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
# Bring in from base debian docker image
22
FROM debian:9.5
33

4+
# Update packages, then install lua
5+
RUN apt-get update -qq
6+
RUN apt-get install -y lua5.3 luarocks liblua5.3-dev build-essential libssl-dev m4
7+
48
# Copy over our LUA libraries/runtime
59
COPY ./src /opt/executor
610

11+
# Build the sdk and save it in luarocks default folder
12+
WORKDIR /opt/executor/pm4-sdk-lua
13+
RUN luarocks make --local
14+
715
# Set working directory to our /opt/executor location
816
WORKDIR /opt/executor
917

1018
LABEL maintainer="taylor@processmaker.com"
1119

12-
# Update packages, then install lua
13-
RUN apt-get update -qq && apt-get install -y lua5.3 luarocks liblua5.3-dev
14-
15-
RUN luarocks install dkjson
16-
20+
RUN luarocks install dkjson

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,30 @@ return data
5252
{"message":"dlroW olleH"}
5353
```
5454

55+
## Using the PM4 SKD
56+
57+
The executor comes pre-configured with the ProcessMaker 4 SDK ready to use.
58+
59+
Get an instance by calling `client.make('name')`.
60+
61+
Here is an example of fetching all pm4 users:
62+
63+
```lua
64+
users_api = client.make('users_api')
65+
66+
filter=''
67+
order_by='id'
68+
order_direction='asc'
69+
per_page='10'
70+
include=''
71+
local users, ret2, ret3 = users_api:get_users(filter, order_by, order_direction, per_page, include)
72+
73+
return {users=users}
74+
```
75+
76+
See ProcessMaker API documentation for more info at /api/documentation
77+
on your ProcessMaker 4 instance
78+
5579
## Command Line Usage
5680
```bash
5781
$ docker run -v <path to local data.json>:/opt/executor/data.json \

build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set -e
2+
set -x
3+
4+
BRANCH=${BRANCH:=master}
5+
TAG=${TAG:=dev-${BRANCH//[\/]/-}}
6+
7+
pushd src
8+
if [[ ! -d "pm4-sdk-lua" ]]; then
9+
git clone --branch ${BRANCH} --depth 1 https://github.com/ProcessMaker/pm4-sdk-lua.git
10+
fi
11+
popd
12+
13+
docker build -t processmaker/pm4-docker-executor-lua:${TAG} .
14+
rm -rf src/pm4-sdk-lua
15+
16+
# Push to dockerhub here

src/bootstrap.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "luarocks.loader"
2+
13
-- Create our global variables
24
data = nil
35
config = nil
@@ -28,6 +30,9 @@ end
2830
-- Reimport our dkjson, but this can now be in local scope
2931
local json = require "dkjson"
3032

33+
-- Add a client wrapper to get the pre-configured api and model instances from the sdk
34+
client = require("client")
35+
3136
-- Do our script and get the response
3237
response = dofile("/opt/executor/script.lua")
3338

src/client.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require "luarocks.loader"
2+
3+
-- This helper allows the script user to get a pre-configured client instance
4+
-- For example, users_api = client.make('users_api')
5+
local function make(name)
6+
local api_class = require("pmsdk.api." .. name)
7+
8+
local host = os.getenv("API_HOST")
9+
https, host, path = host:match("^(https?)://(.-)/(.*)$")
10+
11+
local api_instance = api_class.new(host, '/' .. path, {https})
12+
api_instance.access_token = os.getenv('API_TOKEN')
13+
14+
return api_instance
15+
end
16+
17+
local function model(name)
18+
return require("pmsdk.model." .. name)
19+
end
20+
21+
return {
22+
make = make,
23+
model = model
24+
}

test.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set -e
2+
set -x
3+
4+
API_TOKEN=bearer-token-here
5+
API_HOST=http://bpm4.local.processmaker.com/api/1.0
6+
7+
EXECUTOR_IMAGE="processmaker/pm4-docker-executor-lua:dev-master"
8+
EXECUTOR_DIR=${PWD}/tests/sdk
9+
10+
docker run --rm \
11+
-v $EXECUTOR_DIR/data.json:/opt/executor/data.json \
12+
-v $EXECUTOR_DIR/config.json:/opt/executor/config.json \
13+
-v $EXECUTOR_DIR/script.lua:/opt/executor/script.lua \
14+
-v $EXECUTOR_DIR/output.json:/opt/executor/output.json \
15+
-e "API_TOKEN=$API_TOKEN" \
16+
-e "API_HOST=$API_HOST" \
17+
$EXECUTOR_IMAGE lua5.3 bootstrap.lua
18+
19+
cat $EXECUTOR_DIR/output.json
20+
echo '' > $EXECUTOR_DIR/output.json

tests/sdk/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

tests/sdk/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

tests/sdk/output.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)