Loading services/TS29222_CAPIF_Events_API/capif_events/core/notifications.py +4 −18 Original line number Diff line number Diff line Loading @@ -19,21 +19,12 @@ class Notifications(): def send_notifications(self, event): current_app.logger.info("Received event, sending notifications") subscriptions = self.events_ops.get_event_subscriptions(event) # message, *ids = event.split(":") try: for sub in subscriptions: url = sub["notification_destination"] data = EventNotification(sub["subscription_id"], events=event) # details = CAPIFEventDetail() # if message == "ACCESS_CONTROL_POLICY_UPDATE": # current_app.logger.info("event: ACCESS_CONTROL_POLICY_UPDATE") # acls = self.events_ops.get_acls(ids[0]) # details.acc_ctrl_pol_list = AccessControlPolicyListExt(api_id=acls['service_id'], api_invoker_policies=acls['apiInvokerPolicies']) # data.event_detail=details self.request_post(url, data) #current_app.logger.info("notification sended") except Exception as e: current_app.logger.error("An exception occurred ::" + str(e)) Loading @@ -46,7 +37,6 @@ class Notifications(): current_app.logger.info("Received event " + redis_event.get('event') + ", sending notifications") subscriptions = self.events_ops.get_event_subscriptions(redis_event.get('event')) # message, *ids = event.split(":") current_app.logger.info(subscriptions) for sub in subscriptions: Loading @@ -54,24 +44,20 @@ class Notifications(): current_app.logger.debug(url) event_detail=None if redis_event.get('key', None) != None and redis_event.get('information', None) != None: # current_app.logger.debug(json.dumps(redis_event.get('information'),cls=JSONEncoder)) # event_detail=CAPIFEventDetail().from_dict({redis_event.get('key'):redis_event.get('information')}) # current_app.logger.debug(json.dumps(event_detail,cls=JSONEncoder)) event_detail={redis_event.get('key'):redis_event.get('information')} data = EventNotification(sub["subscription_id"], events=redis_event.get('event'), event_detail=event_detail) current_app.logger.debug(json.dumps(data,cls=JSONEncoder)) # self.request_post(url, data) asyncio.run(self.send(url, json.loads(json.dumps(data,cls=JSONEncoder)))) except Exception as e: current_app.logger.error("An exception occurred ::" + str(e)) return False # def request_post(self, url, data): # headers = {'content-type': 'application/json'} # return requests.post(url, json={'text': str(data.to_str())}, headers=headers) def request_post(self, url, data): headers = {'content-type': 'application/json'} return requests.post(url, json={'text': str(data.to_str())}, headers=headers) async def send_request(self, url, data): async with aiohttp.ClientSession() as session: Loading tests/libraries/api_logging_service/bodyRequests.py +10 −5 Original line number Diff line number Diff line def create_log_entry(aefId, apiInvokerId, apiId, apiName, results=['200']): def create_log_entry(aefId, apiInvokerId, apiId, apiName, results=['200','500'],api_versions=['v1','v2']): data = { "aefId": aefId, "apiInvokerId": apiInvokerId, Loading @@ -6,11 +6,16 @@ def create_log_entry(aefId, apiInvokerId, apiId, apiName, results=['200']): "supportedFeatures": "ffff" } if len(results) > 0: count=0 for result in results: data['logs'].append(create_log(apiId,apiName,result)) data['logs'].append(create_log(apiId,apiName,result,api_versions[count])) count=count+1 if count == len(api_versions): count=0 return data def create_log_entry_bad_service(aefId, apiInvokerId, result=500): def create_log_entry_bad_service(aefId, apiInvokerId, result='500'): data = { "aefId": aefId, "apiInvokerId": apiInvokerId, Loading Loading @@ -61,11 +66,11 @@ def get_api_ids_and_names_from_discover_response(discover_response): return api_ids, api_names def create_log(apiId, apiName, result): def create_log(apiId, apiName, result, api_version='v1'): log= { "apiId": apiId[0], "apiName": apiName[0], "apiVersion": "v1", "apiVersion": api_version, "resourceName": "string", "uri": "http://resource/endpoint", "protocol": "HTTP_1_1", Loading Loading
services/TS29222_CAPIF_Events_API/capif_events/core/notifications.py +4 −18 Original line number Diff line number Diff line Loading @@ -19,21 +19,12 @@ class Notifications(): def send_notifications(self, event): current_app.logger.info("Received event, sending notifications") subscriptions = self.events_ops.get_event_subscriptions(event) # message, *ids = event.split(":") try: for sub in subscriptions: url = sub["notification_destination"] data = EventNotification(sub["subscription_id"], events=event) # details = CAPIFEventDetail() # if message == "ACCESS_CONTROL_POLICY_UPDATE": # current_app.logger.info("event: ACCESS_CONTROL_POLICY_UPDATE") # acls = self.events_ops.get_acls(ids[0]) # details.acc_ctrl_pol_list = AccessControlPolicyListExt(api_id=acls['service_id'], api_invoker_policies=acls['apiInvokerPolicies']) # data.event_detail=details self.request_post(url, data) #current_app.logger.info("notification sended") except Exception as e: current_app.logger.error("An exception occurred ::" + str(e)) Loading @@ -46,7 +37,6 @@ class Notifications(): current_app.logger.info("Received event " + redis_event.get('event') + ", sending notifications") subscriptions = self.events_ops.get_event_subscriptions(redis_event.get('event')) # message, *ids = event.split(":") current_app.logger.info(subscriptions) for sub in subscriptions: Loading @@ -54,24 +44,20 @@ class Notifications(): current_app.logger.debug(url) event_detail=None if redis_event.get('key', None) != None and redis_event.get('information', None) != None: # current_app.logger.debug(json.dumps(redis_event.get('information'),cls=JSONEncoder)) # event_detail=CAPIFEventDetail().from_dict({redis_event.get('key'):redis_event.get('information')}) # current_app.logger.debug(json.dumps(event_detail,cls=JSONEncoder)) event_detail={redis_event.get('key'):redis_event.get('information')} data = EventNotification(sub["subscription_id"], events=redis_event.get('event'), event_detail=event_detail) current_app.logger.debug(json.dumps(data,cls=JSONEncoder)) # self.request_post(url, data) asyncio.run(self.send(url, json.loads(json.dumps(data,cls=JSONEncoder)))) except Exception as e: current_app.logger.error("An exception occurred ::" + str(e)) return False # def request_post(self, url, data): # headers = {'content-type': 'application/json'} # return requests.post(url, json={'text': str(data.to_str())}, headers=headers) def request_post(self, url, data): headers = {'content-type': 'application/json'} return requests.post(url, json={'text': str(data.to_str())}, headers=headers) async def send_request(self, url, data): async with aiohttp.ClientSession() as session: Loading
tests/libraries/api_logging_service/bodyRequests.py +10 −5 Original line number Diff line number Diff line def create_log_entry(aefId, apiInvokerId, apiId, apiName, results=['200']): def create_log_entry(aefId, apiInvokerId, apiId, apiName, results=['200','500'],api_versions=['v1','v2']): data = { "aefId": aefId, "apiInvokerId": apiInvokerId, Loading @@ -6,11 +6,16 @@ def create_log_entry(aefId, apiInvokerId, apiId, apiName, results=['200']): "supportedFeatures": "ffff" } if len(results) > 0: count=0 for result in results: data['logs'].append(create_log(apiId,apiName,result)) data['logs'].append(create_log(apiId,apiName,result,api_versions[count])) count=count+1 if count == len(api_versions): count=0 return data def create_log_entry_bad_service(aefId, apiInvokerId, result=500): def create_log_entry_bad_service(aefId, apiInvokerId, result='500'): data = { "aefId": aefId, "apiInvokerId": apiInvokerId, Loading Loading @@ -61,11 +66,11 @@ def get_api_ids_and_names_from_discover_response(discover_response): return api_ids, api_names def create_log(apiId, apiName, result): def create_log(apiId, apiName, result, api_version='v1'): log= { "apiId": apiId[0], "apiName": apiName[0], "apiVersion": "v1", "apiVersion": api_version, "resourceName": "string", "uri": "http://resource/endpoint", "protocol": "HTTP_1_1", Loading