Skip to content
Snippets Groups Projects
Commit 6c7de665 authored by Nikos Filinis's avatar Nikos Filinis
Browse files

Add new pages

parent 08df3753
No related branches found
No related tags found
No related merge requests found
Pipeline #63947 passed with stage
in 2 minutes and 35 seconds
Showing
with 259 additions and 51 deletions
......@@ -105,6 +105,7 @@ make push
FLASK_PASSWORD: XXXXXXXXX
CLIENT_ID: XXXXXXXXX
CLIENT_SECRET: XXXXXXXXX
ADMIN_DASHBOARD_PASSWORD: XXXXXXXXX
```
5. Install the helm chart:
......
# pull official base image
FROM python:3.11.3-slim-buster
# Set environment variables for Python optimizations
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Create a directory for the app
WORKDIR /app
# Copy requirements file and install dependencies
COPY requirements.txt /app/
# RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt --no-cache-dir
# Copy the Flask application code into the container
COPY . /app/
ENV NAME=dashboard
......@@ -23,13 +17,6 @@ ENV NAME=dashboard
# RUN useradd -m myuser
# USER myuser
# Expose the port that the Flask app runs on
EXPOSE 5000
# Set the command to run the Flask app
# CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:443", "--certfile=/app/certbot/conf/live/nephele.netmode.ece.ntua.gr/cert.pem", "--keyfile=/app/certbot/conf/live/nephele.netmode.ece.ntua.gr/privkey.pem", "app:dashboard"]
# CMD ["python", "app.py"]
CMD ["flask", "run", "--host=0.0.0.0"]
\ No newline at end of file
CMD ["flask", "run", "--host=0.0.0.0"]
......@@ -4,13 +4,11 @@ import os
from flasgger import Swagger
from flask import Flask
from flask_cors import CORS
from config import configs
from models import db
from blueprints.artifact import artifact
from blueprints.cluster import cluster
from blueprints.dashboard import dashboard
from blueprints.device import device
from blueprints.hdag import hdag
from blueprints.user import user
......@@ -24,20 +22,44 @@ def create_app(app_name='dashboard'):
Function that returns a configured Flask app.
"""
app = Flask(app_name, static_url_path='', static_folder='nephele-front/dist/spa/')
swagger = Swagger(app)
# TODO: do we need CORS if hosted on the same domain?
cors = CORS(app)
ROOT_PATH = os.path.dirname(__file__)
app = Flask(app_name, root_path=ROOT_PATH)
app.config.from_object(configs[env])
app.config['CORS_HEADERS'] = 'Content-Type'
app.config['SWAGGER'] = {
'title': 'Nephele Backend API',
'uiversion': 3,
'specs_route': '/backend-api/',
'basePath': '/web',
'specs': [
{
'endpoint': 'nephele-spec',
'route': '/nephele-spec.json',
'rule_filter': lambda rule: True,
'model_filter': lambda tag: True,
}
],
'ui_params': {
'apisSorter': 'alpha',
'operationsSorter': 'alpha',
'tagsSorter': 'alpha'
},
'ui_params_text': (
'{\n'
' "operationsSorter": (a, b) => {\n'
' var order = { "get": "0", "post": "1", "put": "2", "delete": "3" };\n'
' return order[a.get("method")].localeCompare(order[b.get("method")]);\n'
' }\n'
'}'
)
}
Swagger(app=app)
# Load other configurations as needed
app.config.from_object(configs[env])
app.register_blueprint(artifact)
app.register_blueprint(cluster)
app.register_blueprint(dashboard)
app.register_blueprint(device)
app.register_blueprint(hdag)
app.register_blueprint(user)
......
import base64
import os
import requests
from flasgger import swag_from
from flask import Blueprint, request, jsonify, current_app
from utils.keycloak_client import keycloak_client
artifact = Blueprint('artifact', __name__)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@artifact.route('/fetch_artifacts', methods=['POST'])
@swag_from('swagger_docs/fetch_artifacts.yml')
@swag_from(os.path.join(BASE_DIR, 'swagger_docs/fetch_artifacts.yml'))
def fetch_artifacts():
hdar_base_url = current_app.config["HDAR_BASE_URL"]
url = f'{hdar_base_url}/catalogue'
......@@ -56,7 +57,7 @@ def fetch_artifacts():
@artifact.route('/fetch_artifacts_information', methods=['POST'])
@swag_from('swagger_docs/fetch_artifacts_information.yml')
@swag_from(os.path.join(BASE_DIR, 'swagger_docs/fetch_artifacts_information.yml'))
def fetch_artifacts_information():
hdar_base_url = current_app.config["HDAR_BASE_URL"]
......
import os
import requests
from flasgger import swag_from
from flask import Blueprint, jsonify
from flask import Blueprint, current_app, jsonify
from models import db, NepheleCluster
from utils.utils import login_required
cluster = Blueprint('cluster', __name__)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@cluster.route('/clusters', methods=['GET'])
@swag_from('swagger_docs/clusters.yml')
@swag_from(os.path.join(BASE_DIR, 'swagger_docs/clusters.yml'))
@login_required
def get_clusters():
clusters = db.session.query(NepheleCluster).all()
cluster_list = [cluster.to_dict() for cluster in clusters]
smo_base_url = current_app.config["SMO_BASE_URL"]
url = f'{smo_base_url}/clusters'
response = requests.get(url)
print(response)
return jsonify({'clusters': cluster_list}), 200
return jsonify({'clusters': response.json()}), 200
from flask import Blueprint, current_app
dashboard = Blueprint('dashboard', __name__)
@dashboard.route('/<path:filename>')
def send_static(filename):
return current_app.send_static_file(filename)
@dashboard.route('/main', methods=['GET'])
def index():
return current_app.send_static_file('index.html')
import os
from flasgger import swag_from
from flask import Blueprint, jsonify
......@@ -7,9 +9,11 @@ from utils.utils import login_required
device = Blueprint('device', __name__)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@device.route('/devices', methods=['GET'])
@swag_from('swagger_docs/devices.yml')
@swag_from(os.path.join(BASE_DIR, 'swagger_docs/devices.yml'))
@login_required
def get_devices():
devices = db.session.query(RegisteredIoTDevice).all()
......
import os
import requests
from flasgger import swag_from
......@@ -6,9 +8,11 @@ from flask import Blueprint, request, jsonify, current_app
hdag = Blueprint('hdag', __name__)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@hdag.route('/publish_hdag', methods=['POST'])
@swag_from('swagger_docs/publish_hdag.yml')
@swag_from(os.path.join(BASE_DIR, 'swagger_docs/publish_hdag.yml'))
def publish_hdag():
hdar_base_url = current_app.config["HDAR_BASE_URL"]
smo_base_url = current_app.config["SMO_BASE_URL"]
......@@ -50,7 +54,7 @@ def update_hdag():
return f"Error: {response.status_code} - {response.text}", response.status_code
@hdag.route('/app_graphs', methods=['POST'])
@swag_from('swagger_docs/app_graphs.yml')
@swag_from(os.path.join(BASE_DIR, 'swagger_docs/app_graphs.yml'))
def app_graphs():
smo_base_url = current_app.config["SMO_BASE_URL"]
......
paths:
/api/v1/add_user_to_project:
post:
summary: AddUserToProject
tags:
- Projects
description: Endpoint to add a user in a project group with project_name and username.
operationId: AddUserToProject
consumes:
- application/json
parameters:
- in: body
name: user
description: Add user to project group object
required: true
schema:
type: object
properties:
username:
type: string
example: testuser
x-example: testuser
password:
type: string
example: testpassword
x-example: testpassword
responses:
200:
description: User is successfully added to the project group.
401:
description: Unauthorized. Invalid credentials provided.
404:
description: User not found.
404:
description: Project group not found.
409:
description: User does not belong to project group.
500:
description: Internal server error
\ No newline at end of file
paths:
/api/v1/change_password:
post:
summary: ChangePassword
tags:
- Users
description: Endpoint to change a user's password with username, current_password and new_password.
operationId: ChangeUserPassword
consumes:
- application/json
parameters:
- in: body
name: user
description: Updated user object containing username and (new)password
required: true
schema:
type: object
properties:
username:
type: string
example: testuser
x-example: testuser
current_password:
type: string
example: testpassword
x-example: testpassword
new_password:
type: string
example: testpassword
x-example: testpassword
responses:
200:
description: User's password changed successfully.
401:
description: Unauthorized. Invalid credentials provided.
404:
description: User not found
500:
description: Internal server error
\ No newline at end of file
......@@ -2,6 +2,8 @@ paths:
/api/v1/clusters:
post:
summary: Get Clusters
tags:
- Clusters
description: Retrieve a list of clusters
operationId: getClusters
consumes:
......
......@@ -2,6 +2,8 @@ paths:
/api/v1/create_project:
post:
summary: Create Project
tags:
- Projects
description: Endpoint to create a new project.
operationId: createProject
consumes:
......
paths:
/api/v1/create_project_no_assigned_users:
post:
summary: Create Project Without Assigning Users
tags:
- Projects
description: Endpoint to create a new project without assigned users.
operationId: createProjectNoAssignedUsers
consumes:
- application/x-www-form-urlencoded
parameters:
- in: header
name: Authorization
description: Access token for authentication
required: true
type: string
default: Bearer {access_token}
- in: formData
name: project
description: Project name
required: true
type: string
required: true
example: test_project
x-example: test_project
responses:
'200':
description: Project created successfully
'401':
description: Unauthorized
'500':
description: Internal server error
\ No newline at end of file
paths:
/api/v1/delete_account:
post:
summary: DeleteAccount
tags:
- Users
description: Endpoint to delete a user's account with username and password.
operationId: DeleteUserAccount
consumes:
- application/json
parameters:
- in: body
name: user
description: Delete user object
required: true
schema:
type: object
properties:
username:
type: string
example: testuser
x-example: testuser
password:
type: string
example: testpassword
x-example: testpassword
responses:
200:
description: Account deleted successfully.
400:
description: Fields missing. All fields required.
401:
description: Unauthorized. Invalid credentials provided.
404:
description: User not found
500:
description: Internal server error
\ No newline at end of file
paths:
/api/v1/delete_project:
post:
summary: DeleteProject
tags:
- Projects
description: Endpoint to delete a project with project_name.
operationId: DeleteProject
consumes:
- application/json
parameters:
- in: body
name: user
description: Delete project group object
required: true
schema:
type: object
properties:
username:
type: string
example: testuser
x-example: testuser
password:
type: string
example: testpassword
x-example: testpassword
responses:
200:
description: Project group deleted successfully
401:
description: Unauthorized. Invalid credentials provided.
404:
description: User not found
500:
description: Internal server error
\ No newline at end of file
......@@ -2,6 +2,8 @@ paths:
/api/v1/devices:
post:
summary: Get Devices
tags:
- Devices
description: Retrieve a list of IoT devices
operationId: getDevices
consumes:
......
......@@ -2,6 +2,8 @@ paths:
/api/v1/fetch_artifacts:
post:
summary: Fetch Artifacts
tags:
- Artifacts
description: Endpoint to fetch artifacts for a project.
operationId: fetchArtifacts
consumes:
......
......@@ -2,6 +2,8 @@ paths:
/api/v1/fetch_artifacts_information:
post:
summary: Fetch Artifacts Information
tags:
- Artifacts
description: Endpoint to fetch information about artifacts.
operationId: fetchArtifactsInformation
consumes:
......
......@@ -2,6 +2,8 @@ paths:
/api/v1/login:
post:
summary: User Login
tags:
- Users
description: Endpoint to authenticate a user and retrieve access and refresh tokens.
operationId: UserLogin
consumes:
......
......@@ -2,6 +2,8 @@ paths:
/api/v1/renderHdag:
post:
description: "Based on user input compose a baseline HDAG descriptor"
tags:
- Graphs
consumes:
- "application/json"
summary: "Create HDAG Descriptor"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment