BETTERZON-58: Adding access key verification

This commit is contained in:
Patrick Müller 2021-05-17 17:32:52 +02:00
parent c8d37d60f8
commit 73effffc89

View File

@ -1,3 +1,5 @@
import os
from flask import Flask from flask import Flask
from flask_restful import Resource, Api, reqparse from flask_restful import Resource, Api, reqparse
@ -19,8 +21,12 @@ class CrawlerApi(Resource):
def post(self): def post(self):
# Accept crawler request here # Accept crawler request here
args = parser.parse_args() args = parser.parse_args()
access_key = os.getenv('CRAWLER_ACCESS_KEY')
if(args['key'] == access_key):
crawler.crawl(args['products']) crawler.crawl(args['products'])
return args return {'message': 'success'}
else:
return {'message': 'Wrong access key'}
api.add_resource(CrawlerApi, '/') api.add_resource(CrawlerApi, '/')