diff --git a/services/TS29222_CAPIF_Events_API/capif_events/core/events_apis.py b/services/TS29222_CAPIF_Events_API/capif_events/core/events_apis.py index 09ad7f7e8822da44e627ac22d59b1cd20dd05c58..ef7c2ceaa199b4b6151ea1129fa42bdb9454bf48 100644 --- a/services/TS29222_CAPIF_Events_API/capif_events/core/events_apis.py +++ b/services/TS29222_CAPIF_Events_API/capif_events/core/events_apis.py @@ -54,6 +54,13 @@ class EventSubscriptionsOperations(Resource): current_app.logger.error("Bad url format") return bad_request_error(detail="Bad Param", cause = "Detected Bad formar of param", invalid_params=[{"param": "notificationDestination", "reason": "Not valid URL format"}]) + if event_subscription.supportedFeatures is None: + return bad_request_error( + detail="supportedFeatures must be present in this request", + cause="supportedFeatures missed", + invalid_params=[{"param": "supportedFeatures", "reason": "not defined"}] + ) + ## Verify that this subscriberID exist in publishers or invokers result = self.__check_subscriber_id(subscriber_id) @@ -124,6 +131,13 @@ class EventSubscriptionsOperations(Resource): mycol = self.db.get_col_by_name(self.db.event_collection) current_app.logger.debug("Updating event subscription") + + if event_subscription.supportedFeatures is None: + return bad_request_error( + detail="supportedFeatures must be present in this request", + cause="supportedFeatures missed", + invalid_params=[{"param": "supportedFeatures", "reason": "not defined"}] + ) result = self.__check_subscriber_id(subscriber_id) diff --git a/services/TS29222_CAPIF_Events_API/capif_events/core/notifications.py b/services/TS29222_CAPIF_Events_API/capif_events/core/notifications.py index 2c2528815c5834a81ab03491049b0557846ac225..27a7f3e075ceab3500ba51ec3428e200f1e8eb4d 100644 --- a/services/TS29222_CAPIF_Events_API/capif_events/core/notifications.py +++ b/services/TS29222_CAPIF_Events_API/capif_events/core/notifications.py @@ -33,18 +33,25 @@ class Notifications(): current_app.logger.debug(url) data = EventNotification(sub["subscription_id"], events=redis_event.get('event')) if redis_event.get('key', None) != None and redis_event.get('information', None) != None: - event_detail={} - for pos, key in enumerate(redis_event.get('key', None)): + if EventSubscription.return_supp_feat_dict(sub["supported_features"])["EnhancedEventReport"]: + event_detail={} + if redis_event.get('event', None) in ["SERVICE_API_AVAILABLE", "SERVICE_API_UNAVAILABLE"]: + event_detail["apiIds"]=redis_event.get('information', None)["apiIds"] + if EventSubscription.return_supp_feat_dict(sub["supported_features"])["ApiStatusMonitoring"] and "serviceAPIDescriptions" in redis_event.get('key', None): + event_detail["serviceAPIDescriptions"]=redis_event.get('information', None)["serviceAPIDescription"] + elif redis_event.get('event', None) in ["SERVICE_API_UPDATE"]: + event_detail["serviceAPIDescriptions"]=redis_event.get('information', None)["serviceAPIDescription"] + elif redis_event.get('event', None) in ["API_INVOKER_ONBOARDED", "API_INVOKER_OFFBOARDED", "API_INVOKER_UPDATED"]: + event_detail["apiInvokerIds"]=redis_event.get('information', None)["apiInvokerIds"] + elif redis_event.get('event', None) in ["ACCESS_CONTROL_POLICY_UPDATE"]: + event_detail["accCtrlPolList"]=redis_event.get('information', None)["accCtrlPolList"] + elif redis_event.get('event', None) in ["SERVICE_API_INVOCATION_SUCCESS", "SERVICE_API_INVOCATION_FAILURE"]: + event_detail["invocationLogs"]=redis_event.get('information', None)["invocationLogs"] + elif redis_event.get('event', None) in ["API_TOPOLOGY_HIDING_CREATED", "API_TOPOLOGY_HIDING_REVOKED"]: + event_detail["apiTopoHide"]=redis_event.get('information', None)["apiTopoHide"] - if sub["supported_features"] is None: - if not (key == "serviceAPIDescriptions" and redis_event.get('event', None) in ["SERVICE_API_AVAILABLE", "SERVICE_API_UNAVAILABLE"]): - event_detail[key]=redis_event.get('information', None)[pos] - else: - if not (redis_event.get('event', None) in ["SERVICE_API_AVAILABLE", "SERVICE_API_UNAVAILABLE"] and key == "serviceAPIDescriptions" and (not EventSubscription.return_supp_feat_dict(sub["supported_features"])["ApiStatusMonitoring"] or not EventSubscription.return_supp_feat_dict(sub["supported_features"])["EnhancedEventReport"])): - event_detail[key]=redis_event.get('information', None)[pos] - - current_app.logger.debug(event_detail) - data.event_detail=event_detail + current_app.logger.debug(event_detail) + data.event_detail=event_detail current_app.logger.debug(json.dumps(data.to_dict(),cls=CustomJSONEncoder))