diff --git a/.gitignore b/.gitignore index 08d19200..56142666 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .vscode .mypy_cache -.env \ No newline at end of file +.env +.key +.crt +capif_exposer_details.json \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 464646bc..1123f227 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,30 @@ # Changelog +## v1.6.1 + +### UI changes + + - Upgrade coreui bootstrat admin template to v.4.2.1 + + +### NEF APIs / backend + +- Change status code from `403` to `401` for invalid credentials +- Create environment variable for MongoClient host 👉 ```MONGO_CLIENT``` + + +### Docker 🐳 + +- Addition of ```services_default``` network in docker-compose. Individual services are now connected to services_default network. Environmental variable ```EXTERNAL_NET``` defines if this network is external or not (```true``` or ```false```) + + +### Libraries + +- 🪛 Fix poetry installer - deprecated (different URL for poetry installation) +- Import ```evolved5g ^0.8.3``` library +- Change ```requests``` from ```^2.27.0``` 👉 ```^2.26.0``` +- Change ```pytest``` from ```^5.4.1``` 👉 ```>6``` + +

## v1.6.0 diff --git a/README.md b/README.md index 3464a633..84997c96 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,13 @@

+## Contents + +- [Setup locally](#-setup-locally) + - [Try out your setup](#try-out-your-setup) +- [How to work with a specific tag / release](#%EF%B8%8F-how-to-work-on-a-specific-tag--release) +- [NetApp communication options](#%EF%B8%8F-netapp-communication-options) +- [Integration with CAPIF](#integration-with-capif) ## ⚙ Setup locally @@ -154,3 +161,30 @@ Three possible ways to achieve the above approach: 3. with **docker network connect**, try adding your container to the bridge network: docker network connect BRIDGE_NAME NETAPP_NAME + +## Integration with CAPIF + +In order to integrate NEF Emulator with CAPIF you should perform the following steps: + +1. The first step is to ensure that all CAPIF services are up and running. After cloning the code from the official github repository https://github.com/EVOLVED-5G/CAPIF_API_Services you can execute: + +``` +cd services/ + +sudo ./run.sh + +./check_services_are_running.sh +``` + +2. Then, in NEF Emulator project, change the `EXTERNAL_NET` environment variable to **true** in `.env` file. This will enable NEF containers to join CAPIF's pre-existing network (services_default) + +3. Start NEF services either using `make up` or `make debug-up` commands + +NEF should be successfully onboard to CAPIF Core Function. To ensure that, the following files should be created in `app/core/certificates/` folder: + +``` +ca.crt +private.key +test_nef01.crt +capif_exposer_details.json +``` diff --git a/backend/app/app/backend_pre_start.py b/backend/app/app/backend_pre_start.py index 3363a415..ae608462 100644 --- a/backend/app/app/backend_pre_start.py +++ b/backend/app/app/backend_pre_start.py @@ -1,13 +1,13 @@ import logging - +from evolved5g.sdk import CAPIFExposerConnector from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed - from app.db.session import SessionLocal +import requests logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) -max_tries = 60 * 5 # 5 minutes +max_tries = 60 wait_seconds = 1 @@ -26,11 +26,42 @@ def init() -> None: logger.error(e) raise e +def capif_nef_connector(): + """ + + """ + try: + capif_connector = CAPIFExposerConnector(certificates_folder="app/core/certificates", + capif_host="capifcore", + capif_http_port="8080", + capif_https_port="443", + capif_netapp_username="test_nef01", + capif_netapp_password="test_netapp_password", + description= "test_app_description" + ) + + capif_connector.register_and_onboard_exposer() + capif_connector.publish_services( + service_api_description_json_full_path="app/core/capif_files/service_api_description.json") + except requests.exceptions.HTTPError as err: + if err.response.status_code == 409: + logger.error(f'"Http Error:", {err.response.json()}') + except requests.exceptions.ConnectionError as err: + logger.error(f'"Error Connecting:", {err}') + except requests.exceptions.Timeout as err: + logger.error(f'"Timeout Error:", {err}') + except requests.exceptions.RequestException as err: + logger.error(f'"Error:", {err}') + + def main() -> None: logger.info("Initializing service") init() logger.info("Service finished initializing") + logger.info("Trying to connect with CAPIF Core Function") + capif_nef_connector() + logger.info("Successfully onboard to CAPIF Core Function") if __name__ == "__main__": diff --git a/backend/app/app/core/capif_files/service_api_description.json b/backend/app/app/core/capif_files/service_api_description.json new file mode 100644 index 00000000..a859e892 --- /dev/null +++ b/backend/app/app/core/capif_files/service_api_description.json @@ -0,0 +1,62 @@ +{ + "apiName": "api_name_2", + "aefProfiles": [ + { + "aefId": "UNIQUE_ID THAT IS SET AUTOMATICALLY BY THE SDK. Contains the API PROV DOM ID parameter", + "versions": [ + { + "apiVersion": "v1", + "expiry": "2021-11-30T10:32:02.004Z", + "resources": [ + { + "resourceName": "hello-endpoint", + "commType": "REQUEST_RESPONSE", + "uri": "/hello", + "custOpName": "string", + "operations": [ + "POST" + ], + "description": "string" + } + ], + "custOperations": [ + { + "commType": "REQUEST_RESPONSE", + "custOpName": "string", + "operations": [ + "POST" + ], + "description": "string" + } + ] + } + ], + "protocol": "HTTP_1_1", + "dataFormat": "JSON", + "securityMethods": ["Oauth", "PSK"], + "interfaceDescriptions": [ + { + "ipv4Addr": "the ip address where the exposer relies", + "port": 8086, + "securityMethods": ["Oauth"] + } + ] + } + ], + "description": "API of dummy netapp to test", + "supportedFeatures": "fffff", + "shareableInfo": { + "isShareable": true, + "capifProvDoms": [ + "string" + ] + }, + "serviceAPICategory": "string", + "apiSuppFeats": "fffff", + "pubApiPath": { + "ccfIds": [ + "string" + ] + }, + "ccfId": "test" +} diff --git a/backend/app/pyproject.toml b/backend/app/pyproject.toml index 03168a7d..40c9fa70 100644 --- a/backend/app/pyproject.toml +++ b/backend/app/pyproject.toml @@ -11,7 +11,7 @@ fastapi = "^0.78.0" pymongo = "^4.1.0" python-multipart = "^0.0.5" email-validator = "^1.0.5" -requests = "^2.27.0" +requests = "^2.26.0" passlib = {extras = ["bcrypt"], version = "^1.7.2"} tenacity = "^6.1.0" pydantic = "^1.4" @@ -21,9 +21,10 @@ gunicorn = "^20.1.0" jinja2 = "3.0.3" psycopg2-binary = "^2.8.5" sqlalchemy = "^1.3.16" -pytest = "^5.4.1" +pytest = ">6" python-jose = {extras = ["cryptography"], version = "^3.1.0"} aiofiles = "^0.6.0" +evolved5g = "^0.8.3" [tool.poetry.dev-dependencies] @@ -32,7 +33,7 @@ black = "^19.10b0" isort = "^4.3.21" autoflake = "^1.3.1" flake8 = "^3.7.9" -pytest = "^5.4.1" +pytest = ">6" sqlalchemy-stubs = "^0.3" pytest-cov = "^2.8.1" diff --git a/docker-compose.yml b/docker-compose.yml index 5596dd25..184c1806 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,8 @@ services: - .env environment: - PGDATA=/var/lib/postgresql/data/pgdata + networks: + - services_default @@ -26,6 +28,8 @@ services: - .env logging: driver: none + networks: + - services_default mongo: image: mongo:4.4.10 @@ -38,6 +42,8 @@ services: environment: MONGO_INITDB_ROOT_USERNAME: "${MONGO_USER}" MONGO_INITDB_ROOT_PASSWORD: "${MONGO_PASSWORD}" + networks: + - services_default mongo-express: image: mongo-express:1.0.0-alpha.4 @@ -52,6 +58,8 @@ services: ME_CONFIG_MONGODB_ADMINPASSWORD: "${MONGO_PASSWORD}" ME_CONFIG_MONGODB_URL: mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongo:27017/ ME_CONFIG_MONGODB_ENABLE_ADMIN: "${MONGO_EXPRESS_ENABLE_ADMIN}" + networks: + - services_default backend: @@ -77,9 +85,13 @@ services: INSTALL_JUPYTER: ${INSTALL_JUPYTER-true} extra_hosts: - "host.docker.internal:host-gateway" + networks: + - services_default - +networks: + services_default: + external: ${EXTERNAL_NET} volumes: diff --git a/env-file-for-local.dev b/env-file-for-local.dev index f5dfc49d..70846491 100644 --- a/env-file-for-local.dev +++ b/env-file-for-local.dev @@ -37,7 +37,13 @@ PGADMIN_DEFAULT_PASSWORD=pass # Mongo MONGO_USER=root MONGO_PASSWORD=pass -MONGO_CLIENT=mongodb://localhost:27017/ +MONGO_CLIENT=mongodb://mongo:27017/ # MongoExpress -MONGO_EXPRESS_ENABLE_ADMIN=true \ No newline at end of file +MONGO_EXPRESS_ENABLE_ADMIN=true + +# Compose Networking +# If CAPIF CORE FUNCTION is up and running set EXTERNAL_NET to true +# Else if NEF is used as a standalone service set EXTERNAL_NET to false + +EXTERNAL_NET=false \ No newline at end of file