async def get_pubkey(request: Request, _=Depends(jwt_auth_scheme)) -> str: try: orch = Orchestrator(request.app.state.gstate.ceph_mgr) return orch.get_public_key() except Exception as e: raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
async def get_pubkey() -> str: try: orch = Orchestrator() return orch.get_public_key() except Exception as e: raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
async def _handle_join(self, conn: IncomingConnection, msg: JoinMessageModel) -> None: logger.debug(f"handle join {msg}") assert self._state is not None if msg.token != self._token: logger.info(f"handle join > bad token from {conn}") await conn.send_msg( MessageModel( type=MessageTypeEnum.ERROR, data=ErrorMessageModel(what="bad token", code=status.HTTP_401_UNAUTHORIZED), )) return if not msg.address or not msg.hostname: logger.info(f"handle join > missing address or host from {conn}") await conn.send_msg( MessageModel( type=MessageTypeEnum.ERROR, data=ErrorMessageModel( what="missing address or hostname", code=status.HTTP_400_BAD_REQUEST, ), )) return orch = Orchestrator(self.gstate.ceph_mgr) pubkey: str = orch.get_public_key() cephconf_path: Path = Path("/etc/ceph/ceph.conf") keyring_path: Path = Path("/etc/ceph/ceph.client.admin.keyring") assert cephconf_path.exists() assert keyring_path.exists() cephconf: str = cephconf_path.read_text("utf-8") keyring: str = keyring_path.read_text("utf-8") assert len(cephconf) > 0 assert len(keyring) > 0 logger.debug(f"handle join > pubkey: {pubkey}") welcome = WelcomeMessageModel(pubkey=pubkey, cephconf=cephconf, keyring=keyring) try: logger.debug(f"handle join > send welcome: {welcome}") await conn.send_msg( MessageModel(type=MessageTypeEnum.WELCOME, data=welcome.dict())) except Exception as e: logger.error(f"handle join > error: {str(e)}") return logger.debug(f"handle join > welcome sent: {welcome}") self._joining[conn.address] = JoiningNodeModel(address=msg.address, hostname=msg.hostname)
async def _handle_join(self, conn: IncomingConnection, msg: JoinMessageModel) -> None: logger.debug(f"handle join {msg}") assert self._state is not None if msg.token != self._token: logger.info(f"handle join > bad token from {conn}") await conn.send_msg( MessageModel(type=MessageTypeEnum.ERROR, data=ErrorMessageModel( what="bad token", code=status.HTTP_401_UNAUTHORIZED))) return if not msg.address or not msg.hostname: logger.info(f"handle join > missing address or host from {conn}") await conn.send_msg( MessageModel(type=MessageTypeEnum.ERROR, data=ErrorMessageModel( what="missing address or hostname", code=status.HTTP_400_BAD_REQUEST))) return orch = Orchestrator() pubkey: str = orch.get_public_key() logger.debug(f"handle join > pubkey: {pubkey}") welcome = WelcomeMessageModel(pubkey=pubkey) try: logger.debug(f"handle join > send welcome: {welcome}") await conn.send_msg( MessageModel(type=MessageTypeEnum.WELCOME, data=welcome.dict())) except Exception as e: logger.error(f"handle join > error: {str(e)}") return logger.debug(f"handle join > welcome sent: {welcome}") self._joining[conn.address] = \ JoiningNodeModel(address=msg.address, hostname=msg.hostname)