karannaoh's Blog

Week #7 | Guillotina PubSub

Published: 07/15/2019

Commit :- 530f9c7e08151cf499d156c1fc756a0239bace5c

Worked on guillotina_pubsub which is a guillotina addon to subscribe to the content change via a websocket endpoint.


Created a subscriber to listen to content change event and publish it on redis pubsub guillotina

This Week:-  

Created websocket endpoint to @content-changes which a user can subscribe to in order to get the the changes from server about the content changed

View Blog Post

Week #6 | Guillotina PubSub

Published: 07/15/2019

Issue #553

A consumer of the API needs to be able to subscribe to changes to a specific content object in Guillotina.

This week:-

Repository:- guillotina_pubsub

Created a new Addon for Guillotina which subscribe to changes made to any object and publish on a websocket service.

IObjectModifiedEvent is the event triggered everytime any object is modified, using this event details of changed object are publish on a channel of redis pubsub.

@content-changes is a websocket service which subscribe to all the changes made on the channel of redis pubsub and send to client.

Next week:-

Adding test cases for this Addon and necessary refractor to push the code to a new repository of guillotinaweb  

View Blog Post

Week #5 | Decorator for schema Validation

Published: 07/01/2019

This Week:

Issue: #507 Provide decorator for validating json schema request payloads. 

Last week: added jsonschema validation to all the endpoints.

example- PR: #517  

validator = get_schema_validator('Type_Of_schema')
   data = await request.json()
   behavior = data.get('behavior', None)
   return await delete_behavior(context, behavior)
except jsonschema.exceptions.ValidationError as e:
 raise HTTPPreconditionFailed(content={
      'reason': 'json schema validation error',
      'message': e.message,
      'validator': e.validator,
      'validator_value': e.validator_value,
      'path': [i for i in e.path],
      'schema_path': [i for i in e.schema_path],
      "schema": app_settings['json_schema_definitions']['Behavior']

problem in this:- This piece of code was added to all the endpoint causing too much code redundancy

Solution:- Adding an additional argument to the decorator of every route for the validation and validating request only if it's true. 

example: - 1b8703dc28ff3487efa5ba09829af98b528740f4/guillotina/api/addons.py#L19

PR for this: -  #544


Next Week: 

Issue #553 Be able to subscribe to content changes.

Will be adding a new addon to guillotina which will subscribe to changes made on any object and publish it on a websocket endpoint. 

View Blog Post

WEEK #4 JSON schema validation

Published: 06/23/2019

Issue: #508 Validating all the request hiting Guillotina against proper jsonschema.

This Week:

PR: #517 

Requests coming to the API were not being validated, task was to validate all the request hitting the API. Jsonschema is already defined for most of the endpoints, only a validation wrapper was required to be added to all the endpoint(along with jsonschema for missing endpoints and testcases for validation). Now all the request hitting being validated against a well defined schema and through 412(Precondition failed) along with proper error in case of a bad request. 

Next Week:

Issue: #507

Added validation is a wrapper over all the endpoint causing too much redundancy in code base because its need to be added to all the endpoint. Next thing is to replace the validation with a decorator, which will validate the request automatically and will have very less code redundancy

Stuck anywhere:


View Blog Post

Week #3 Upgrading Guillotina_swagger

Published: 06/16/2019

Last week- Finished up adding authentication to Guillotina_swagger and updating security schemes for OpenAPI 3.

This Week :- 

Issue: Authenticating the request send to baseurl.

This Week:-

Request send to baseurl needs to be authenticated in order to generate proper path object for swaggerUI. SwaggerUI provides `configs` in which authentication token can be added manually to every request sent.

Solution:- When a person tries to login, a new instance of swaggerUI object is created with the auth token in `configs`. github

Problem in this solution:- New event is added to login button which is kind of a hacky way to fix things up, other than that logout button also requires a similar event handler to delete authentication token.

Other than this guillotina_swagger is completely upgraded to OpenAPI 3.

Next Week:-

Requests coming to the Api are not being validated, second task is to provide validation to the payloads of all the request hitting the API. JSON schema is already defined for most of the endpoints just adding the validation is required. Will be adding validation to all the endpoint and jsonschema for those where schema doesn't exist. 

Stuck Somewhere:-

Still, the authentication of guillotina_swagger is working on a small hack and logout need to be fixed which needs to be fixed.

View Blog Post