-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/update-share-feature
- Loading branch information
Showing
24 changed files
with
621 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ cloud-harness/ | |
.vscode/ | ||
node_modules | ||
secret.json | ||
data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
14 changes: 14 additions & 0 deletions
14
applications/visualizer/backend/api/authenticators/basic_auth_super_user.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from ninja.security import HttpBasicAuth | ||
from django.contrib.auth import authenticate as django_authenticate | ||
|
||
|
||
class BasicAuthSuperUser(HttpBasicAuth): | ||
def authenticate(self, request, username, password): | ||
# Authenticate user with Django's built-in authenticate function | ||
user = django_authenticate(request, username=username, password=password) | ||
if user and user.is_superuser: # Ensure the user is a superuser | ||
return user | ||
return None | ||
|
||
|
||
basic_auth_superuser = BasicAuthSuperUser() |
Empty file.
63 changes: 63 additions & 0 deletions
63
applications/visualizer/backend/api/decorators/streaming.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import asyncio | ||
import sys | ||
import threading | ||
from queue import Queue | ||
from functools import wraps | ||
from django.http import StreamingHttpResponse | ||
|
||
|
||
def with_stdout_streaming(func): | ||
""" | ||
A decorator that: | ||
- Runs the decorated function in a separate thread, | ||
- Captures anything it prints to stdout, | ||
- Streams that output asynchronously line-by-line as it's produced. | ||
""" | ||
|
||
@wraps(func) | ||
def wrapper(request, *args, **kwargs): | ||
q = Queue() | ||
|
||
def run_func(): | ||
# Redirect sys.stdout | ||
old_stdout = sys.stdout | ||
|
||
class QueueWriter: | ||
def write(self, data): | ||
if data: | ||
q.put(data) | ||
|
||
def flush(self): | ||
pass # For compatibility with print | ||
|
||
sys.stdout = QueueWriter() | ||
|
||
try: | ||
func(request, *args, **kwargs) | ||
except Exception as e: | ||
q.put(f"Error: {e}\n") | ||
finally: | ||
# Signal completion | ||
q.put(None) | ||
sys.stdout = old_stdout | ||
|
||
# Run the function in a background thread | ||
t = threading.Thread(target=run_func) | ||
t.start() | ||
|
||
# Async generator to yield lines from the queue | ||
async def line_generator(): | ||
while True: | ||
line = await asyncio.to_thread(q.get) | ||
if line is None: # End signal | ||
break | ||
yield line | ||
|
||
# Return a streaming response that sends data asynchronously | ||
return StreamingHttpResponse( | ||
line_generator(), | ||
content_type="text/plain", | ||
headers={"Content-Encoding": "identity"}, | ||
) | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.