Skip to content

Commit

Permalink
Merge branch '2fa-dev' of github.com:introlab/opentera into 2fa-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
doumdi committed Oct 3, 2024
2 parents fa528a7 + d5b3048 commit f725cf1
Show file tree
Hide file tree
Showing 83 changed files with 763 additions and 417 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from modules.LoginModule.LoginModule import LoginModule, current_device
from modules.DatabaseModule.DBManager import DBManager
from modules.FlaskModule.FlaskModule import device_api_ns as api
from opentera.db.models.TeraDevice import TeraDevice
from opentera.redis.RedisRPCClient import RedisRPCClient
from opentera.modules.BaseModule import ModuleNames
from opentera.utils.UserAgentParser import UserAgentParser
Expand All @@ -30,6 +29,9 @@ def __init__(self, _api, *args, **kwargs):
@api.expect(get_parser)
@LoginModule.device_token_or_certificate_required
def get(self):
"""
Device login
"""
# Redis key is handled in LoginModule
server_name = self.module.config.server_config['hostname']
port = self.module.config.server_config['port']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import jsonify, session
from flask import session
from flask_restx import Resource
from flask_babel import gettext
from modules.LoginModule.LoginModule import LoginModule, current_device
Expand All @@ -7,7 +7,7 @@

# Parser definition(s)
get_parser = api.parser()
get_parser.add_argument('token', type=str, help='Secret Token')
get_parser.add_argument('token', type=str, help='Access Token')


class DeviceLogout(Resource):
Expand All @@ -22,6 +22,9 @@ def __init__(self, _api, *args, **kwargs):
@api.expect(get_parser)
@LoginModule.device_token_or_certificate_required
def get(self):
"""
Device logout
"""
if current_device:
logout_user()
session.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
get_parser.add_argument('with_urls', type=inputs.boolean, help='Also include assets infos and download-upload url')
get_parser.add_argument('with_only_token', type=inputs.boolean, help='Only includes the access token. '
'Will ignore with_urls if specified.')
get_parser.add_argument('token', type=str, help='Secret Token')


class DeviceQueryAssets(Resource):
Expand All @@ -27,10 +26,14 @@ def __init__(self, _api, *args, **kwargs):

@api.doc(description='Get device assets based specified session or asset ID or, if no parameters, get all assets',
responses={200: 'Success',
403: 'Device doesn\'t have access to the specified asset'})
403: 'Device doesn\'t have access to the specified asset'},
params={'token': 'Access token'})
@api.expect(get_parser)
@LoginModule.device_token_or_certificate_required
def get(self):
"""
Get device assets
"""
args = get_parser.parse_args()
device_access = DBManager.deviceAccess(current_device)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import jsonify, session, request
from flask_restx import Resource, reqparse
from flask import request
from flask_restx import Resource
from flask_babel import gettext
from sqlalchemy import exc

Expand All @@ -25,11 +25,14 @@ def __init__(self, _api, *args, **kwargs):
500: 'Required parameter is missing',
501: 'Not implemented',
403: 'Logged device doesn\'t have permission to access the requested data'},
params={'token': 'Secret token'})
params={'token': 'Access token'})
@api.expect(get_parser)
@LoginModule.device_token_or_certificate_required
def get(self):
args = get_parser.parse_args()
"""
Get connected device information
"""
# args = get_parser.parse_args()

# Reply device information
response = {'device_info': current_device.to_json(minimal=True)}
Expand Down Expand Up @@ -62,9 +65,12 @@ def get(self):
403: 'Logged device can\'t update the specified device',
400: 'Badly formed JSON or missing fields(id_device) in the JSON body',
500: 'Internal error occurred when saving device'},
params={'token': 'Secret token'})
params={'token': 'Access token'})
@LoginModule.device_token_or_certificate_required
def post(self):
"""
Update current device information
"""
if 'device' not in request.json:
return gettext('Missing device schema'), 400

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from flask import jsonify, session, request
from flask_restx import Resource, reqparse
from flask_restx import Resource
from flask_babel import gettext
from modules.LoginModule.LoginModule import LoginModule, current_device
from modules.DatabaseModule.DBManager import DBManager
from modules.FlaskModule.FlaskModule import device_api_ns as api
from opentera.db.models.TeraDevice import TeraDevice

# Parser definition(s)
get_parser = api.parser()
Expand All @@ -22,11 +19,14 @@ def __init__(self, _api, *args, **kwargs):
500: 'Required parameter is missing',
501: 'Not implemented',
403: 'Logged device doesn\'t have permission to access the requested data'},
params={'token': 'Secret token'})
params={'token': 'Access token'})
@api.expect(get_parser)
@LoginModule.device_token_or_certificate_required
def get(self):
args = get_parser.parse_args()
"""
Get device associated participants information
"""
# args = get_parser.parse_args()

# Device must have device_onlineable flag
if current_device and current_device.device_onlineable:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from flask import jsonify, request, session
from flask_restx import Resource, reqparse
from flask import request
from flask_restx import Resource
from flask_babel import gettext
from opentera.db.models.TeraSessionEvent import TeraSessionEvent
from modules.LoginModule.LoginModule import LoginModule, current_device
from modules.DatabaseModule.DBManager import DBManager
from sqlalchemy import exc
from modules.FlaskModule.FlaskModule import device_api_ns as api
from opentera.db.models.TeraDevice import TeraDevice

# Parser definition(s)
get_parser = api.parser()
Expand All @@ -24,10 +23,13 @@ def __init__(self, _api, *args, **kwargs):

@api.doc(description='Get session events',
responses={403: 'Forbidden for security reasons.'},
params={'token': 'Secret token'})
params={'token': 'Access token'})
@api.expect(get_parser)
@LoginModule.device_token_or_certificate_required
def get(self):
"""
Get events for a specific session
"""
return gettext('Forbidden for security reasons'), 403

@api.doc(description='Update/Create session events',
Expand All @@ -36,10 +38,13 @@ def get(self):
500: 'Internal server error',
501: 'Not implemented',
403: 'Logged device doesn\'t have permission to access the requested data'},
params={'token': 'Secret token'})
params={'token': 'Access token'})
@api.expect(post_parser)
@LoginModule.device_token_or_certificate_required
def post(self):
"""
Create / update session events
"""
device_access = DBManager.deviceAccess(current_device)

# Using request.json instead of parser, since parser messes up the json!
Expand Down Expand Up @@ -94,4 +99,7 @@ def post(self):

@LoginModule.device_token_or_certificate_required
def delete(self):
"""
Delete session events
"""
return gettext('Forbidden for security reasons'), 403
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import jsonify, session, request
from flask import jsonify, request
from flask_restx import Resource, inputs
from flask_babel import gettext
from opentera.db.models.TeraSession import TeraSession
Expand All @@ -7,7 +7,6 @@
from modules.LoginModule.LoginModule import LoginModule, current_device
from sqlalchemy import exc
from modules.FlaskModule.FlaskModule import device_api_ns as api
from opentera.db.models.TeraDevice import TeraDevice
import datetime

# Parser definition(s)
Expand Down Expand Up @@ -65,10 +64,13 @@ def __init__(self, _api, *args, **kwargs):

@api.doc(description='Get session',
responses={403: 'Forbidden for security reasons.'},
params={'token': 'Secret token'})
params={'token': 'Access token'})
@api.expect(get_parser)
@LoginModule.device_token_or_certificate_required
def get(self):
"""
Query device sessions
"""
return gettext('Forbidden for security reasons'), 403

@api.doc(description='Update/Create session',
Expand All @@ -77,10 +79,13 @@ def get(self):
500: 'Internal server error',
501: 'Not implemented',
403: 'Logged device doesn\'t have permission to access the requested data'},
params={'token': 'Secret token'})
params={'token': 'Access token'})
@api.expect(session_schema)
@LoginModule.device_token_or_certificate_required
def post(self):
"""
Update / create a session
"""
# args = post_parser.parse_args()
# Using request.json instead of parser, since parser messes up the json!
if 'session' not in request.json:
Expand Down Expand Up @@ -190,4 +195,7 @@ def post(self):

@LoginModule.device_token_or_certificate_required
def delete(self):
"""
Delete a session
"""
return gettext('Forbidden for security reasons'), 403
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from flask import jsonify, session, request
from flask_restx import Resource, reqparse
from flask import request
from flask_restx import Resource
from modules.LoginModule.LoginModule import LoginModule, current_device
from flask_babel import gettext
from modules.FlaskModule.FlaskModule import device_api_ns as api
from opentera.db.models.TeraDevice import TeraDevice
from opentera.redis.RedisRPCClient import RedisRPCClient
from opentera.modules.BaseModule import ModuleNames
import json
Expand Down Expand Up @@ -38,10 +37,13 @@ def __init__(self, _api, *args, **kwargs):
500: 'Required parameter is missing',
501: 'Not implemented',
403: 'Logged device doesn\'t have permission to access the requested data'},
params={'token': 'Secret token'})
params={'token': 'Access token'})
@api.expect(status_schema)
@LoginModule.device_token_or_certificate_required
def post(self):
"""
Update current device status
"""
# status_schema.validate(request.json)
# This should not be required since schema should be validated first.
if 'status' not in request.json or 'timestamp' not in request.json:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def __init__(self, _api, *args, **kwargs):
401: 'Unauthorized - provided registration key is invalid'})
@api.expect(api_parser)
def get(self):
"""
Register a new device in the server (token based)
"""
args = api_parser.parse_args(strict=True)

# Check if provided registration key is ok
Expand All @@ -92,6 +95,9 @@ def get(self):
400: 'Missing or invalid parameter',
401: 'Unauthorized - provided registration key is invalid'})
def post(self):
"""
Register a new device in the server (certificate based)
"""
args = api_parser.parse_args(strict=True)

# Check if provided registration key is ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ def __init__(self, _api, *args, **kwargs):
500: 'Required parameter is missing',
501: 'Not implemented.',
403: 'Logged user doesn\'t have permission to access the requested data'},
params={'token': 'Secret token'})
params={'token': 'Access token'})
@api.expect(get_parser)
@participant_multi_auth.login_required(role='limited')
def get(self):
"""
Login a participant with username / password
"""
if current_participant:
args = get_parser.parse_args()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import jsonify, session, request
from flask import session, request
from flask_login import logout_user
from flask_restx import Resource, reqparse, fields
from flask_restx import Resource
from flask_babel import gettext
from modules.LoginModule.LoginModule import participant_multi_auth, current_participant, LoginModule
from modules.FlaskModule.FlaskModule import participant_api_ns as api
Expand All @@ -22,10 +22,13 @@ def __init__(self, _api, *args, **kwargs):
500: 'Required parameter is missing',
501: 'Not implemented.',
403: 'Logged user doesn\'t have permission to access the requested data'},
params={'token': 'Secret token'})
params={'token': 'Access token'})
@api.expect(get_parser)
@participant_multi_auth.login_required
def get(self):
"""
Participant logout
"""
if current_participant:
logout_user()
session.clear()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from flask import session, request
from flask import request
from flask_restx import Resource, inputs
from flask_babel import gettext
from modules.LoginModule.LoginModule import participant_multi_auth, current_participant
from modules.DatabaseModule.DBManager import DBManager
from modules.FlaskModule.FlaskModule import device_api_ns as api
from opentera.db.models.TeraParticipant import TeraParticipant
from opentera.db.models.TeraAsset import TeraAsset

from opentera.redis.RedisVars import RedisVars
Expand All @@ -29,10 +28,13 @@ def __init__(self, _api, *args, **kwargs):
@api.doc(description='Get participant assets based on the ID or, if no parameters, get all assets',
responses={200: 'Success',
403: 'Participant doesn\'t have access to the specified asset'},
params={'token': 'Secret token'})
params={'token': 'Access token'})
@api.expect(get_parser)
@participant_multi_auth.login_required(role='limited')
def get(self):
"""
Get participant assets
"""
args = get_parser.parse_args()
participant_access = DBManager.participantAccess(current_participant)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from flask import session
from flask_restx import Resource, inputs
from flask_babel import gettext
from modules.LoginModule.LoginModule import participant_multi_auth, current_participant
from modules.FlaskModule.FlaskModule import participant_api_ns as api
from opentera.db.models.TeraParticipant import TeraParticipant
from modules.DatabaseModule.DBManager import DBManager

# Parser definition(s)
Expand All @@ -26,11 +23,13 @@ def __init__(self, _api, *args, **kwargs):
responses={200: 'Success',
500: 'Required parameter is missing',
501: 'Not implemented.',
403: 'Logged user doesn\'t have permission to access the requested data'},
params={'token': 'Secret token'})
403: 'Logged user doesn\'t have permission to access the requested data'})
@api.expect(get_parser)
@participant_multi_auth.login_required(role='full')
def get(self):
"""
Get associated participant devices
"""
participant_access = DBManager.participantAccess(current_participant)
args = get_parser.parse_args(strict=True)

Expand Down
Loading

0 comments on commit f725cf1

Please sign in to comment.