Rum - The first think you think of when your users want to run custom code on your system.
Rumscript is still a very young project, while the container is fully operational, you might face some bugs. Contact [email protected] if you have any questions or to get your own key.
Feel free to use the key below under https://runner-fbcdweakcq-uc.a.run.app/run to run your tests:
export RUM_SCRIPT_MANAGED_KEY=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6Im1lQGJpbGxjb3VudHJ5LnRlY2giLCJUeXBlIjoibWFuYWdlZCIsImV4cCI6MTY1Mjc3MzY4MiwianRpIjoiNjBhMjFmYjI0ODNhZjEzM2ZmZDVjOTc3IiwiaWF0IjoxNjIxMjM3NjgyLCJpc3MiOiJCaWxsY291bnRyeSIsIm5iZiI6MTYyMTIzNzY4Mn0.vPcKG9iaSk9hw9VtE4UZ4Z3NxrkJ_Nkr5DQRfPbwKMdTCRuk8Fp8WaLaeYV0P4-a03T-3QR1TSdQ1awcDO2t9w
The following example demonstrates running on a managed server:
curl --location --request POST 'https://runner-fbcdweakcq-uc.a.run.app/run' \
--header "Authorization: Bearer $RUM_SCRIPT_MANAGED_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"code": "const resp = await fetch('\''https://api.github.com/users/billcountry'\'', {method:'\''GET'\''})\nconst body = await resp.json()\nconsole.log(encodeURI('\''Billcountry Mwaniki'\''))\nreturn body"
}'
This container provides the javascript runner which you can run on your own premises or cloud.
You'll need to provide your private key in the environment as RUM_SCRIPT_PRIVATE_KEY.
Run example:
docker run --name js-runner --env RUM_SCRIPT_PRIVATE_KEY={your-private-key} --env PORT=8080 --network host -it rumscript/js-runner:latest
The runner provides a REST api for running your code under:
[POST] /runSample request:
curl --location --request POST 'http://localhost:8080/run' \
--header "Authorization: Bearer $RUM_SCRIPT_PUBLIC_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"code": "console.log('\''this is a test'\'')\n return age + 5",
"globals": "{\"age\": 22}",
"timeout": 10
}'
The request expects the following headers
Authorization - Authorization header with your public key as the token. i.e.The request accepts a JSON object with the following attributes:
code(string:required) - The string of the code to run.
e.g.
console.log('this is a test')
return age + 5
globals(string:optional) - A JSON encoded string of values you'd like to be available globally to the user.
e.g. "{\"age\": 22}"pre_launch(string:optional) - This is javascript code that can be run before running the actual code.
It can be for example be useful to provide helper functions to your users.timeout(int:optional) - This is the maximum amount of time your user's code can run.
The response is a json object with the following interface
interface Response {
start: number
end: number
status: "DONE" | "TIMED_OUT" | "INTERNAL_ERROR" | "JS_ERROR"
result: {
// The error that occured if any. Otherwise an empty string
error: string
// If the user returned a value from their code.
// The value will be json encoded and provided here
data: any
}
// If the user called console.log and other logging functions
// the logs will be available here
logs: LogEntry[]
}
interface LogEntry {
time: number
level string
message string
}
Fetch is implemented to Match the browser fetch as much as possible. The following interfaces apply.
interface Response {
status: number
status_text: string
headers: [header: string]: string
text: ()=>Promise<string> // Resolves to the response body as text
json: ()=>Promise<object> // Resolves the response as a JSON object.
}
interface Request {
body?: string | object // If an object is provided, it's going to be encoded to form-encoded-url-content
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" // default to GET
headers?: [header: string]: string
}
function fetch(url: string, request?: Request): Promise<Response>
Example:
const resp = await fetch('https://api.github.com/users/billcountry', {method:'GET'})
const body = await resp.json()
return body
Content type
Image
Digest
Size
85.8 MB
Last updated
over 5 years ago
docker pull rumscript/js-runner