Skip to content

Commit fff7f45

Browse files
committed
PR 3: System Routes and Run Execution Endpoints
1 parent f409134 commit fff7f45

21 files changed

Lines changed: 2993 additions & 126 deletions

mod_api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@
3535

3636
# Route modules
3737
from mod_api.routes import auth as auth_routes # noqa: E402, F401
38+
from mod_api.routes import runs as runs_routes # noqa: E402, F401
39+
from mod_api.routes import system as system_routes # noqa: E402, F401

mod_api/middleware/error_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def handle_value_error(error):
144144
def convert_api_errors_to_json(response):
145145
"""Catch routing errors that were handled by global app handlers and convert them to JSON."""
146146
if request.path.startswith(_API_PREFIX):
147-
if response.status_code >= 500:
147+
if response.status_code >= 500 and not response.is_json:
148148
new_resp = make_error_response(
149149
'internal_error', 'An unexpected error occurred.', http_status=response.status_code
150150
)

mod_api/routes/auth.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ def create_token(validated_data=None):
6868
'runs:read', 'runs:write', 'results:read',
6969
'system:read'
7070
}
71-
if user.role.value in ('admin', 'contributor', 'tester'):
72-
allowed_scopes.add('tokens:manage')
7371
if user.role.value == 'admin':
72+
allowed_scopes.add('tokens:manage')
7473
allowed_scopes.add('baselines:write')
7574

7675
invalid_scopes = set(scopes) - allowed_scopes
@@ -127,7 +126,11 @@ def create_token(validated_data=None):
127126

128127
@mod_api.route('/auth/tokens/current', methods=['DELETE'])
129128
def revoke_current_token():
130-
"""Revoke whatever token is in the Authorization header right now."""
129+
"""Revoke whatever token is in the Authorization header right now.
130+
131+
Note: This endpoint is intentionally scope-free. Any valid token
132+
is allowed to revoke itself regardless of its scopes.
133+
"""
131134
token = getattr(g, 'api_token', None)
132135
if token is None:
133136
return make_error_response(

0 commit comments

Comments
 (0)