Code Duplication    Length = 22-22 lines in 2 locations

kytos/core/api_server.py 2 locations

@@ 503-524 (lines=22) @@
500
501
        return JSONResponse({"response": "enabled"})
502
503
    def _disable_napp(self, request: Request) -> JSONResponse:
504
        """Disable an installed NApp."""
505
506
        username = request.path_params["username"]
507
        napp_name = request.path_params["napp_name"]
508
        # Check if the NApp is installed
509
        if not self.napps_manager.is_installed(username, napp_name):
510
            return JSONResponse({"response": "not installed"},
511
                                status_code=HTTPStatus.BAD_REQUEST.value)
512
513
        # Check if the NApp is enabled
514
        if self.napps_manager.is_enabled(username, napp_name):
515
            self.napps_manager.disable(username, napp_name)
516
517
        # Check if NApp is still enabled
518
        if self.napps_manager.is_enabled(username, napp_name):
519
            # If it is still enabled an admin user must check the log file
520
            status_code = HTTPStatus.INTERNAL_SERVER_ERROR.value
521
            return JSONResponse({"response": "error"},
522
                                status_code=status_code)
523
524
        return JSONResponse({"response": "disabled"})
525
526
    def _install_napp(self, request: Request) -> JSONResponse:
527
        username = request.path_params["username"]
@@ 480-501 (lines=22) @@
477
            "napps/{username}/{napp_name}/metadata/{key}",
478
            self._get_napp_metadata)
479
480
    def _enable_napp(self, request: Request) -> JSONResponse:
481
        """Enable an installed NApp."""
482
483
        username = request.path_params["username"]
484
        napp_name = request.path_params["napp_name"]
485
        # Check if the NApp is installed
486
        if not self.napps_manager.is_installed(username, napp_name):
487
            return JSONResponse({"response": "not installed"},
488
                                status_code=HTTPStatus.BAD_REQUEST.value)
489
490
        # Check if the NApp is already been enabled
491
        if not self.napps_manager.is_enabled(username, napp_name):
492
            self.napps_manager.enable(username, napp_name)
493
494
        # Check if NApp is enabled
495
        if not self.napps_manager.is_enabled(username, napp_name):
496
            # If it is not enabled an admin user must check the log file
497
            status_code = HTTPStatus.INTERNAL_SERVER_ERROR.value
498
            return JSONResponse({"response": "error"},
499
                                status_code=status_code)
500
501
        return JSONResponse({"response": "enabled"})
502
503
    def _disable_napp(self, request: Request) -> JSONResponse:
504
        """Disable an installed NApp."""