motiv-labs / janus

An API Gateway written in Go
https://hellofresh.gitbooks.io/janus
MIT License
2.77k stars 319 forks source link

Add Cassandra Support for Repo API Definitions #463

Open jtesser opened 3 years ago

jtesser commented 3 years ago

[Short description of problem here] Add support to store API Spec in Cassandra. This is similar to the Mongo approach.

The MongoDB Repo is implemented here. https://github.com/motiv-labs/janus/blob/master/pkg/api/mongodb_repository.go

Here you can see where the Repository is setup https://github.com/motiv-labs/janus/blob/9998651bbc8dad96cdcdb34ece18b3c214739f3c/pkg/api/repository.go#L45

Need to load a configured SQL file on first time start. We can do this like we do for other microservices here at Motiv. The file will have to be placed inside the Container. The default will be the basic schema but one could be added that has default definitions

** Things to be aware of Need to test to make sure a cluster of Januses will work. Obviously all pointed at the same Cassandra Ring. Make sure watch works and you can add new API Definitions get propagated to all connected Janus containers Config of Cassandra and Janus should be able to be controlled via Environment Variables passed into the Docker container. Ultimatly we might need to create a card to update this for Mongo also.

  [database]
    dsn = "cassandra:......:user..."

** More code to be aware of Definitions are stored here for APIs https://github.com/motiv-labs/janus/blob/9998651bbc8dad96cdcdb34ece18b3c214739f3c/pkg/api/api.go#L19 https://github.com/motiv-labs/janus/blob/9998651bbc8dad96cdcdb34ece18b3c214739f3c/pkg/proxy/definition.go#L18

The file_repo impl https://github.com/motiv-labs/janus/blob/9998651bbc8dad96cdcdb34ece18b3c214739f3c/pkg/api/file_repository.go#L11

The in_memory repo https://github.com/motiv-labs/janus/blob/master/pkg/api/in_memory_repository.go#L28

Where the watcher is hooked up. This should be the thing that allows everything to reload. https://github.com/motiv-labs/janus/blob/9998651bbc8dad96cdcdb34ece18b3c214739f3c/pkg/server/server.go#L216

How mongo is unmarshalling the JSON. In mongo it is simply key/value. So all the structs are a big JSON Object https://github.com/motiv-labs/janus/blob/9998651bbc8dad96cdcdb34ece18b3c214739f3c/pkg/plugin/plugin.go#L146 https://github.com/motiv-labs/janus/blob/9998651bbc8dad96cdcdb34ece18b3c214739f3c/pkg/plugin/plugin.go#L146