Skip to content

Commit

Permalink
Namespaces: Daemon: add a way to register new builds and users from cli
Browse files Browse the repository at this point in the history
Signed-off-by: ZorEl212 <[email protected]>
  • Loading branch information
ZorEl212 committed Oct 23, 2024
1 parent 2f39cbe commit 0d7357c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions socket_namespaces/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,45 @@
import json
from models.server import Server
from socket_namespaces.common import Common
from models import storage, sio
from models.build import Build
from models.user import User

class Daemon(Common, Namespace):
def on_builds_report(self, sid, data):
if not self.check_auth(sid):
self.handle_unauthorized(sid)
return
print(f"Received builds report from {sid}: {data}")

def on_add_build(self, sid, data):
if not self.check_auth(sid):
self.handle_unauthorized(sid)
return
print(f"Received add build request from {sid}: {data}")
info = data
server = storage.get('Server', info.get('server_id'))
if server:
build = Build(**info.get('build'))
print(f"Adding build {build.id} to the database. Dict: {build.to_dict()}")
storage.new(build)
return {'status': 'success'}
else:
return {'status': 'failed', 'message': 'Server not found'}

def on_add_user(self, sid, data):
if not self.check_auth(sid):
self.handle_unauthorized(sid)
return
print(f"Received add user request from {sid}: {data}")
info = data
server = storage.get('Server', info.get('server_id'))
user = storage.get('User', info.get('user_id'))
if server and user:
print(f"Adding user {user.id} to server {server.id}")
server.add_user(user.id)
storage.update(server)
print(f'Updated server details: {server.to_dict()}')
return {'status': 'success'}
else:
return {'status': 'failed', 'message': 'Server or user found'}

0 comments on commit 0d7357c

Please sign in to comment.