PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/README.md

https://bitbucket.org/aksenchyk/200loc
Markdown | 65 lines | 47 code | 18 blank | 0 comment | 0 complexity | 9997bb434671ecc66648637bfed80f34 MD5 | raw file
  1. ## Oneopp microgateway
  2. Api gateway stands in front of all infrastructure and serves as bridge between external network and inner perimeter services. API Gateway
  3. encapsulates the internal structure of the application. Put services behind gateway layer and add functionality by means of plugins. Use dashboard for managing plugins and request middleware. Plugins bear main responsibility for request authentication/authorization, caching, logging, rate limiting and any api extentions.
  4. ## Requirements
  5. - Node.js > 8.*
  6. - Docker > 1.12
  7. - MongoDB > 3.*
  8. ## Basics
  9. Api gateway works in conjunction with Management dashboard for reducing downtime in development and shipping api to clients. Api routing, circuit breakers and healthchecks are manageble via dashboard, making the process for updating the API Gateway as lightweight as possible. Dashboard provides simple tools for pre-shipped testing of api endpoints and route middleware management.
  10. ### Plugins
  11. Plugins allows you to transmogrify visitor request and server response data. Depending on the Plugin, it could add data to the backend request headers, change body content, or send custom log or debug information at the end of each request. To your application, this looks like end-to-end HTTPS, Geo IP headers, Google Authentication, Session Aware Routing and more.
  12. #### Authentication plugin
  13. The API Gateway might first need to validate the request by calling an authentication service (if route security policy require it), before routing the request to a backend service. E.g., to fetch information about the jobs in a recruiterss list, the API Gateway must first retrieve the recruiterss profile containing that information, and then proxy request to appropriate service for retrieving the data. That is what authentication plugin is used for. By settting this plugin on entry point one can restrict access to a service api before proxying external request to it.
  14. * **Authentication server** is separated and works independendly within or out of infrastructure. Gateway provides healthcheching and, if the authentiucation service is offline will fetch 401 on every secured route. This service as dependency is injected in Authentication plugin and allow to use it's interface for checking permissions.
  15. * Authentication policy is archived by means of RBAC model. User have a role, role - permissions. To have access to the api user's role must have appropriate permissions. There are three main roles in ONEOPP project - `candidate`, `recruiter`, `company`. Roles permissions are manageble.
  16. * Authentication plugin provides access for any **authenticated** user if grant param is set to `$authenticated`, and to **everyone**, if set to `$anonymous`.
  17. * Authentication plugin may or may not use **Redis server** for session storage. If redis is not available, the **Authentication server** will be called on every request, that require permissions. The point of using redis as session cache touching the DB on every request that should be authenticated.
  18. ---
  19. #### Amazon simple notification plugin
  20. A microservicesbased application is a distributed system and must use an interprocess communication mechanism. There are two styles of interprocess communication. One option is to use an asynchronous, messagingbased mechanism. In ONEOPP project Amazon SnS is used for that purpose. The other style of interprocess communication is a synchronous mechanism such as HTTP. Amazon SnS client plugin works as a bridge and provides methods for validation of sns request and proxy it to inner-perimeter microservice.
  21. ---
  22. #### Simple tracer plugin
  23. Any distributed system needs central logging. But distributing adds challanges to this process. To monitor how query is managed within perimeter Simple tracer plugin is used. It adds corellation token to the request header for watching and passing througth microservices to be consumed by the central logging software (Logz.io).
  24. ## Handling Partial Failures and Services Conceipt
  25. Services are like stateholders of remote processes. For instance, Redis as remote process is wrapped to internal client, wich holds it's state, can gain metrics and try to recover it's state if any connection error. That conceipt and plugins-based upproach (plugin can inject service as dependency) any type of system state can be handled during api call and fetched appropriate, specific to that scenario respond without downtime. For masking services fault additional plugins can be implemented for responding with default data if underlying service healthcheck fails.
  26. ## Security
  27. The Api gateway provides inter-perimeter security by means of basic authentication passed in custom headers. Every service working within perimeter should handle it for giving access to it's api.
  28. ## Basic Usage
  29. ```bash
  30. # clone the repo
  31. $ git clone https://aksenchyk@bitbucket.org/aksenchyk/oneopp-gateway.git
  32. $ cd oneopp-gateway
  33. # install
  34. $ yarn install
  35. # run development/production
  36. $ yarn compose:deps #runs redis, auth service and admin dashboard in local network
  37. $ yarn dev # nodemon
  38. # testing
  39. $ yarn test
  40. ```
  41. ## Run within Docker container:
  42. ```bash
  43. # build image
  44. $ yarn dockerize
  45. # run via docker-compose with all dependencies
  46. $ yarn compose:dev
  47. ```