Firex
Firex is a real time database backend service designed for fast mobile and web apps development.
On top of an API to C.R.U.D json documents from a MySQL database firex uses a CEL based security rules layer to manage access to documents.
Install and run
go get github.com/omecodes/firex
requirements
Firex only a need a MySQL database installed to run.
Run
Executing just ./firex
command will start a server that listens to the port 80 and assumes you have a MySQL database running on 127.0.0.1:3306
accessible with firex:firex
credentials.
To run it using non default port and database, excute it with --p
and --dsn
arguments as follow:
./firex --p=8080 --dsn=ome:code@(loclahost:3306)/firex?charset=utf8
Setting up security rules
Writing security rule consists of using Common Expression Language to create boolean expressions that are executed at runtime against requests context.
- Request context
The request context is a set of objects that hold information about:
type auth {
uid string //user id
email string
validated bool
scope string
group string
}
type data {
id string //user id
col string // collection
creator string
}
- some global information like the request time
// permissions
type perm {
read bool
write bool
delete bool
rules bool
graft bool
}
// acl laods permissions of user
// identified by 'uid' on data with 'did' as id
func acl (uid string, did string) perm
- Write and apply rules
Allowing everybody to read document and allowing only creator to edit documents will give:
read: true
write: auth.validated && auth.uid == data.id
and to apply these rules on a server that runs at localhost send an http post request as follow:
curl --location --request POST 'http://127.0.0.1/.settings/security/rules/access/data' \
--header 'Authorization: Basic YWRtaW46YWRtaW5wYXNzd29yZA==' \
--header 'Content-Type: application/json' \
--data-raw '{
"read": "true",
"write": "auth.validated && auth.uid == data.id"
}'
API with swagger
Go to Swagger online editor and paste the content of the firex API specification to learn more about the Firex or generate a client code of the language you are working with.