diff --git a/config/capif_sdk_config.json b/config/capif_sdk_config.json index f76613236f6d5319187c3be9b169a79127ae7846..6feb89be61058c6f05ca6579c8721a394c4baeba 100644 --- a/config/capif_sdk_config.json +++ b/config/capif_sdk_config.json @@ -37,7 +37,50 @@ "api-supported-features": "", "ue-ip-addr": "", "service-kpis": "" + }, + "events":{ + "events": ["SERVICE_API_AVAILABLE"], + "eventFilters": [ + { + "apiIds": [ + "string" + ], + "apiInvokerIds": [ + "string" + ], + "aefIds": [ + "string" + ] + } + ], + "eventReq":{ + "immRep": true, + "notifMethod": "string", + "maxReportNbr": 5, + "monDur": "DATE-time", + "repPeriod": 5, + "sampRatio": "integer from 1 to 100", + "partitionCriteria": [ + "TAC" + ], + "grpRepTime": 3, + "notifFlag": "ACTIVATE", + "notifFlagInstruct": { + "bufferedNotifs":"SEND_ALL", + "subscription":"CLOSE" + }, + "mutingSetting": { + "maxNoOfNotif":5, + "durationBufferedNotif":5 + } + }, + "requestTestNotification": true, + "websockNotifConfig": { + "websocketUri":"", + "requestWebsocketUri": true + } } + }, "provider": { "provider_folder": "", diff --git a/opencapif_sdk/capif_event_feature.py b/opencapif_sdk/capif_event_feature.py new file mode 100644 index 0000000000000000000000000000000000000000..5e640a17d21f70fa2353ebfbe05999897fd52ee2 --- /dev/null +++ b/opencapif_sdk/capif_event_feature.py @@ -0,0 +1,101 @@ +from capif_invoker_connector import capif_invoker_connector +from capif_provider_connector import capif_provider_connector +import os +import logging +import shutil +from requests.auth import HTTPBasicAuth +import urllib3 +from OpenSSL.SSL import FILETYPE_PEM +from OpenSSL.crypto import ( + dump_certificate_request, + dump_privatekey, + PKey, + TYPE_RSA, + X509Req +) +import requests +import json +import warnings +from requests.exceptions import RequestsDependencyWarning +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) +warnings.filterwarnings("ignore", category=RequestsDependencyWarning) +# noqa: E501 +# Basic configuration of the logger functionality + +log_path = 'logs/sdk_logs.log' + +log_dir = os.path.dirname(log_path) + +if not os.path.exists(log_dir): + os.makedirs(log_dir) + +logging.basicConfig( + level=logging.NOTSET, # Minimum severity level to log + # Log message format + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + handlers=[ + logging.FileHandler(log_path), # Log to a file + logging.StreamHandler() # Also display in the console + ] +) + +class capif_invoker_event_feature(capif_invoker_connector): + + def create_subscription: + + invoker_capif_details = self.__load_invoker_api_details() + + subscriberId = invoker_capif_details["api_invoker_id"] + + path = self.capif_https_url + f"/{subscriberId}/subscriptions" + + payload = { + "events": [ + "SERVICE_API_AVAILABLE", + "string" + ], + "eventFilters": [ + { + "apiIds": [ + "string" + ], + "apiInvokerIds": [ + "string" + ], + "aefIds": [ + "string" + ] + } + ], + "eventReq": "string", + "notificationDestination": f"{self.capif_callback_url}", + "requestTestNotification": true, + "websockNotifConfig": "string", + } + + + try: + response = requests.post( + url=path, + json=payload, + headers={"Content-Type": "application/json"}, + cert=cert, + verify=os.path.join(self.invoker_folder, "ca.crt") + ) + + response.raise_for_status() + + return response.status_code, response.json() + + except Exception as e: + self.logger.error("Unexpected error: %s", e) + return None, {"error": f"Unexpected error: {e}"} + + + def delete_subcription: + + def modify_subcription: + + def patch_subcription: + + \ No newline at end of file