Skip to content

Schema validation layer and metadata management tool built for mongodb

License

Notifications You must be signed in to change notification settings

PierreKieffer/mgate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mgate


                               
 _____ _____ _____ _____ _____ 
|     |   __|  _  |_   _|   __|
| | | |  |  |     | | | |   __|
|_|_|_|_____|__|__| |_| |_____|
                               

mgate is a schema validation layer for mongodb, which provides :

  • Metadata management rest interface
  • Schema validation for insert and update/upsert queries
  • Production deployment workflow on kubernetes

Run

docker pull pierrekieffer/mgate

configuration

You need to edit the config.yml file with your own settings :

You must specify the names of the schemas assigned to each collection, and the database names of each collection

associatedCollectionSchema : '{"collection1" : "schema_name1","collection2":"schema_name2"}'
associatedCollectionDatabase : '{"collection1":"database_name","collection2":"database_name"}'

Start mGate

docker run --network host -v /.../mgate/docker/config/:/usr/local/config/ pierrekieffer/mgate

Usage

Upload or update a schema

Your schema name must respect the following pattern : name_version.json (user_v2.json)

Your schema must respect json standard rules (http://json-schema.org/draft-04/schema#)

To easily generate json schemas, you can refer to https://github.com/coursera/autoschema

To upload a new schema or update an existing schema :

curl -X POST -d @schema-name_v1.json http://localhost:8080/secured/schema-registry/admin/schema-update --header "Content-Type:application/json" --header "Authorization: Bearer token"

Routes

  • Main
http://<HOST>:8080/secured/schema-registry
  • Test auth
/test-login
  • INSERT
/db-driver/insert

Payload :

{
    "collection": "users",
    "document": $jsonDocument
}

jsonDocument = { json associated to collection data}

Example :

{
    "collection": "users",
    "document": {
        "email": "pikachu@mail.com",
        "firstName": "Pika",
        "lastName": "Chu",
        "communications": {
            "allowNewsletters": False
        }
    }
}
curl -X POST -d @insert-data.json http://localhost:8080/secured/schema-registry/db-driver/insert --header "Content-Type:application/json" --header "Authorization: Bearer token"
  • UPDATE
/db-driver/update

Payload :

{
    "collection":  String,  	    
    "_id" : String,    
    "document": $jsonDocument
}

jsonDocument = { json data to update}

Example :

{
    "collection": "users",
    “_id” : “592be28bf322cc152069e957”
    "document": {
        "email": "pikachu-newmail@mail.com",
        "communications": {
            "allowNewsletters": True, 
            "allowSMS": True
            }
         }
}
curl -X POST -d @update-data.json http://localhost:8080/secured/schema-registry/db-driver/update --header "Content-Type:application/json" --header "Authorization: Bearer token"
  • UPSERT
/db-driver/upsert

Payload :

{
    "collection":  String,
    "_id" : String,
    "document": $jsonDocument
}

jsonDocument = { json data to update}

Example :

{
    "collection": "users",
    “_id” : “592be28bf322cc152069e957”
    "document": {
        "email": "pikachu-newmail@mail.com",
        "communications": {
            "allowNewsletters": True,
            "allowSMS": True
            }
         }
}
  • PUSH
/db-driver/push

Payload :

{
    "collection":  String,
    "_id" : String,
    "document": $jsonDocument
}

It is possible to pass MongoDB operations inside the document :

Example :

"document" : {"array" : {"$each" : ["foo","bar"] }}

Build and deploy

Package application

To package the application you need sbt 0.13.15

sbt assembly

Docker

docker build -t mgate . 

Build and deploy on Kubernetes

Prerequisities

You will need to install :

  • gcloud
  • kubectl

Deploying to kubernetes

Application

Build docker image and push it to your favorite registry

Add your own parameters to the config.yml file

Generate the config-map :

./k8s/generate-configMap.sh PROJECT_ID CLUSTER_ID config.yml

Deploy :

./deploy.sh PROJECT_ID CLUSTER_ID

About

Schema validation layer and metadata management tool built for mongodb

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published