11import web
22import os
33import json
4- from src .wl import WebLogger
4+ # from src.wl import WebLogger
55import requests
66import urllib .parse as urlparse
77import re
5151 "oci" : "tools" ,
5252 "intrepid" : "tools" ,
5353 "api" : "querying" ,
54- "api" : "querying" ,
5554 "search" : "querying"
5655}
5756
7069)
7170
7271# Set the web logger
73- web_logger = WebLogger (env_config ["base_url" ], env_config ["log_dir" ], [
74- "HTTP_X_FORWARDED_FOR" , # The IP address of the client
75- "REMOTE_ADDR" , # The IP address of internal balancer
76- "HTTP_USER_AGENT" , # The browser type of the visitor
77- "HTTP_REFERER" , # The URL of the page that called your program
78- "HTTP_HOST" , # The hostname of the page being attempted
79- "REQUEST_URI" , # The interpreted pathname of the requested document
80- # or CGI (relative to the document root)
81- "HTTP_AUTHORIZATION" , # Access token
82- ],
83- # comment this line only for test purposes
84- {"REMOTE_ADDR" : ["130.136.130.1" , "130.136.2.47" , "127.0.0.1" ]}
85- )
72+ # web_logger = WebLogger(env_config["base_url"], env_config["log_dir"], [
73+ # "HTTP_X_FORWARDED_FOR", # The IP address of the client
74+ # "REMOTE_ADDR", # The IP address of internal balancer
75+ # "HTTP_USER_AGENT", # The browser type of the visitor
76+ # "HTTP_REFERER", # The URL of the page that called your program
77+ # "HTTP_HOST", # The hostname of the page being attempted
78+ # "REQUEST_URI", # The interpreted pathname of the requested document
79+ # # or CGI (relative to the document root)
80+ # "HTTP_AUTHORIZATION", # Access token
81+ # ],
82+ # # comment this line only for test purposes
83+ # {"REMOTE_ADDR": ["130.136.130.1", "130.136.2.47", "127.0.0.1"]}
84+ # )
8685
8786# API Managers
8887meta_api_manager = APIManager (c ["api_meta" ])
104103
105104application = app .wsgifunc ()
106105
107- rconn = Redis (host = env_config ["redis" ]["host" ],
108- port = env_config ["redis" ]["port" ],
109- db = env_config ["redis" ]["db" ],
110- password = env_config ["redis" ]["password" ])
106+ if env_config ["redis" ]["enabled" ]:
107+ try :
108+ rconn = Redis (
109+ host = env_config ["redis" ]["host" ],
110+ port = env_config ["redis" ]["port" ],
111+ db = env_config ["redis" ]["db" ],
112+ password = env_config ["redis" ]["password" ]
113+ )
114+ # Test della connessione
115+ rconn .ping ()
116+ print ("Redis connection established" )
117+ except Exception as e :
118+ print (f"Redis connection failed: { e } " )
119+ rconn = None
120+ else :
121+ rconn = None
111122
112123def sync_static_files ():
113124 """
@@ -123,7 +134,7 @@ def sync_static_files():
123134 print (f"Unexpected error during synchronization: { e } " )
124135
125136def validateAccessToken ():
126- if not env_config ["redis" ]["enabled" ]:
137+ if not env_config ["redis" ]["enabled" ] or rconn is None :
127138 # If Redis is not enabled, skip token validation
128139 return True
129140 auth_code = web .ctx .env .get ('HTTP_AUTHORIZATION' )
@@ -205,7 +216,7 @@ def __init__(self, sparql_endpoint, sparql_endpoint_title, yasqe_sparql_endpoint
205216 self .collparam = ["query" ]
206217
207218 def GET (self ):
208- web_logger .mes ()
219+ # web_logger.mes()
209220 content_type = web .ctx .env .get ('CONTENT_TYPE' )
210221 return self .__run_query_string (self .sparql_endpoint_title , web .ctx .env .get ("QUERY_STRING" ), content_type )
211222
@@ -247,7 +258,7 @@ def __contact_tp(self, data, is_post, content_type):
247258 web .header ('Content-Type' , 'application/sparql-results+json' )
248259 else :
249260 web .header ('Content-Type' , req .headers ["content-type" ])
250- web_logger .mes ()
261+ # web_logger.mes()
251262 req .encoding = "utf-8"
252263 return req .text
253264 else :
@@ -298,7 +309,7 @@ def __run_query_string(self, active, query_string, is_post=False,
298309
299310class Main :
300311 def GET (self ):
301- web_logger .mes ()
312+ # web_logger.mes()
302313 current_subdomain = web .ctx .host .split ('.' )[0 ].lower ()
303314 return render .api (active = "" , sp_title = "" , sparql_endpoint = "" , current_subdomain = current_subdomain , render = render )
304315
@@ -362,7 +373,7 @@ def GET(self, dataset, call):
362373 web .header ('Content-Type' , "text/html" )
363374 web .header ('Access-Control-Allow-Methods' , '*' )
364375 web .header ('Access-Control-Allow-Headers' , 'Authorization' )
365- web_logger .mes ()
376+ # web_logger.mes()
366377 return doc .get_documentation ()[1 ]
367378 else :
368379 content_type = web .ctx .env .get ('HTTP_ACCEPT' )
@@ -391,7 +402,7 @@ def GET(self, dataset, call):
391402 web .header ('Access-Control-Allow-Methods' , '*' )
392403 web .header ('Access-Control-Allow-Headers' ,
393404 'Authorization' )
394- web_logger .mes ()
405+ # web_logger.mes()
395406 return res
396407 else :
397408 try :
0 commit comments