def post_node_credentials(node_id, private_key, public_key): #ssh_key_private", "ssh_key_public bee_db = BeekeeperDB() post_creds = {"ssh_key_private": private_key, "ssh_key_public": public_key} try: bee_db.set_node_keypair(node_id, post_creds) except Exception as e: raise Exception(f"set_node_keypair returned: {str(e)}") bee_db.close() return
def post(self, node_id): try: #request.get postData = request.get_json(force=True, silent=False) except Exception as e: raise ErrorResponse(f"Error parsing json: { sys.exc_info()[0] } {e}" , status_code=HTTPStatus.INTERNAL_SERVER_ERROR) if not postData: raise ErrorResponse(f"Could not parse json." , status_code=HTTPStatus.INTERNAL_SERVER_ERROR) valid_keys = {"ssh_key_private", "ssh_key_public"} expected_keys = valid_keys for key in postData: if key not in valid_keys: raise ErrorResponse(f"Key {key} not supported" , status_code=HTTPStatus.INTERNAL_SERVER_ERROR) for key in expected_keys: if key not in postData: raise ErrorResponse(f"Key {key} missing" , status_code=HTTPStatus.INTERNAL_SERVER_ERROR) try: bee_db = BeekeeperDB() results = bee_db.set_node_keypair(node_id, postData) bee_db.close() except Exception as e: raise ErrorResponse(f"Unexpected error: {e}" , status_code=HTTPStatus.INTERNAL_SERVER_ERROR) return "success"