diff --git a/README.md b/README.md index d7a9df7f36f4f2a8dcbcf152f2074ea862c70f2d..5fd8f584e37b9c37ed2dee746c5f76509c24034a 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,11 @@ GET /hello ## Getting started To deploy the service, run the following command in an Ubuntu or MacOS terminal. - ``` - ./start_dummy_api.sh + cd dummy-aef + chmod +x start_dummy_api.sh + ./start_dummy_api.sh ``` - The above command will deploy a docker container with the name or username inserted The API of this AEF, during the tutorial, has to be accessible via the [CAPIF Provider Gateway](https://labs.etsi.org/rep/ocf/provider-gateway) @@ -29,3 +29,15 @@ The neccesary files to configure the Provider Gateway with the AEF API are: First fill the fields starting with <> with the correct information and then copy them to the Provider Gateway folder. + +To check the logs, run the following command. +``` + ./logs_dummy_api.sh +``` + +To stop the service, run the following command. +``` + ./stops_dummy_api.sh +``` + + diff --git a/Dockerfile b/app/Dockerfile similarity index 100% rename from Dockerfile rename to app/Dockerfile diff --git a/app.py b/app/app.py similarity index 53% rename from app.py rename to app/app.py index 5d920c5914efdc67fcda0306192d13baa08e754f..7fe7b4678095dd3fcdc72218d51d5c940ba1f0b0 100644 --- a/app.py +++ b/app/app.py @@ -1,5 +1,6 @@ import os -from flask import Flask, jsonify +from flask import Flask, jsonify, request +import logging app = Flask(__name__) @@ -7,11 +8,19 @@ app = Flask(__name__) # Default to 'World' if the variable isn't set app_name = os.getenv("APP_NAME", "World") +# Set up logging +app.logger.setLevel(logging.INFO) + + @app.route("/hello", methods=["GET"]) def hello(): # return f"Hello {app_name}" + # Flask attempts to parse the token automatically + token = request.authorization.token if request.authorization else None + app.logger.info(f"JWT detected: {token}") return jsonify(f"Hello, {app_name}!") + if __name__ == "__main__": port = int(os.getenv("PORT", 8000)) - app.run(host='0.0.0.0', port=port) \ No newline at end of file + app.run(host='0.0.0.0', port=port) diff --git a/requirements.txt b/app/requirements.txt similarity index 100% rename from requirements.txt rename to app/requirements.txt diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..557c741552467868fb65cc3512971181c4438004 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +name: dummy +services: + aef: + image: flask-hello-service + build: + context: ./app + restart: unless-stopped + ports: + - 8000:8000 + environment: + - APP_NAME=${APP_NAME} diff --git a/logs_dummy_api.sh b/logs_dummy_api.sh new file mode 100755 index 0000000000000000000000000000000000000000..9d59ee0de7f23f45213f07d4216e9c3cb4bf5d99 --- /dev/null +++ b/logs_dummy_api.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +echo "Logs of dummy service for user: $1" + +APP_NAME=$1 docker compose logs -f diff --git a/northbound.yaml b/northbound.yaml index 3a06398f8957ca298362c9999e6aef0557e89314..876398b152844c58dfe4ba04c532ccd66e4d0fb2 100644 --- a/northbound.yaml +++ b/northbound.yaml @@ -27,7 +27,7 @@ northbound: description: Example API for demonstration version: 1.0.0 paths: - /greet: + /hello: get: summary: Say hello description: Returns a greeting message. diff --git a/southbound.yaml b/southbound.yaml index 62a44962d8a9d5f331430440b85f273f6caa310d..03986ae3894381555153c81bb3d07bcb3ec974a3 100644 --- a/southbound.yaml +++ b/southbound.yaml @@ -6,6 +6,6 @@ southbound: credentials: jwt: "example-token" paths: - - northbound_path: "/greet" + - northbound_path: "/hello" southbound_path: "/hello" method: GET diff --git a/start_dummy_api.sh b/start_dummy_api.sh index 9ed383fa77c8e5d932e7e3cc392408e42efc718d..19e0fa41631442524a12c8d2833ffb3580b3eb89 100755 --- a/start_dummy_api.sh +++ b/start_dummy_api.sh @@ -1,5 +1,10 @@ #!/bin/bash +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + echo "Create dummy service for user: $1" -docker build -t flask-hello-service . -docker run -it --rm --name "$1" -p 8000:8000 -e APP_NAME=$1 flask-hello-service \ No newline at end of file + +APP_NAME=$1 docker compose up --detach --build --force-recreate diff --git a/stops_dummy_api.sh b/stops_dummy_api.sh new file mode 100755 index 0000000000000000000000000000000000000000..7ac44271d7e1ac4c0b26938100e000bbfa9326de --- /dev/null +++ b/stops_dummy_api.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +echo "Stop dummy service for user: $1" + +APP_NAME=$1 docker compose down