Articles on karannaoh's Bloghttps://blogs.python-gsoc.orgUpdates on different articles published on karannaoh's BlogenThu, 22 Aug 2019 14:27:35 +0000Final Week | Helm chart tweekshttps://blogs.python-gsoc.org/en/karannaohs-blog/final-week-helm-chart-tweeks/<p>PR:- <a href="https://github.com/plone/guillotina/pull/638">#638</a></p> <p>Added helm charts for Guillotina</p> <p>Description</p> <p>1 Deployement with 2 pods by default</p> <p>1 configmap to mount guillotina configuration yaml on the pods </p> <p>1 Service to expose guillotina</p> <p>Guillotina allows user to pass arguments to override values defined in configuration fine similar to that user can pass arguments to `helm install` to override configuration.</p> <p>Simple way to edit configurations is to edit configuration file in values.yaml</p>karanpratapsingh43@gmail.com (karannaoh)Thu, 22 Aug 2019 14:27:35 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/final-week-helm-chart-tweeks/Week #11 Added validation for query Parametershttps://blogs.python-gsoc.org/en/karannaohs-blog/week-11-added-validation-for-query-parameters/<p>PR:- <a href="https://github.com/plone/guillotina/pull/630">#630</a></p> <p>This Week:-</p> <p>- Added OpenAPI definitions to @search service for both post and get request.</p> <p>- Added validation of query parameters, so that a query parameters of a request can also be validated against defined schema only by adding `validate=True` in the service definition.</p> <p>Stuck Anywhere:-</p> <p>The way we are validating query params is iterating over all the params and validating there schema, it's short of like implementing our own jsonschema package which is a bit redundant and in efficient. </p>karanpratapsingh43@gmail.com (karannaoh)Tue, 13 Aug 2019 18:05:04 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/week-11-added-validation-for-query-parameters/Week #10 | Helm chart Guillotinahttps://blogs.python-gsoc.org/en/karannaohs-blog/week-10-helm-chart-guillotina/<p>Issue:-<a href="https://github.com/plone/guillotina/issues/617">#617</a></p> <p>Task is to add helm charts for guillotina, so that guillotina can easily be deployed on kubernetes with all availble configurations.</p> <ul> <li>allows mounting config file</li> <li>allows overriding configuration values with <code>G_</code> env variables, see: <a href="https://guillotina.readthedocs.io/en/latest/developer/commands.html?highlight=override#overridding-configuration">https://guillotina.readthedocs.io/en/latest/developer/commands.html?highlight=override#overridding-configuration</a></li> </ul> <p>The helm chart should have support for configuring <code>n</code> number of databases and all the settings that guillotina supports. It would package these configuration settings into a <code>config.json</code>(or yaml if you prefer) that is mounted and referenced in the command arguments.</p> <p>Make sure to provide the ability to also customize the image because people using this will likely be customizing the docker image used to package other things with guillotina(like customize addons).</p> <p>This helm chart would serve as a generic chart to be able to deploy guillotina with.</p>karanpratapsingh43@gmail.com (karannaoh)Wed, 07 Aug 2019 13:51:30 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/week-10-helm-chart-guillotina/Week #9 | Fixes in Swagger and schema validationhttps://blogs.python-gsoc.org/en/karannaohs-blog/week-9-fixes-in-swagger-and-schema-validation/<p>PR <a href="https://github.com/plone/guillotina/pull/618">#618</a></p> <p>This week:-</p> <p>Updated services parameters definitions according to OpenAPI 3.0</p> <p>- Added path parameters for endpoints</p> <p>- Added schemas to parameter definitions</p> <p>- and added definitions to the endpoint which didnt had definitions of swagger</p> <p> </p>karanpratapsingh43@gmail.com (karannaoh)Mon, 29 Jul 2019 07:29:13 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/week-9-fixes-in-swagger-and-schema-validation/Week #8 | Fixes in decorator for validationhttps://blogs.python-gsoc.org/en/karannaohs-blog/week-8-fixes-in-decorator-for-validation/<p>Issue: <a href="https://github.com/plone/guillotina/issues/507/">#50</a><a href="https://github.com/plone/guillotina/issues/508">8</a> Validating all the request hiting Guillotina against proper jsonschema.</p> <p>This Week:</p> <p>PR: <a href="https://github.com/plone/guillotina/pull/517">#517</a> </p> <p>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. </p> <p>Next Week:</p> <p>Issue: <a href="https://github.com/plone/guillotina/issues/507">#507</a></p> <p>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</p> <p>Stuck anywhere:</p> <p>No</p>karanpratapsingh43@gmail.com (karannaoh)Tue, 23 Jul 2019 06:15:53 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/week-8-fixes-in-decorator-for-validation/Week #7 | Guillotina PubSubhttps://blogs.python-gsoc.org/en/karannaohs-blog/week-7-guillotina-pubsub/<p>Commit :- <a href="https://github.com/guillotinaweb/guillotina_pubsub/commit/530f9c7e08151cf499d156c1fc756a0239bace5c">530f9c7e08151cf499d156c1fc756a0239bace5c</a></p> <p>Worked on guillotina_pubsub which is a guillotina addon to subscribe to the content change via a websocket endpoint.</p> <p>Last-Week:</p> <p>Created a subscriber to listen to content change event and publish it on redis pubsub guillotina</p> <p>This Week:-  </p> <p>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</p>karanpratapsingh43@gmail.com (karannaoh)Mon, 15 Jul 2019 05:50:25 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/week-7-guillotina-pubsub/Week #6 | Guillotina PubSubhttps://blogs.python-gsoc.org/en/karannaohs-blog/week-6-guillotina-pubsub/<p>Issue <a href="https://github.com/plone/guillotina/issues/553">#553</a></p> <p>A consumer of the API needs to be able to subscribe to changes to a specific content object in Guillotina.</p> <p>This week:-</p> <p>Repository:- <a href="https://github.com/karannaoh/guillotina_pubsub/">guillotina_pubsub</a></p> <p>Created a new Addon for Guillotina which subscribe to changes made to any object and publish on a websocket service.</p> <p><strong>IObjectModifiedEvent </strong>is the event triggered everytime any object is modified, using this event details of changed object are publish on a channel of redis pubsub.</p> <p>@content-changes is a websocket service which subscribe to all the changes made on the channel of redis pubsub and send to client.</p> <p>Next week:-</p> <p>Adding test cases for this Addon and necessary refractor to push the code to a new repository of guillotinaweb  </p>karanpratapsingh43@gmail.com (karannaoh)Mon, 15 Jul 2019 05:49:56 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/week-6-guillotina-pubsub/Week #5 | Decorator for schema Validationhttps://blogs.python-gsoc.org/en/karannaohs-blog/week-5-decorator-for-schema-validation/<p><strong>This Week:</strong></p> <p>Issue: <a href="https://github.com/plone/guillotina/issues/507">#507</a> Provide decorator for validating json schema request payloads. </p> <p>Last week: added jsonschema validation to all the endpoints.</p> <p>example- PR: <a href="https://github.com/plone/guillotina/pull/517/">#517</a>  </p> <p><code>validator = get_schema_validator('Type_Of_schema')<br> try:<br>    data = await request.json()<br>    validator.validate(data) <br>    behavior = data.get('behavior', None)<br>    return await delete_behavior(context, behavior)<br> except jsonschema.exceptions.ValidationError as e:<br>  raise HTTPPreconditionFailed(content={<br>       'reason': 'json schema validation error',<br>       'message': e.message,<br>       'validator': e.validator,<br>       'validator_value': e.validator_value,<br>       'path': [i for i in e.path],<br>       'schema_path': [i for i in e.schema_path],<br>       "schema": app_settings['json_schema_definitions']['Behavior']<br> })</code></p> <p>problem in this:- This piece of code was added to all the endpoint causing too much code redundancy</p> <p>Solution:- Adding an additional argument to the decorator of every route for the validation and validating request only if it's true. </p> <p>example: - <a href="https://github.com/plone/guillotina/blob/1b8703dc28ff3487efa5ba09829af98b528740f4/guillotina/api/addons.py#L19">1b8703dc28ff3487efa5ba09829af98b528740f4/guillotina/api/addons.py#L19</a></p> <p>PR for this: -  <a href="https://github.com/plone/guillotina/pull/544">#544</a></p> <p> </p> <p><strong>Next Week: </strong></p> <p>Issue <a href="https://github.com/plone/guillotina/issues/553">#553</a> Be able to subscribe to content changes.</p> <p>Will be adding a new addon to guillotina which will subscribe to changes made on any object and publish it on a websocket endpoint. </p>karanpratapsingh43@gmail.com (karannaoh)Mon, 01 Jul 2019 06:04:31 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/week-5-decorator-for-schema-validation/WEEK #4 JSON schema validationhttps://blogs.python-gsoc.org/en/karannaohs-blog/week-4-json-schema-validation/<p>Issue: <a href="https://github.com/plone/guillotina/issues/507\">#50</a><a href="https://github.com/plone/guillotina/issues/508">8</a> Validating all the request hiting Guillotina against proper jsonschema.</p> <p>This Week:</p> <p>PR: <a href="https://github.com/plone/guillotina/pull/517">#517</a> </p> <p>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. </p> <p>Next Week:</p> <p>Issue: <a href="https://github.com/plone/guillotina/issues/507">#507</a></p> <p>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</p> <p>Stuck anywhere:</p> <p>No</p>karanpratapsingh43@gmail.com (karannaoh)Sun, 23 Jun 2019 10:12:18 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/week-4-json-schema-validation/Week #3 Upgrading Guillotina_swaggerhttps://blogs.python-gsoc.org/en/karannaohs-blog/week-3-upgrading-guillotina-swagger/<p><a href="https://blogs.python-gsoc.org/en/blogs/karannaohs-blog/week-2-still-upgrading-guillotina-swagger-p/">Last week</a>- Finished up adding authentication to Guillotina_swagger and updating security schemes for OpenAPI 3.</p> <p>This Week :- </p> <p><strong>Issue: </strong>Authenticating the request send to baseurl.</p> <p>This Week:-</p> <p>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.</p> <p>Solution:- When a person tries to login, a new instance of swaggerUI object is created with the auth token in `configs`. <a href="https://github.com/guillotinaweb/guillotina_swagger/pull/3/files#diff-7bbc8b2584356e2b66d645e6f0f533e9R308">github</a>. </p> <p>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.</p> <p>Other than this guillotina_swagger is completely upgraded to OpenAPI 3.</p> <p>Next Week:-</p> <p>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. </p> <p>Stuck Somewhere:-</p> <p>Still, the authentication of guillotina_swagger is working on a small hack and logout need to be fixed which needs to be fixed.</p>karanpratapsingh43@gmail.com (karannaoh)Sun, 16 Jun 2019 17:58:06 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/week-3-upgrading-guillotina-swagger/Week #2 Still Upgrading Guillotina_swagger :phttps://blogs.python-gsoc.org/en/karannaohs-blog/week-2-still-upgrading-guillotina-swagger-p/<p>Started to update Guillotina_swagger which is an addon to Guillotina, generates swagger UI for Guillotina, link to <a href="https://blogs.python-gsoc.org/en/blogs/karannaohs-blog/week-1-upgrading-guillotina-swagger/">last week</a> blog.</p> <p>Things which were completed:- PR:- <a href="https://github.com/guillotinaweb/guillotina_swagger/pull/3">Upgrade swagger #3</a></p> <ul> <li>Updated static js and css for OpenAPI 3. <a href="https://github.com/plone/guillotina/issues/506">Issue#506</a></li> <li>Updated swaggerObject(which is not OpenAPI object) according to OpenAPI 3 specifications. <a href="https://github.com/plone/guillotina/issues/505">Issue#505</a></li> </ul> <p> What did you do this week?:- <a href="https://github.com/plone/guillotina/issues/513">Issue#513</a> </p> <p>Guillotina_swagger need authentication in order to generate the swagger object with the path object a user is authorized to access. Previously HTTP basic auth or JWT token were manually added to all the request headers and then the response object was rendered by swaggerUI which is now replaced by `securitySchemes` of OpenAPI 3. Instead of adding auth token to request header manually now `securitySchemes` of OpenAPI 3.</p> <p>Definition of path objects is defined inline in the guillotina repository along with every endpoint. In OpenAPI 3  schema, parameters, responses, and definitions are now a part on a new object which is component, it's is one of the major changes required for the upgrade. </p> <p>What is coming up next?</p> <p>Path Object is created by Guillotina_swagger according to the permissions a user have, previously it was done by sending auth token to the baseurl. Now all the authentication is taken care by swaggerUI auth except the request send to get the OpenAPI object, which requires a fix.</p> <p>Did you get stuck anywhere?</p> <p> OpenAPI's authentication adds auth token to the request created to all the endpoints but the requests send to baseurl also need to have the auth token in order to generate the proper path object, it can be added manually to the request header but that would be a hacky solution. This problem still needs some research and brainstorming. </p> <p> </p> <p> </p>karanpratapsingh43@gmail.com (karannaoh)Sat, 08 Jun 2019 10:50:16 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/week-2-still-upgrading-guillotina-swagger-p/Week #1 | Upgrading Guillotina_swaggerhttps://blogs.python-gsoc.org/en/karannaohs-blog/week-1-upgrading-guillotina-swagger/<p><span style="font-size: 16px;"><strong><a href="https://github.com/plone/guillotina/issues/505">Issue #505</a></strong></span></p> <p><a href="https://github.com/guillotinaweb/guillotina_swagger">Guillotina_swagger</a> is a addon to <a href="http://guillotina.io">Guillotina</a> which generates Swagger interface for the endpoints defined in Guillotina according to user access.</p> <p>Task- Is to upgrade the Swagger object generated by Guillotina_swagger according to OpenAPI3 specs.</p> <p>Terms which will be used in the article:-</p> <p><strong>Swagger/OpenAPI:</strong> Swagger is an open source framework used for documenting and testing APIs which has now upgraded to OpenAPI3</p> <p><strong>SwaggerUI:</strong> SwaggerUI is a tool provided by Swagger to generate a UI where all the functionalities of an API can be documented and tested.</p> <p><strong>Swagger Object/OpenAPI Object:</strong> Swagger Object is JSON or YAML where specifications about APIs are defined. </p> <p>Guillotina_swagger generates swagger object(which is OpenAPI now) which is consumed by the frontend to create swaggerUI. </p> <p>Changes required:- </p> <ul> <li>Upgrading previously used swaggerUI packages(js,css files).</li> <li>Upgrading Swagger Object according to new OpenAPI Specification.</li> <li>Updating Javascript which is used to render swagger Object on the frontend</li> </ul> <p>What did you do this week?</p> <p>Started from understanding Guillotina and Guillotina_swagger and the things which need to be upgraded for OpenAPI3. Upgraded previously used SwaggerUI packages. Updated Swagger Object generated by Guillotina_swagger according to OpenAPI 3 specifications. Major changes which happened due to shift on OpenAPI 3 are - </p> <ul> <li>swagger.host, swagger.basepath, swagger.schemes now comes under a new object swagger.servers</li> <li>securityDefinitions, produces, consumes, definitions, parameter, responses comes under component which is also a new object in OpenAPI 3.</li> </ul> <p>What is coming up next week? </p> <ul> <li>Previously authentication was managed manually by adding authentication tokens inside the request created to get swagger object, this will be changed by using inbuilt securityDefinitions of SwaggerUI.</li> <li>Schema, parameters, definitions, and responses are defined inside guillotina which are used inside path object of are needed to be updated as schema, parameters, definitions and responses are now a part of component object.</li> </ul> <p> </p> <p> </p> <p> </p>karanpratapsingh43@gmail.com (karannaoh)Fri, 31 May 2019 05:37:14 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/week-1-upgrading-guillotina-swagger/GSOC 2019 | karannaoh's blog | Guillotinahttps://blogs.python-gsoc.org/en/karannaohs-blog/gsoc-2019-karannaoh-s-blog-guillotina/<p>Hello Everyone, It's <a href="http://karannaoh.github.io">Karan Pratap Singh</a> an undergraduate student from India. I got selected in GSOC'19 project(<a href="https://summerofcode.withgoogle.com/projects/#5888430322483200" target="_self">Plone: Guillotina API Evolution</a>) under Plone which is a sub-org of Python Software Foundation. I will be working on a major upgradation of <a href="http://guillotina.io">Guillotina</a> which is a fullstack Async framework for the next 12 weeks. My project involves </p> <ul> <li>Upgrading Swagger2.0 documentation of the apis to Openapi 3.</li> <li>Validating JSON schema to all the request and responses.</li> <li>Working on adding all api's functionalities to the websocket endpoint to Guillotina.</li> <li>Adding a mechanism to version the API.</li> <li>And adding helm chart for easy deployment of Guillotina</li> </ul> <p>I will be writing weekly blogs for the next 12 weeks explaining my work and progress.</p> <p>Thank you for reading</p>karanpratapsingh43@gmail.com (karannaoh)Tue, 28 May 2019 17:52:13 +0000https://blogs.python-gsoc.org/en/karannaohs-blog/gsoc-2019-karannaoh-s-blog-guillotina/