From 6cbcef873eb510c7b16f6ed87862ec336feffc50 Mon Sep 17 00:00:00 2001 From: Marco Malavolti <marco.malavolti@gmail.com> Date: Thu, 29 Jul 2021 20:09:10 +0200 Subject: [PATCH] Add 'check_result' parameter to API --- api.py | 33 +++++++++++++++++++++++---------- web/eccs2.js | 5 ++++- web/index.php | 2 ++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/api.py b/api.py index 32c4783..1425fec 100755 --- a/api.py +++ b/api.py @@ -21,7 +21,7 @@ def buildEmailAddress(listContacts): hrefList = [] for email in listCtcs: - hrefList.append("<a href='%s'>%s</a>" % (email,email.replace('mailto:', ''))) + hrefList.append(f"<a href='{email}'>{email.replace('mailto:', '')}</a>") return hrefList @@ -34,7 +34,7 @@ def existsInFile(file_path, value, research_item, eccsDataTable, date): if (eccsDataTable): return '' else: - return jsonify(error='FileNotFound: ECCS2 script has not been executed on %s yet' % date) + return jsonify(error=f'FileNotFound: ECCS2 script has not been executed on {date} yet') for line in lines: aux = json.loads(line) @@ -70,19 +70,20 @@ class Test(Resource): class EccsResults(Resource): def get(self): - file_path = "%s/eccs2_%s.log" % (ECCS2OUTPUTDIR,DAY) + file_path = f"{ECCS2OUTPUTDIR}/eccs2_{DAY}.log" date = DAY status = None idp = None reg_auth = None eccsDataTable = False simple = False + check_result = None if 'eccsdt' in request.args: eccsDataTable = True if 'date' in request.args: date = request.args['date'] - file_path = "%s/eccs2_%s.log" % (ECCS2OUTPUTDIR,date) + file_path = f"{ECCS2OUTPUTDIR}/eccs2_{date}.log" if 'status' in request.args: status = request.args['status'].upper() if (status not in ['OK','DISABLED','ERROR']): @@ -90,14 +91,18 @@ class EccsResults(Resource): if 'idp' in request.args: idp = request.args['idp'] if (not existsInFile(file_path, idp, "entityID", eccsDataTable, date)): - return jsonify(error="Identity Provider not found with the entityID: %s" % idp) + return jsonify(error=f"Identity Provider not found with the entityID: {idp}") if 'reg_auth' in request.args: reg_auth = request.args['reg_auth'] if (not existsInFile(file_path, reg_auth, "registrationAuthority", eccsDataTable, date)): - return jsonify(error="Identity Providers not found with the Registration Authority: %s" % reg_auth) + return jsonify(error=f"Identity Providers not found with the Registration Authority: {reg_auth}") if 'format' in request.args: if 'simple' == request.args['format']: simple = True + if 'check_result' in request.args: + check_result = request.args['check_result'] + if (check_result not in ['OK','Timeout','Invalid-Form','Connection-Error','No-eduGAIN-Metadata','SSL-Error','DISABLED']): + return jsonify(error="Incorrect check_result value provided. It can be 'OK','Timeout','Invalid-Form','Connection-Error','No-eduGAIN-Metadata','SSL-Error' ok 'DISABLED'") lines = [] results = [] @@ -109,7 +114,7 @@ class EccsResults(Resource): if (eccsDataTable): return '' else: - return jsonify(error='FileNotFound: ECCS2 script has not been executed on %s' % date) + return jsonify(error=f'FileNotFound: ECCS2 script has not been executed on {date}') for line in lines: # Strip the line feed and carriage return characters @@ -163,9 +168,17 @@ class EccsResults(Resource): results.append(auxSimple) else: results.append(aux) + elif (check_result): + if (check_result == aux['sp1']['checkResult'] or check_result == aux['sp2']['checkResult']): + if (simple): + auxSimple = getSimpleDict(aux) + results.append(auxSimple) + else: + results.append(aux) elif (simple): auxSimple = getSimpleDict(aux) results.append(auxSimple) + else: results.append(aux) @@ -178,14 +191,14 @@ class FedStats(Resource): list_feds = get_list_feds(ECCS2LISTFEDSURL, ECCS2LISTFEDSFILE) regAuthDict = get_reg_auth_dict(list_feds) - file_path = "%s/eccs2_%s.log" % (ECCS2OUTPUTDIR,DAY) + file_path = f"{ECCS2OUTPUTDIR}/eccs2_{DAY}.log" date = DAY reg_auth = None eccsDataTable = False if ('date' in request.args): date = request.args['date'] - file_path = "%s/eccs2_%s.log" % (ECCS2OUTPUTDIR,date) + file_path = f"{ECCS2OUTPUTDIR}/eccs2_{date}.log" if ('reg_auth' in request.args): reg_auth = request.args['reg_auth'] if (not existsInFile(file_path, reg_auth, "registrationAuthority", eccsDataTable, date)): @@ -201,7 +214,7 @@ class FedStats(Resource): if (eccsDataTable): return '' else: - return jsonify(error='FileNotFound: ECCS2 script has not been executed on %s yet' % date) + return jsonify(error=f'FileNotFound: ECCS2 script has not been executed on {date} yet') if (reg_auth): resultDict = {'date': date, 'registrationAuthority': reg_auth, 'OK': 0, 'ERROR': 0, 'DISABLED': 0} diff --git a/web/eccs2.js b/web/eccs2.js index 76e6e78..7c9a821 100644 --- a/web/eccs2.js +++ b/web/eccs2.js @@ -147,6 +147,7 @@ function SHA1(msg) { // date (date time of the check) // reg_auth (the IdP RegistrationAuthority) // status (the ECCS2 IdP Status) +// check_result (the ECCS2 check result) if (date) { url = url.concat("&date=" + date); } @@ -159,7 +160,9 @@ if (idp) { if (status) { url = url.concat("&status=" + status); } - +if (check_result) { + url = url.concat("&check_result=" + check_result); +} function getPastResults() { var checkDate = $.datepicker.formatDate("yy-mm-dd", $('#datepicker').datepicker().datepicker('getDate')); diff --git a/web/index.php b/web/index.php index dcb9764..1644096 100644 --- a/web/index.php +++ b/web/index.php @@ -17,6 +17,7 @@ $data['idp'] = htmlspecialchars($_GET["idp"]); $data['reg_auth'] = htmlspecialchars($_GET["reg_auth"]); $data['date'] = (htmlspecialchars($_GET["date"]) ? htmlspecialchars($_GET["date"] : $lastDate); $data['status'] = htmlspecialchars($_GET["status"]); +$data['check_result'] = htmlspecialchars($_GET["check_result"]); ?> <!DOCTYPE html> @@ -83,6 +84,7 @@ $data['status'] = htmlspecialchars($_GET["status"]); var reg_auth = "<?php echo $data['reg_auth'] ?>"; var idp = "<?php echo $data['idp'] ?>"; var status = "<?php echo $data['status'] ?>"; + var check_result = "<?php echo $data['check_result'] ?>"; </script> <script type="text/javascript" src="eccs2.js" /></script> </body> -- GitLab