Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pierrekieffer/mgate
Schema validation layer and metadata management tool built for mongodb
https://github.com/pierrekieffer/mgate
akka akka-http json-schema mongodb schema-registry schema-validation
Last synced: about 2 months ago
JSON representation
Schema validation layer and metadata management tool built for mongodb
- Host: GitHub
- URL: https://github.com/pierrekieffer/mgate
- Owner: PierreKieffer
- License: apache-2.0
- Created: 2020-05-01T17:28:25.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-18T07:14:04.000Z (over 4 years ago)
- Last Synced: 2023-03-07T01:31:41.741Z (almost 2 years ago)
- Topics: akka, akka-http, json-schema, mongodb, schema-registry, schema-validation
- Language: Scala
- Homepage:
- Size: 198 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](#run)
* [configuration](#configuration)
* [Start mGate](#start-mgate)
* [Usage](#usage)
* [Upload or update a schema](#upload-or-update-a-schema)
* [Routes](#routes)
* [Build and deploy](#build-and-deploy)
* [Package application](#package-application)
* [Docker](#docker)
* [Build and deploy on Kubernetes](#build-and-deploy-on-kubernetes)
* [Prerequisities](#prerequisities)
* [Deploying to kubernetes](#deploying-to-kubernetes)
* [Application](#application)## Run
```bash
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
```yaml
associatedCollectionSchema : '{"collection1" : "schema_name1","collection2":"schema_name2"}'
associatedCollectionDatabase : '{"collection1":"database_name","collection2":"database_name"}'
```### Start mGate
```bash
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 :
```bash
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://: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": "[email protected]",
"firstName": "Pika",
"lastName": "Chu",
"communications": {
"allowNewsletters": False
}
}
}
```
```bash
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": "[email protected]",
"communications": {
"allowNewsletters": True,
"allowSMS": True
}
}
}
``````bash
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": "[email protected]",
"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```bash
sbt assembly
```### Docker
```bash
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 registryAdd your own parameters to the config.yml file
Generate the config-map :
```bash
./k8s/generate-configMap.sh PROJECT_ID CLUSTER_ID config.yml
```Deploy :
```bash
./deploy.sh PROJECT_ID CLUSTER_ID
```