Skip to content

Commit

Permalink
Merge pull request #61 from medianetlab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
JFrgs authored Oct 27, 2022
2 parents 950ac5b + c10088b commit 5dfbbd7
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.vscode
.mypy_cache
.env
.env
.key
.crt
capif_exposer_details.json
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
# 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```


### Other

-`make db-reset` : except for reseting the postgresql db, add functionality to also reset mongo db


<br><br>

## v1.6.0

Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
<img src="./backend/app/app/static/NEF_logo_400x400_light.svg" />
</p>

## 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

Expand Down Expand Up @@ -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
```
37 changes: 34 additions & 3 deletions backend/app/app/backend_pre_start.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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__":
Expand Down
62 changes: 62 additions & 0 deletions backend/app/app/core/capif_files/service_api_description.json
Original file line number Diff line number Diff line change
@@ -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"
}
7 changes: 4 additions & 3 deletions backend/app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand All @@ -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"

Expand Down
14 changes: 13 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ services:
- .env
environment:
- PGDATA=/var/lib/postgresql/data/pgdata
networks:
- services_default



Expand All @@ -26,6 +28,8 @@ services:
- .env
logging:
driver: none
networks:
- services_default

mongo:
image: mongo:4.4.10
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions env-file-for-local.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit 5dfbbd7

Please sign in to comment.