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

Fixed API and added Calendar for the input date value

parent b2f7a796
Branches
Tags
No related merge requests found
......@@ -5,6 +5,7 @@ import logging
import re
from eccs2properties import DAY,ECCS2LOGSDIR,ECCS2OUTPUTDIR
from flask.logging import default_handler
from flask import Flask, request, jsonify
from flask_restful import Resource, Api
from utils import getLogger
......@@ -13,11 +14,7 @@ app = Flask(__name__)
api = Api(app)
# /eccs2/test
class Test(Resource):
def get(self):
app.logger.info("Test Passed!")
return {'test':'It Works!'}
### Functions
# Build Email Addresses Link for ECCS2 Web Gui
def buildEmailAddress(listContacts):
......@@ -29,72 +26,115 @@ def buildEmailAddress(listContacts):
return hrefList
### Classes
# Test
class Test(Resource):
def get(self):
return {'test':'It Works!'}
# /eccs2/api/eccsresults
class EccsResults(Resource):
def get(self):
app.logger.info("Request 'EccsResults'")
file_path = "%s/eccs2_%s.log" % (ECCS2OUTPUTDIR,DAY)
date = DAY
pretty = 0
status = None
idp = None
reg_auth = None
eccsDataTable = False
if 'eccsdt' in request.args:
eccsDataTable = True
if 'date' in request.args:
app.logger.info("'date' parameter inserted")
date = request.args['date']
file_path = "%s/eccs2_%s.log" % (ECCS2OUTPUTDIR,date)
if 'pretty' in request.args:
app.logger.info("'pretty' parameter inserted")
pretty = request.args['pretty']
if 'status' in request.args:
app.logger.info("'status' parameter inserted")
status = request.args['status']
status = request.args['status'].upper()
if (status not in ['OK','DISABLED','ERROR']):
return "Incorrect status format, should be 'ok','disabled','error'"
if 'idp' in request.args:
app.logger.info("'idp' parameter inserted")
idp = request.args['idp']
app.logger.info(idp)
fo = open(file_path,"r",encoding="utf-8")
result = []
lines = fo.readlines()
with open(file_path,"r",encoding="utf-8") as fo:
lines = fo.readlines()
found = False
for line in lines:
aux = json.loads(line)
if (idp == aux['entityID']):
found = True
if (found == False):
return "Identity Provider not found with the entityID: %s" % idp
if 'reg_auth' in request.args:
reg_auth = request.args['reg_auth']
with open(file_path,"r",encoding="utf-8") as fo:
lines = fo.readlines()
found = False
for line in lines:
aux = json.loads(line)
if (reg_auth == aux['registrationAuthority']):
found = True
if (found == False):
return "Identity Providers not found with the Registration Authority: %s" % reg_auth
lines = []
results = []
with open(file_path,"r",encoding="utf-8") as fo:
lines = fo.readlines()
for line in lines:
# Strip the line feed and carriage return characters
line = line.rstrip("\n\r")
print(line)
# Loads the json line into aux
aux = json.loads(line)
aux['date'] = date
aux['contacts']['technical'] = buildEmailAddress(aux['contacts']['technical'])
aux['contacts']['support'] = buildEmailAddress(aux['contacts']['support'])
# If the results are for ECCS2 DataTable, otherwise... remove only "mailto:" prefix
if (eccsDataTable):
aux['contacts']['technical'] = buildEmailAddress(aux['contacts']['technical'])
aux['contacts']['support'] = buildEmailAddress(aux['contacts']['support'])
else:
aux['contacts']['technical'] = aux['contacts']['technical'].replace("mailto:","")
aux['contacts']['support'] = aux['contacts']['support'].replace("mailto:","")
if (idp and status):
app.logger.info("eccsresults: check for 'idp':'%s' with 'status':'%s'" % (idp, status))
if (idp == aux['entityID'] and status == aux['status']):
result.append( aux )
results.append(aux)
elif (reg_auth and status):
if (reg_auth == aux['registrationAuthority'] and status == aux['status']):
results.append(aux)
elif (idp):
app.logger.info("eccsresults: results for IdP:'%s'." % idp)
if (re.search(".*."+idp+".*.", aux['entityID'], re.IGNORECASE)):
result.append( aux )
if (idp == aux['entityID']):
results.append(aux)
elif (reg_auth):
if (reg_auth == aux['registrationAuthority']):
results.append(aux)
elif (status):
if (status == aux['status']):
result.append( aux )
results.append(aux)
else:
result.append(aux)
results.append(aux)
return jsonify(results)
if (pretty):
pp_json = json.dumps(result, indent=4, sort_keys=True)
return jsonify(pp_json)
else:
return jsonify(result)
api.add_resource(Test, '/eccs/test') # Route_1
api.add_resource(EccsResults, '/eccs/eccsresults') # Route_2
# /eccs2/api/fedstats
class FedStats(Resource):
def get(self):
return {'fedstats':'It Works!'}
# Routes
api.add_resource(Test, '/test') # Route_1
api.add_resource(EccsResults, '/eccsresults') # Route_2
api.add_resource(FedStats, '/fedstats') # Route_3
if __name__ == '__main__':
app.config['JSON_AS_ASCII'] = False
app.logger = getLogger("eccs2api.log", ECCS2LOGSDIR, "w", "INFO")
#app.config['JSON_AS_ASCII'] = True
#app.logger.removeHandler(default_handler)
#app.logger = getLogger("eccs2api.log", ECCS2LOGSDIR, "w", "INFO")
app.run(port='5002')
......@@ -15,9 +15,11 @@
<body>
<hr>
<div id="status">
<input type="checkbox" name="status" value="ERROR">ERROR
<input type="checkbox" name="status" value="OK">OK
<input type="checkbox" name="status" value="DISABLE">DISABLE
<input type="checkbox" name="status" value="ERROR">ERROR</input>
<input type="checkbox" name="status" value="OK">OK</input>
<input type="checkbox" name="status" value="DISABLE">DISABLE</input>
<button style="float:right;" onclick="getPastResults()">Go</button>
<input style="float:right;" type="date" id="myDate" min="2020-07-03" max="<?php echo date("Y-m-d")?>" value="<?php echo date("Y-m-d")?>"/>
</div>
<hr>
<button id="btn-show-all-children" type="button">Expand All</button>
......
// Global URL
var url = "/eccs2/api/eccsresults?eccdt=1";
var table;
// use URL constructor and return hostname
function getHostname(url) {
const urlNew = new URL(url);
......@@ -51,11 +55,15 @@ function format ( d ) {
'</table>';
}
function getPastResults() {
url = "/eccs2/api/eccsresults?eccsdt=1&date=" + document.getElementById("myDate").value;
table.ajax.url( url ).load();
}
$(document).ready(function() {
var table = $('#eccstable').DataTable( {
table = $('#eccstable').DataTable( {
"ajax": {
"url": "data.json",
"url": url,
"dataSrc": ""
},
"lengthMenu": [[10, 20, 30, 40, 50, 100, -1], [10, 20, 30, 40, 50, 100, "All"]],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment