Skip to content
Snippets Groups Projects
Commit 84480476 authored by Marco Malavolti's avatar Marco Malavolti
Browse files

Fixed returned errors

parent 9f66d469
No related branches found
No related tags found
No related merge requests found
...@@ -4,8 +4,8 @@ import json ...@@ -4,8 +4,8 @@ import json
import logging import logging
import re import re
from eccs2properties import DAY,ECCS2LOGSDIR,ECCS2OUTPUTDIR from eccs2properties import DAY, ECCS2LOGSDIR, ECCS2OUTPUTDIR
from flask.logging import default_handler #from flask.logging import default_handler
from flask import Flask, request, jsonify from flask import Flask, request, jsonify
from flask_restful import Resource, Api from flask_restful import Resource, Api
from utils import getLogger from utils import getLogger
...@@ -27,18 +27,25 @@ def buildEmailAddress(listContacts): ...@@ -27,18 +27,25 @@ def buildEmailAddress(listContacts):
return hrefList return hrefList
def existsInFile(file_path, value, research_item): def existsInFile(file_path, value, research_item, eccsDataTable):
with open(file_path,"r",encoding="utf-8") as fo: try:
lines = fo.readlines() with open(file_path,"r",encoding="utf-8") as fo:
for line in lines: lines = fo.readlines()
aux = json.loads(line) except FileNotFoundError as e:
if (research_item == "entityID"): if (eccsDataTable):
if (value == aux['entityID']): return ''
return True else:
if (research_item == "registrationAuthority"): return jsonify(error='FileNotFound: ECCS2 script has not been executed for this day')
if (value == aux['registrationAuthority']):
return True for line in lines:
return False aux = json.loads(line)
if (research_item == "entityID"):
if (value == aux['entityID']):
return True
if (research_item == "registrationAuthority"):
if (value == aux['registrationAuthority']):
return True
return False
### Classes ### Classes
...@@ -69,15 +76,15 @@ class EccsResults(Resource): ...@@ -69,15 +76,15 @@ class EccsResults(Resource):
if 'status' in request.args: if 'status' in request.args:
status = request.args['status'].upper() status = request.args['status'].upper()
if (status not in ['OK','DISABLED','ERROR']): if (status not in ['OK','DISABLED','ERROR']):
return '{ "error": "Incorrect status provided. It can be \'ok\',\'disabled\',\'error\'" }' return jsonify(error="Incorrect status provided. It can be 'ok','disabled','error'")
if 'idp' in request.args: if 'idp' in request.args:
idp = request.args['idp'] idp = request.args['idp']
if (not existsInFile(file_path, idp, "entityID")): if (not existsInFile(file_path, idp, "entityID", eccsDataTable)):
return "Identity Provider not found with the entityID: %s" % idp return jsonify(error="Identity Provider not found with the entityID: %s" % idp)
if 'reg_auth' in request.args: if 'reg_auth' in request.args:
reg_auth = request.args['reg_auth'] reg_auth = request.args['reg_auth']
if (not existsInFile(file_path, reg_auth, "registrationAuthority")): if (not existsInFile(file_path, reg_auth, "registrationAuthority", eccsDataTable)):
return "Identity Providers not found with the Registration Authority: %s" % reg_auth return jsonify(error="Identity Providers not found with the Registration Authority: %s" % reg_auth)
lines = [] lines = []
results = [] results = []
...@@ -89,7 +96,7 @@ class EccsResults(Resource): ...@@ -89,7 +96,7 @@ class EccsResults(Resource):
if (eccsDataTable): if (eccsDataTable):
return '' return ''
else: else:
return "FileNotFound: ECCS2 script has not been executed for this day" return jsonify(error='FileNotFound: ECCS2 script has not been executed for this day')
for line in lines: for line in lines:
# Strip the line feed and carriage return characters # Strip the line feed and carriage return characters
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment