Skip to content

Commit cd48f2a

Browse files
authored
Merge pull request #76 from medianetlab/develop
Merge develop in main
2 parents 3fed7f9 + 2a3f5b8 commit cd48f2a

File tree

12 files changed

+502
-95
lines changed

12 files changed

+502
-95
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
*.csr
77
*.pem
88
backend/app/app/core/certificates/capif_provider_details.json
9+
backend/app/app/core/certificates/CAPIF_service_as_session_with_qos.json
10+
backend/app/app/core/certificates/CAPIF_service_monitoring_event.json
911
venv/

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
# Changelog
2+
## v2.1.0
3+
4+
***Summary:***
5+
> - *Add functionality to support CAPIF Core Function's logging service*
6+
> - *Avoid db connections within the threads (optimisation)*
7+
> - *Fix token causing 403 error in mapbox front-end*
8+
<br><br>
9+
210
## v2.0.0
311

412
***Summary:***

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ build:
3535
build-no-cache:
3636
docker compose --profile debug build --no-cache --pull
3737

38-
logs:
39-
docker compose logs -f
38+
logs-dev:
39+
docker compose --profile dev logs -f
40+
41+
logs-debug:
42+
docker compose --profile debug logs -f
4043

4144
logs-backend:
4245
docker compose logs -f backend

backend/app/app/api/api_v1/endpoints/monitoringevent.py

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
from app.api import deps
99
from app import tools
1010
from app.db.session import client
11-
from app.api.api_v1.endpoints.utils import add_notifications
11+
from app.api.api_v1.endpoints.utils import add_notifications, ccf_logs
1212
from .ue_movement import retrieve_ue_state, retrieve_ue
13+
import logging
1314

1415
router = APIRouter()
1516
db_collection= 'MonitoringEvent'
@@ -41,6 +42,16 @@ def read_active_subscriptions(
4142
if retrieved_docs:
4243
http_response = JSONResponse(content=retrieved_docs, status_code=200)
4344
add_notifications(http_request, http_response, False)
45+
#CAPIF Core Function Logging Service
46+
try:
47+
response = http_response.body.decode("utf-8")
48+
json_response = {}
49+
json_response.update({"response" : response})
50+
json_response.update({"status_code" : str(http_response.status_code)})
51+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
52+
except TypeError as error:
53+
logging.critical(f"Error: {error}")
54+
4455
return http_response
4556
else:
4657
return Response(status_code=204)
@@ -72,6 +83,14 @@ def create_subscription(
7283

7384
UE = ue.get_externalId(db=db, externalId=str(item_in.externalId), owner_id=current_user.id)
7485
if not UE:
86+
#CAPIF Core Function Logging Service
87+
try:
88+
json_response = {}
89+
json_response.update({"response" : "UE with this external identifier doesn't exist"})
90+
json_response.update({"status_code" : "409"})
91+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
92+
except TypeError as error:
93+
logging.critical(f"Error: {error}")
7594
raise HTTPException(status_code=409, detail="UE with this external identifier doesn't exist")
7695

7796

@@ -98,12 +117,30 @@ def create_subscription(
98117
http_response = JSONResponse(content=json_compatible_item_data, status_code=200)
99118
add_notifications(http_request, http_response, False)
100119

120+
#CAPIF Core Function Logging Service
121+
try:
122+
response = http_response.body.decode("utf-8")
123+
json_response = {}
124+
json_response.update({"response" : response})
125+
json_response.update({"status_code" : str(http_response.status_code)})
126+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
127+
except TypeError as error:
128+
logging.error(f"Error: {error}")
129+
101130
return http_response
102131
#Subscription
103132
elif item_in.monitoringType == "LOCATION_REPORTING" and item_in.maximumNumberOfReports>1:
104133

105134
#Check if subscription with externalid exists
106135
if crud_mongo.read_by_multiple_pairs(db_mongo, db_collection, externalId = item_in.externalId, monitoringType = item_in.monitoringType):
136+
#CAPIF Core Function Logging Service
137+
try:
138+
json_response = {}
139+
json_response.update({"response" : f"There is already an active subscription for UE with external id {item_in.externalId} - Monitoring Type = {item_in.monitoringType}"})
140+
json_response.update({"status_code" : "409"})
141+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
142+
except TypeError as error:
143+
logging.critical(f"Error: {error}")
107144
raise HTTPException(status_code=409, detail=f"There is already an active subscription for UE with external id {item_in.externalId} - Monitoring Type = {item_in.monitoringType}")
108145

109146
json_data = jsonable_encoder(item_in.dict(exclude_unset=True))
@@ -126,8 +163,27 @@ def create_subscription(
126163
http_response = JSONResponse(content=updated_doc, status_code=201, headers=response_header)
127164
add_notifications(http_request, http_response, False)
128165

166+
#CAPIF Core Function Logging Service
167+
try:
168+
response = http_response.body.decode("utf-8")
169+
json_response = {}
170+
json_response.update({"response" : response})
171+
json_response.update({"status_code" : str(http_response.status_code)})
172+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
173+
except TypeError as error:
174+
logging.error(f"Error: {error}")
175+
129176
return http_response
130177
elif (item_in.monitoringType == "LOSS_OF_CONNECTIVITY" or item_in.monitoringType == "UE_REACHABILITY") and item_in.maximumNumberOfReports == 1:
178+
179+
#CAPIF Core Function Logging Service
180+
try:
181+
json_response = {}
182+
json_response.update({"response" : "\"maximumNumberOfReports\" should be greater than 1 in case of LOSS_OF_CONNECTIVITY event"})
183+
json_response.update({"status_code" : "403"})
184+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
185+
except TypeError as error:
186+
logging.critical(f"Error: {error}")
131187
return JSONResponse(content=jsonable_encoder(
132188
{
133189
"title" : "The requested parameters are out of range",
@@ -140,6 +196,14 @@ def create_subscription(
140196
elif (item_in.monitoringType == "LOSS_OF_CONNECTIVITY" or item_in.monitoringType == "UE_REACHABILITY") and item_in.maximumNumberOfReports > 1:
141197
#Check if subscription with externalid && monitoringType exists
142198
if crud_mongo.read_by_multiple_pairs(db_mongo, db_collection, externalId = item_in.externalId, monitoringType = item_in.monitoringType):
199+
#CAPIF Core Function Logging Service
200+
try:
201+
json_response = {}
202+
json_response.update({"response" : f"There is already an active subscription for UE with external id {item_in.externalId} - Monitoring Type = {item_in.monitoringType}"})
203+
json_response.update({"status_code" : "409"})
204+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
205+
except TypeError as error:
206+
logging.critical(f"Error: {error}")
143207
raise HTTPException(status_code=409, detail=f"There is already an active subscription for UE with external id {item_in.externalId} - Monitoring Type = {item_in.monitoringType}")
144208

145209
json_data = jsonable_encoder(item_in.dict(exclude_unset=True))
@@ -161,6 +225,16 @@ def create_subscription(
161225

162226
http_response = JSONResponse(content=updated_doc, status_code=201, headers=response_header)
163227
add_notifications(http_request, http_response, False)
228+
229+
#CAPIF Core Function Logging Service
230+
try:
231+
response = http_response.body.decode("utf-8")
232+
json_response = {}
233+
json_response.update({"response" : response})
234+
json_response.update({"status_code" : str(http_response.status_code)})
235+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
236+
except TypeError as error:
237+
logging.error(f"Error: {error}")
164238

165239
return http_response
166240

@@ -183,10 +257,26 @@ def update_subscription(
183257
try:
184258
retrieved_doc = crud_mongo.read_uuid(db_mongo, db_collection, subscriptionId)
185259
except Exception as ex:
260+
#CAPIF Core Function Logging Service
261+
try:
262+
json_response = {}
263+
json_response.update({"response" : "Please enter a valid uuid (24-character hex string)"})
264+
json_response.update({"status_code" : "400"})
265+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
266+
except TypeError as error:
267+
logging.critical(f"Error: {error}")
186268
raise HTTPException(status_code=400, detail='Please enter a valid uuid (24-character hex string)')
187269

188270
#Check if the document exists
189271
if not retrieved_doc:
272+
#CAPIF Core Function Logging Service
273+
try:
274+
json_response = {}
275+
json_response.update({"response" : "Subscription not found"})
276+
json_response.update({"status_code" : "404"})
277+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
278+
except TypeError as error:
279+
logging.critical(f"Error: {error}")
190280
raise HTTPException(status_code=404, detail="Subscription not found")
191281
#If the document exists then validate the owner
192282
if not user.is_superuser(current_user) and (retrieved_doc['owner_id'] != current_user.id):
@@ -205,6 +295,17 @@ def update_subscription(
205295

206296
http_response = JSONResponse(content=updated_doc, status_code=200)
207297
add_notifications(http_request, http_response, False)
298+
299+
#CAPIF Core Function Logging Service
300+
try:
301+
response = http_response.body.decode("utf-8")
302+
json_response = {}
303+
json_response.update({"response" : response})
304+
json_response.update({"status_code" : str(http_response.status_code)})
305+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
306+
except TypeError as error:
307+
logging.error(f"Error: {error}")
308+
208309
return http_response
209310
else:
210311
crud_mongo.delete_by_uuid(db_mongo, db_collection, subscriptionId)
@@ -228,10 +329,25 @@ def read_subscription(
228329
try:
229330
retrieved_doc = crud_mongo.read_uuid(db_mongo, db_collection, subscriptionId)
230331
except Exception as ex:
332+
try:
333+
json_response = {}
334+
json_response.update({"response" : "Please enter a valid uuid (24-character hex string)"})
335+
json_response.update({"status_code" : "400"})
336+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
337+
except TypeError as error:
338+
logging.critical(f"Error: {error}")
231339
raise HTTPException(status_code=400, detail='Please enter a valid uuid (24-character hex string)')
232340

233341
#Check if the document exists
234342
if not retrieved_doc:
343+
#CAPIF Core Function Logging Service
344+
try:
345+
json_response = {}
346+
json_response.update({"response" : "Subscription not found"})
347+
json_response.update({"status_code" : "404"})
348+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
349+
except TypeError as error:
350+
logging.critical(f"Error: {error}")
235351
raise HTTPException(status_code=404, detail="Subscription not found")
236352
#If the document exists then validate the owner
237353
if not user.is_superuser(current_user) and (retrieved_doc['owner_id'] != current_user.id):
@@ -244,6 +360,17 @@ def read_subscription(
244360
http_response = JSONResponse(content=retrieved_doc, status_code=200)
245361

246362
add_notifications(http_request, http_response, False)
363+
364+
#CAPIF Core Function Logging Service
365+
try:
366+
response = http_response.body.decode("utf-8")
367+
json_response = {}
368+
json_response.update({"response" : response})
369+
json_response.update({"status_code" : str(http_response.status_code)})
370+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
371+
except TypeError as error:
372+
logging.error(f"Error: {error}")
373+
247374
return http_response
248375
else:
249376
crud_mongo.delete_by_uuid(db_mongo, db_collection, subscriptionId)
@@ -266,10 +393,25 @@ def delete_subscription(
266393
try:
267394
retrieved_doc = crud_mongo.read_uuid(db_mongo, db_collection, subscriptionId)
268395
except Exception as ex:
396+
try:
397+
json_response = {}
398+
json_response.update({"response" : "Please enter a valid uuid (24-character hex string)"})
399+
json_response.update({"status_code" : "400"})
400+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
401+
except TypeError as error:
402+
logging.critical(f"Error: {error}")
269403
raise HTTPException(status_code=400, detail='Please enter a valid uuid (24-character hex string)')
270404

271405
#Check if the document exists
272406
if not retrieved_doc:
407+
#CAPIF Core Function Logging Service
408+
try:
409+
json_response = {}
410+
json_response.update({"response" : "Subscription not found"})
411+
json_response.update({"status_code" : "404"})
412+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
413+
except TypeError as error:
414+
logging.critical(f"Error: {error}")
273415
raise HTTPException(status_code=404, detail="Subscription not found")
274416
#If the document exists then validate the owner
275417
if not user.is_superuser(current_user) and (retrieved_doc['owner_id'] != current_user.id):
@@ -280,6 +422,17 @@ def delete_subscription(
280422

281423
http_response = JSONResponse(content=retrieved_doc, status_code=200)
282424
add_notifications(http_request, http_response, False)
425+
426+
#CAPIF Core Function Logging Service
427+
try:
428+
response = http_response.body.decode("utf-8")
429+
json_response = {}
430+
json_response.update({"response" : response})
431+
json_response.update({"status_code" : str(http_response.status_code)})
432+
ccf_logs(http_request, json_response, "service_monitoring_event.json", token_payload.get("sub"))
433+
except TypeError as error:
434+
logging.error(f"Error: {error}")
435+
283436
return http_response
284437

285438

0 commit comments

Comments
 (0)