From 58ea7d1836ce0efa97ec114c721c8f14d9280562 Mon Sep 17 00:00:00 2001 From: Jorge Echevarria Uribarri <jorge.echevarriauribarri.practicas@telefonica.com> Date: Fri, 8 Nov 2024 12:23:10 +0100 Subject: [PATCH] Fix license apache2 (#8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR: * SDK packaging in pypi repositories to install via pip opencapif_sdk atifact and simple import commands, * OpenCAPIF SDK installation process clarified and updated, * Pictures of OpenCAPIF flows adjusted, * Updated scripts and test to new installation process, * Updated general documentation, * Small mistakes and typos fixed. --------- Co-authored-by: Daniel GarcÃa <daniel.garciasanchez@telefonica.com> Co-authored-by: JorgeEcheva26 <jorge.echevarriauribarri.practicas@telefonica.es> --- README.md | 25 ++++++++++++++----- doc/sdk_configuration.md | 4 +-- doc/sdk_developers.md | 8 ++---- doc/sdk_full_documentation.md | 2 +- .../capif_sdk_config_sample.json | 4 +-- .../network_app_invoker.py | 16 +++--------- .../capif_sdk_config_sample.json | 2 +- .../network_app_provider.py | 13 +++------- pyproject.toml | 10 ++++---- samples/config_sample.json | 2 +- samples/enviroment_variables_sample.txt | 4 +-- scripts/invoker_capif_connector.py | 5 ---- .../invoker_capif_connector_offboarding.py | 5 ---- scripts/invoker_capif_connector_update.py | 5 ---- scripts/invoker_service_discovery.py | 10 -------- scripts/invoker_service_get_token.py | 10 -------- scripts/provider_capif_connector.py | 7 ------ .../provider_capif_connector_offboarding.py | 7 ------ scripts/provider_capif_connector_update.py | 10 +------- scripts/provider_get_all_published_api.py | 9 ------- scripts/provider_get_published_api.py | 10 -------- scripts/provider_publish_api.py | 10 -------- scripts/provider_unpublish_api.py | 8 ------ scripts/provider_update_api.py | 10 -------- sdk/__init__.py | 3 +++ sdk/capif_invoker_connector.py | 6 ++--- sdk/capif_provider_connector.py | 2 +- sdk/sdk.py | 3 --- sdk/service_discoverer.py | 13 +++++----- setup.py | 9 +++++++ test/test.py | 8 ++---- 31 files changed, 68 insertions(+), 172 deletions(-) create mode 100644 sdk/__init__.py delete mode 100644 sdk/sdk.py create mode 100644 setup.py diff --git a/README.md b/README.md index a3cf02f..608ae1f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # OpenCAPIF SDK +[](https://pypi.org/project/opencapif-sdk/) [](https://opensource.org/licenses/Apache-2.0)  [](https://pypi.org/project/opencapif-sdk/)  @@ -18,16 +19,16 @@ This document serves as the [main bootstrap reference](#networkapp-developer-pat 2. [Network App developers](#network-app-developers) 3. [OpenCAPIF SDK summary](#opencapif-sdk-summary) 4. [OpenCAPIF SDK requirements](#opencapif-sdk-requirements) - 5. [OpenCAPIF SDK data schema](#opencapif-sdk-data-schema) - 6. [OpenCAPIF SDK Configuration](./doc/sdk_configuration.md) - 7. [Network App developer path](#network-app-developer-path) + 5. [OpenCAPIF sdk installation](#opencapif-sdk-installation) + 6. [OpenCAPIF SDK data schema](#opencapif-sdk-data-schema) + 7. [OpenCAPIF SDK Configuration](./doc/sdk_configuration.md) + 8. [Network App developer path](#network-app-developer-path) 1. [Provider Network App](#provider-network-app) * [Provider Network App sample](#provider-network-app-sample) 2. [Invoker Network App](#invoker-network-app) * [Provider Network App sample](#provider-network-app-sample) - 8. [**OpenCAPIF SDK full documentation**](./doc/sdk_full_documentation.md) - 9. [OpenCAPIF SDK known issues](#opencapif-sdk-known-issues) - 10. [OpenCAPIF SDK developers](./doc/sdk_developers.md) + 9. [**OpenCAPIF SDK full documentation**](./doc/sdk_full_documentation.md) + 10. [OpenCAPIF SDK known issues](#opencapif-sdk-known-issues) # Repository structure @@ -113,6 +114,16 @@ To use the OpenCAPIF SDK, a registered user account within the target CAPIF inst **Contact the administrator to obtain the required predefined credentials (CAPIF username and password).** +## OpenCAPIF SDK installation + +To install the OpenCAPIF SDK source code for developing purposes there is an available section: [OpenCAPIF SDK developers](./doc/sdk_developers.md). + +To use the SDK, binary installer for the latest version is available at the [Python Package Index (Pipy)](https://pypi.org/project/opencapif-sdk/) + +```python +pip install opencapif_sdk +``` + ## OpenCAPIF SDK Data Schema Here is a visual look on the variables of the CAPIF sdk referenced in: @@ -136,6 +147,7 @@ A Network App development running as a Provider would typically follow this proc Now, it is described in 4 simple steps how a Provider can be developed in just some code lines, below snippet. It describes the usual flow a Provider would follow to publish an API service. ```python + from sdk import capif_provider_connector provider = capif_provider_connector(config_file="path/to/the/capif_sdk_config.json") provider.onboard_provider() provider.api_description_path = "./nef_upf_vendor_1.json" @@ -212,6 +224,7 @@ A Network App development running as an Invoker would typically follow this proc Now, it is described in some simple steps how an Invoker can be developed in just some code lines. Find below the code snippet. It describes the usual flow an Invoker would follow to consume APIs from CAPIF. ```python + from sdk import capif_invoker_connector,service_discoverer invoker = capif_invoker_connector(config_file="path/to/the/capif_sdk_config.json") invoker.onboard_invoker() service_discoverer = service_discoverer(config_file="path/to/the/capif_sdk_config.json") diff --git a/doc/sdk_configuration.md b/doc/sdk_configuration.md index a9a0b21..f50ee86 100644 --- a/doc/sdk_configuration.md +++ b/doc/sdk_configuration.md @@ -36,7 +36,7 @@ When configuring the SDK as a **Network App Invoker**, the following fields must **Optional:** - `discover_filter`: useful to enable the discovery of specific APIs. Some fields under [`discover_filter`](#configuration-of-discover_filter) structure required to be configured when using discovery filters. Check devoted section below, -- `check_authentication`: useful to use `check_authentication()` function to validate features from a target provider, it will be required to fill up the `ip` and `port` parameters within the `check_authentication` variable. +- `check_authentication_data`: useful to use `check_authentication()` function to validate features from a target provider, it will be required to fill up the `ip` and `port` parameters within the `check_authentication_data` variable. ### Network App Provider @@ -91,7 +91,7 @@ This file can also be populated using [environment variables](../samples/envirom - [`discover_filter`](#configuration-of-discover_filter): Fields for configuring invoker service discovery. - [`publish_req`](#configuration-of-publish_req): Fields required for API publishing. - `api_description_path`: The path to the [ServiceAPIDescription](https://github.com/jdegre/5GC_APIs/blob/Rel-18/TS29222_CAPIF_Publish_Service_API.yaml) JSON file. -- `check_authentication`: The `ip` and `port` of the target Provider's AEF to get their supported features from. +- `check_authentication_data`: The `ip` and `port` of the target Provider's AEF to get their supported features from. ## Configuration via `capif_sdk_register.json` diff --git a/doc/sdk_developers.md b/doc/sdk_developers.md index 32820cc..0026e3d 100644 --- a/doc/sdk_developers.md +++ b/doc/sdk_developers.md @@ -1,8 +1,6 @@ # OpenCAPIF SDK Development Environment Installation -Currently, the OpenCAPIF SDK is only available by downloading this repository and performing a manual installation. In the future, an OpenCAPIF SDK package will be released for easier installation. - Before proceeding, ensure you have fulfilled the necessary [requirements](../README.md). Follow the steps below to install the OpenCAPIF SDK for development purposes: @@ -55,12 +53,10 @@ OPTIONAL step: For Arm64 architecture sometimes will appear this problem This article explains how to solve it [here](https://laict.medium.com/install-python-on-macos-11-m1-apple-silicon-using-pyenv-12e0729427a9) - - 2. Clone GitHub repository: ```console -git clone -b sdk_v0.1 --single-branch https://github.com/Telefonica/pesp_capif_sdk.git +git clone https://github.com/Telefonica/pesp_capif_sdk.git ``` ```console @@ -69,7 +65,7 @@ git clone -b sdk_v0.1 --single-branch https://github.com/Telefonica/pesp_capif_s cd /the/path/to/pesp_capif_sdk ``` -3. Install the Python requirements listed in requirements.txt file: +3. Install the Python requirements listed in [requirements.txt](../installation/requirements.txt) file: ```console cd installation diff --git a/doc/sdk_full_documentation.md b/doc/sdk_full_documentation.md index 6dc3c6d..7c201a7 100644 --- a/doc/sdk_full_documentation.md +++ b/doc/sdk_full_documentation.md @@ -214,7 +214,7 @@ The SDK allows the Network App Invoker to check the `supported_features` from th It is mandatory to have obtained the [JWT token](#obtain-jwt-tokens) previously. **Required SDK inputs**: -- check_authentication +- check_authentication_data  diff --git a/network_app_samples/network_app_invoker_sample/capif_sdk_config_sample.json b/network_app_samples/network_app_invoker_sample/capif_sdk_config_sample.json index aa58c93..806d47d 100644 --- a/network_app_samples/network_app_invoker_sample/capif_sdk_config_sample.json +++ b/network_app_samples/network_app_invoker_sample/capif_sdk_config_sample.json @@ -5,12 +5,12 @@ "capif_register_port": "36211", "capif_username": "echeva_0", "capif_password": "echevapass", - "debug_mode": "False", + "debug_mode": "True", "invoker":{ "invoker_folder": "/Users/IDB0128/Documents/OpenCapif/test_invoker_certificate_folder", "capif_callback_url": "http://localhost:5000", "supported_features":"fffffff", - "check_authentication":{ + "check_authentication_data":{ "ip":"", "port":"" }, diff --git a/network_app_samples/network_app_invoker_sample/network_app_invoker.py b/network_app_samples/network_app_invoker_sample/network_app_invoker.py index e3c1e62..5c02fe5 100644 --- a/network_app_samples/network_app_invoker_sample/network_app_invoker.py +++ b/network_app_samples/network_app_invoker_sample/network_app_invoker.py @@ -1,15 +1,6 @@ import json -import sys -import os import time import requests - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', '..', 'sdk') # Go up two levels and point to 'sdk' -sys.path.insert(0, sdk_path) - -# Import necessary classes from the SDK from sdk import capif_invoker_connector, service_discoverer # Path to the OpenCAPIF SDK configuration file @@ -95,13 +86,12 @@ if __name__ == "__main__": while True: discoverer.get_tokens() - details = discoverer.invoker_capif_details + """ details = discoverer.invoker_capif_details lenght = len(details["registered_security_contexes"]) ip = details["registered_security_contexes"][lenght-1]["aef_profiles"][0]["ip"] port = details["registered_security_contexes"][lenght-1]["aef_profiles"][0]["port"] - discoverer.check_authentication["ip"] = ip - discoverer.check_authentication["port"] = port - discoverer.check_authentication() + discoverer.check_authentication_data.update({"ip": ip, "port": port}) + discoverer.check_authentication() """ # Load API details from the JSON file token = discoverer.token diff --git a/network_app_samples/network_app_provider_sample/capif_sdk_config_sample.json b/network_app_samples/network_app_provider_sample/capif_sdk_config_sample.json index b93180a..2782ab0 100644 --- a/network_app_samples/network_app_provider_sample/capif_sdk_config_sample.json +++ b/network_app_samples/network_app_provider_sample/capif_sdk_config_sample.json @@ -9,7 +9,7 @@ "invoker":{ "invoker_folder": "", "capif_callback_url": "", - "check_authentication":{ + "check_authentication_data":{ "ip":"", "port":"" }, diff --git a/network_app_samples/network_app_provider_sample/network_app_provider.py b/network_app_samples/network_app_provider_sample/network_app_provider.py index 24078fc..8bd6c84 100644 --- a/network_app_samples/network_app_provider_sample/network_app_provider.py +++ b/network_app_samples/network_app_provider_sample/network_app_provider.py @@ -1,17 +1,12 @@ import threading +from sdk import capif_provider_connector from OpenSSL import crypto from flask_jwt_extended import jwt_required, JWTManager from flask import Flask, jsonify, request, redirect -import sys -import os import json from werkzeug import serving -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', '..', 'sdk') # Go up two levels and point to 'sdk' -sys.path.insert(0, sdk_path) -from sdk import capif_provider_connector + capif_sdk_config_path = "./capif_sdk_config_sample.json" @@ -256,7 +251,7 @@ def manage_slices(): @Network_app.route("/aef-security/v1/check-authentication", methods=["POST"]) @jwt_required() -def custom_operation_check(): +def custom_operation_check_2(): if request.method == "POST": try: # Extraer el JSON del cuerpo del request @@ -279,7 +274,6 @@ def custom_operation_check(): return jsonify({"error": str(e)}), 500 - @Network_app.route("/slice/<sliceId>", methods=["GET", "PUT", "DELETE"]) @jwt_required() def manage_single_slice(sliceId): @@ -315,6 +309,7 @@ if __name__ == "__main__": # Initialize the connector capif_connector = capif_provider_connector(config_file=capif_sdk_config_path) print("PROVIDER ONBOARDING COMPLETED") + capif_connector.onboard_provider() capif_connector.api_description_path = "./nef_upf_vendor_1.json" diff --git a/pyproject.toml b/pyproject.toml index 936d205..ce53b20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,17 +3,17 @@ requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [project] -name = "pesp-capif-sdk" -version = "0.0.1" +name = "opencapif_sdk" +version = "0.1.7" authors = [ - { name="JorgeEcheva", email="jorge.echevarriauribarri.practicas@telefonica.com" } + { name="JorgeEcheva", email="jorge.echevarriauribarri.practicas@telefonica.com" }, + { name="dgs-cgm", email="daniel.garciasanchez@telefonica.com" } ] description = "This repository develops a Python Software Development Kit(SDK) which focuses on connecting to OpenCAPIF (Common API Framework for 3GPP Northbound APIs) in a simple way, lowering integration complexity and allowing developers to focus on Network Applications (Network Apps) or services development." readme = "README.md" license = { file="LICENSE" } requires-python = ">=3.9" -[project] -keywords = ["pesp-capif-sdk","capif","sdk capif"] +keywords = ["pesp_capif_sdk","capif","sdk capif","opencapif_sdk"] dependencies = [ "argh==0.31.3", "arrow==1.3.0", diff --git a/samples/config_sample.json b/samples/config_sample.json index a634241..7a1d6ae 100644 --- a/samples/config_sample.json +++ b/samples/config_sample.json @@ -10,7 +10,7 @@ "invoker_folder": "", "capif_callback_url": "", "supported_features":"", - "check_authentication":{ + "check_authentication_data":{ "ip":"", "port":"" }, diff --git a/samples/enviroment_variables_sample.txt b/samples/enviroment_variables_sample.txt index 8e76ace..e7c4a06 100644 --- a/samples/enviroment_variables_sample.txt +++ b/samples/enviroment_variables_sample.txt @@ -20,8 +20,8 @@ export INVOKER_CSR_STATE_OR_PROVINCE_NAME=your_state_or_province export INVOKER_CSR_COUNTRY_NAME=your_country_name export INVOKER_CSR_EMAIL_ADDRESS=your_email_address -export INVOKER_CHECK_AUTHENTICATION_IP = -export INVOKER_CHECK_AUTHENTICATION_PORT = +export INVOKER_CHECK_AUTHENTICATION_DATA_IP = +export INVOKER_CHECK_AUTHENTICATION_DATA_PORT = #DISCOVER FILTER export DISCOVER_FILTER_API_NAME="" export DISCOVER_FILTER_API_VERSION="" diff --git a/scripts/invoker_capif_connector.py b/scripts/invoker_capif_connector.py index bcac3b5..609f97d 100755 --- a/scripts/invoker_capif_connector.py +++ b/scripts/invoker_capif_connector.py @@ -1,11 +1,6 @@ import sys import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) from sdk import capif_invoker_connector def showcase_capif_connector(): diff --git a/scripts/invoker_capif_connector_offboarding.py b/scripts/invoker_capif_connector_offboarding.py index 2e59cd3..3f5f67d 100755 --- a/scripts/invoker_capif_connector_offboarding.py +++ b/scripts/invoker_capif_connector_offboarding.py @@ -1,11 +1,6 @@ import sys import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) from sdk import capif_invoker_connector def showcase_offboard_and_deregister_invoker(): diff --git a/scripts/invoker_capif_connector_update.py b/scripts/invoker_capif_connector_update.py index ba0665b..8052c29 100644 --- a/scripts/invoker_capif_connector_update.py +++ b/scripts/invoker_capif_connector_update.py @@ -1,11 +1,6 @@ import sys import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) from sdk import capif_invoker_connector def showcase_capif_connector(): diff --git a/scripts/invoker_service_discovery.py b/scripts/invoker_service_discovery.py index e9c035e..0084ada 100755 --- a/scripts/invoker_service_discovery.py +++ b/scripts/invoker_service_discovery.py @@ -1,14 +1,4 @@ -import sys -import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) - -# Now import the classes from your sdk.py file - from sdk import service_discoverer def showcase_access_token_retrieval_from_capif(): service_discoverer = service_discoverer(config_file=utilities.get_config_file()) diff --git a/scripts/invoker_service_get_token.py b/scripts/invoker_service_get_token.py index f6095bb..be1b0ee 100755 --- a/scripts/invoker_service_get_token.py +++ b/scripts/invoker_service_get_token.py @@ -1,14 +1,4 @@ -import sys -import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) - -# Now import the classes from your sdk.py file - from sdk import service_discoverer def showcase_access_token_retrieval_from_capif(): service_discoverer = service_discoverer(config_file=utilities.get_config_file()) diff --git a/scripts/provider_capif_connector.py b/scripts/provider_capif_connector.py index 4c46482..5c639fd 100755 --- a/scripts/provider_capif_connector.py +++ b/scripts/provider_capif_connector.py @@ -1,11 +1,4 @@ -import sys -import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) from sdk import capif_provider_connector # Now import the classes from your sdk.py file diff --git a/scripts/provider_capif_connector_offboarding.py b/scripts/provider_capif_connector_offboarding.py index 642fb27..4a676e1 100755 --- a/scripts/provider_capif_connector_offboarding.py +++ b/scripts/provider_capif_connector_offboarding.py @@ -1,11 +1,4 @@ -import sys -import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) from sdk import capif_provider_connector def offboard_capif_nef_connector(): diff --git a/scripts/provider_capif_connector_update.py b/scripts/provider_capif_connector_update.py index 53b3e8a..32875c5 100644 --- a/scripts/provider_capif_connector_update.py +++ b/scripts/provider_capif_connector_update.py @@ -1,12 +1,4 @@ -import sys -import os -import utilities - - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) +import utilities from sdk import capif_provider_connector def showcase_capif_nef_connector(): diff --git a/scripts/provider_get_all_published_api.py b/scripts/provider_get_all_published_api.py index f9cbb0c..467ea7f 100644 --- a/scripts/provider_get_all_published_api.py +++ b/scripts/provider_get_all_published_api.py @@ -1,13 +1,4 @@ -import sys -import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) - -# Now import the classes from your sdk.py file from sdk import capif_provider_connector def showcase_capif_nef_connector(): diff --git a/scripts/provider_get_published_api.py b/scripts/provider_get_published_api.py index 5ffd0bb..12f0d29 100644 --- a/scripts/provider_get_published_api.py +++ b/scripts/provider_get_published_api.py @@ -1,14 +1,4 @@ -import sys -import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) - -# Now import the classes from your sdk.py file - from sdk import capif_provider_connector def showcase_capif_nef_connector(): diff --git a/scripts/provider_publish_api.py b/scripts/provider_publish_api.py index 646e86f..7020f79 100644 --- a/scripts/provider_publish_api.py +++ b/scripts/provider_publish_api.py @@ -1,14 +1,4 @@ -import sys -import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) - -# Now import the classes from your sdk.py file - from sdk import capif_provider_connector def showcase_capif_nef_connector(): diff --git a/scripts/provider_unpublish_api.py b/scripts/provider_unpublish_api.py index 81ab9e2..719ecda 100644 --- a/scripts/provider_unpublish_api.py +++ b/scripts/provider_unpublish_api.py @@ -1,13 +1,5 @@ -import sys -import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) from sdk import capif_provider_connector -# Now import the classes from your sdk.py file def showcase_capif_nef_connector(): """ diff --git a/scripts/provider_update_api.py b/scripts/provider_update_api.py index 8ac9548..e86b861 100644 --- a/scripts/provider_update_api.py +++ b/scripts/provider_update_api.py @@ -1,14 +1,4 @@ -import sys -import os import utilities - -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up one level and point to 'sdk' -sys.path.insert(0, sdk_path) - -# Now import the classes from your sdk.py file - from sdk import capif_provider_connector def showcase_capif_nef_connector(): diff --git a/sdk/__init__.py b/sdk/__init__.py new file mode 100644 index 0000000..f2797c5 --- /dev/null +++ b/sdk/__init__.py @@ -0,0 +1,3 @@ +from sdk.capif_invoker_connector import capif_invoker_connector +from sdk.capif_provider_connector import capif_provider_connector +from sdk.service_discoverer import service_discoverer \ No newline at end of file diff --git a/sdk/capif_invoker_connector.py b/sdk/capif_invoker_connector.py index e43a947..20734aa 100644 --- a/sdk/capif_invoker_connector.py +++ b/sdk/capif_invoker_connector.py @@ -83,10 +83,10 @@ class capif_invoker_connector: capif_callback_url = os.getenv('INVOKER_CAPIF_CALLBACK_URL', invoker_config.get('capif_callback_url', '')).strip() supported_features = os.getenv('INVOKER_FOLDER', invoker_config.get('supported_features', '')).strip() - check_authentication = invoker_config.get('check_authentication', {}) + check_authentication_data = invoker_config.get('check_authentication_data', {}) self.check_authentication = { - "ip": os.getenv('INVOKER_CHECK_AUTHENTICATION_IP', check_authentication.get('ip', '')).strip(), - "port": os.getenv('INVOKER_CHECK_AUTHENTICATION_PORT', check_authentication.get('port', '')).strip() + "ip": os.getenv('INVOKER_CHECK_AUTHENTICATION_DATA_IP', check_authentication_data.get('ip', '')).strip(), + "port": os.getenv('INVOKER_CHECK_AUTHENTICATION_DATA_PORT', check_authentication_data.get('port', '')).strip() } # Extract CSR configuration from the JSON diff --git a/sdk/capif_provider_connector.py b/sdk/capif_provider_connector.py index a1ae418..d9007c4 100644 --- a/sdk/capif_provider_connector.py +++ b/sdk/capif_provider_connector.py @@ -516,7 +516,7 @@ class capif_provider_connector: cert = ( os.path.join(self.provider_folder, f"apf-{apf_number}.crt"), os.path.join(self.provider_folder, - f"apf-{apf_number}_private_key.key"), + f"APF-{apf_number}_private_key.key"), ) self.logger.info(f"Publishing services to URL: {url}") diff --git a/sdk/sdk.py b/sdk/sdk.py deleted file mode 100644 index 69af626..0000000 --- a/sdk/sdk.py +++ /dev/null @@ -1,3 +0,0 @@ -from capif_invoker_connector import capif_invoker_connector -from capif_provider_connector import capif_provider_connector -from service_discoverer import service_discoverer \ No newline at end of file diff --git a/sdk/service_discoverer.py b/sdk/service_discoverer.py index 0566dec..9f079a1 100644 --- a/sdk/service_discoverer.py +++ b/sdk/service_discoverer.py @@ -76,10 +76,10 @@ class service_discoverer: os.getenv('invoker_folder', invoker_config.get('invoker_folder', '')).strip() ) supported_features = os.getenv('INVOKER_FOLDER', invoker_config.get('supported_features', '')).strip() - check_authentication = invoker_config.get('check_authentication', {}) - self.check_authentication = { - "ip": os.getenv('INVOKER_CHECK_AUTHENTICATION_IP', check_authentication.get('ip', '')).strip(), - "port": os.getenv('INVOKER_CHECK_AUTHENTICATION_PORT', check_authentication.get('port', '')).strip() + check_authentication_data = invoker_config.get('check_authentication_data', {}) + self.check_authentication_data = { + "ip": os.getenv('INVOKER_CHECK_AUTHENTICATION_DATA_IP', check_authentication_data.get('ip', '')).strip(), + "port": os.getenv('INVOKER_CHECK_AUTHENTICATION_DATA_PORT', check_authentication_data.get('port', '')).strip() } # Retrieve CAPIF invoker username capif_invoker_username = os.getenv('CAPIF_USERNAME', config.get('capif_username', '')).strip() @@ -247,7 +247,7 @@ class service_discoverer: except requests.exceptions.HTTPError as http_err: if response.status_code == 404: self.logger.warning( - "Received 404 error, redirecting to register security service") + "Received 404 exception from target CAPIF. This means it is the first time this CAPIF user is getting the JWT token, redirecting to register security service in CAPIF. The process continues correctly.") self.__register_security_service() else: self.logger.error("HTTP error occurred: %s", str(http_err)) @@ -509,11 +509,12 @@ class service_discoverer: raise def check_authentication(self): + print("hola") self.logger.info("Checking authentication") try: invoker_details = self.__load_provider_api_details() invoker_id = invoker_details["api_invoker_id"] - check_auth = self.check_authentication + check_auth = self.check_authentication_data url = "http://"+f"{check_auth['ip']}:{check_auth['port']}/" + "aef-security/v1/check-authentication" payload = { diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4edc854 --- /dev/null +++ b/setup.py @@ -0,0 +1,9 @@ +"""The setup script.""" + +from setuptools import setup, find_packages + +setup( + name='opencapif_sdk', + packages=find_packages(include=["sdk"]), + version="0.1.7", +) \ No newline at end of file diff --git a/test/test.py b/test/test.py index cb50e89..d7e9e6f 100644 --- a/test/test.py +++ b/test/test.py @@ -1,11 +1,7 @@ -import sys -import os + import json # flake8: noqa -# Add the SDK directory to PYTHONPATH using a relative path -script_dir = os.path.dirname(os.path.abspath(__file__)) # Current script directory -sdk_path = os.path.join(script_dir, '..', 'sdk') # Go up two levels and point to 'sdk' -sys.path.insert(0, sdk_path) + from sdk import capif_invoker_connector, capif_provider_connector, service_discoverer -- GitLab