handle Ping route based on allowPing=>True in authmiddleware
@@ -11,6 +11,8 @@ from foglamp.common import logger
from aiohttp import web
from foglamp.services.core import server
from foglamp.services.core.api.statistics import get_statistics
+from foglamp.services.core import connect
+from foglamp.common.configuration_manager import ConfigurationManager
__author__ = "Amarendra K. Sinha, Ashish Jabble"
__copyright__ = "Copyright (c) 2017 OSIsoft, LLC"
@@ -41,6 +43,15 @@ async def ping(request):
curl -X GET http://localhost:8081/foglamp/ping
"""
+ try:
+ auth_token = request.token
+ except AttributeError:
+ cf_mgr = ConfigurationManager(connect.get_storage())
+ category_item = await cf_mgr.get_category_item('rest_api', 'allowPing')
+ allowPing = True if category_item['value'] == 'true' else False
+ if request.is_auth_optional is False and allowPing is False:
+ raise web.HTTPForbidden
+
def get_stats(k):
v = [a['value'] for a in stats if a['key'] == k]
return int(v[0])
