GSoC 2021 with SCoRe Lab — Week 6

Nipuna Weerasekara
SCoRe Lab
Published in
2 min readJul 8, 2021

tl;drThis is the seventh article of my journey into the Google Summer of Code 2021 with SCoRe Lab. Here I discuss week six (28th of June to 4th of July) of my GSoC experience.

So what happened in week six?

As my project mentors and I discussed in our online meeting, I was assigned to develop the endpoints related to making updates to the scan records stored in the database. The development of these endpoints was pretty much straightforward and I utilized the power of the all-mighty, Flask RESTful library.

In the Flask RESTful library, you can easily define a single controller for a route and define several HTTP methods. For example,

PATCH  /scans/<id>
DELETE /scans/<id>

these above two HTTP methods utilize the same endpoint /scans/<id> and if the user hits this endpoint via a PATCH method, we need to respond to it as a PATCH request and if the user hits this endpoint via a DELETE method, we need to respond to it as a DELETE request. In hindsight, we need a mechanism to capture the HTTP request method and respond to it accordingly. In plain Flask, we’ll do this as follows,

from flask import request

@app.route('/scans/<id>', methods=['PATCH', 'DELETE'])
def scan_controller(id:str):
if request.method == 'PATCH':
return update_scan_record(id)
else:
return delete_scan_records(id)

(from https://flask.palletsprojects.com/en/1.1.x/quickstart/#http-methods)

But we can utilize the Flask RESTful in the following way (in a more elegant way indeed 😁).

from flask_restful import Resourceclass ScanController(Resource):
method_decorators: Dict[str, List[Callable]] = dict(patch=[validator, authenticate])
model: str = "UpdateScan"
def patch(self,id:str):
return update_scan_records()

def delete(self,id:str):
return delete_scan_record()

(from https://flask-restful.readthedocs.io/en/latest/quickstart.html#full-example)

So by using this example, I was able to create endpoint handlers for PATCH and DELETE methods. Of course, I utilized other libraries such as Marshmallow and Firebase Admin to fulfill my tasks. After completing these tasks, I updated the Swagger-UI to reflect the newly added endpoints, because, documentation is your biggest ally 💪.

So after all of these, I submitted a PR,

and it got merged into the main repository.

So in the coming week, I will work on enhancing the features of our DNSTool-Middleware-API[API-Gateway] component 🤞. Until we meet again, happy coding…

--

--

Nipuna Weerasekara
SCoRe Lab

I am a web developer turned security researcher. Find me on niweera.com