diff --git a/app.py b/app.py index 1782b93..3847dc6 100644 --- a/app.py +++ b/app.py @@ -19,6 +19,7 @@ env = os.environ.get("ENV").upper() == constants.LOCAL logging.basicConfig(level=logging.DEBUG if env else logging.INFO) +logger = logging.getLogger(__name__) async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)): @@ -27,7 +28,7 @@ async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(secur data = jwt.decode(token, app.config["SECRET_TEXT"], algorithms=["HS256"]) logging.debug(f"Authenticated successfully {data}") except Exception as e: - logging.info(f"Error while authenticating {e}") + logging.error(f"Error while authenticating {e}") raise HTTPException(status_code=401, detail="Invalid token") return data diff --git a/server/deployer.py b/server/deployer.py index 1d6ee02..8326e0e 100644 --- a/server/deployer.py +++ b/server/deployer.py @@ -86,7 +86,8 @@ def _setup_project(self): def _configure_outer_proxy(self): if not self._project_nginx_port: - raise Exception("Project Proxy not deployed, project_nginx_port is None") + logger.error('Project Proxy not deployed, project_nginx_port is None') + raise HTTPException("Project Proxy not deployed, project_nginx_port is None") self._nginx_helper.generate_outer_proxy_conf_file(self._project_nginx_port) self._nginx_helper.reload_nginx() diff --git a/server/utils.py b/server/utils.py index c946efb..4aadc13 100644 --- a/server/utils.py +++ b/server/utils.py @@ -41,6 +41,9 @@ def __post_init__(self): self.branch_name[:20] if len(self.branch_name) > 20 else self.branch_name ) if self.branch_name == constants.DEFAULT_SECRETS_PATH: + logger.error( + f"{constants.DEFAULT_SECRETS_PATH} is a reserved keyword in Sarthi. Please use a different branch name", + ) raise HTTPException( 400, f"{constants.DEFAULT_SECRETS_PATH} is a reserved keyword in Sarthi. Please use a different branch name", @@ -268,6 +271,7 @@ def find_free_port(self) -> str: self._port = current_port return str(current_port) + logger.error("Could not find a free port in the specified range") raise HTTPException(500, "Could not find a free port in the specified range") def generate_outer_proxy_conf_file(self, port: str) -> str: @@ -284,6 +288,7 @@ def generate_outer_proxy_conf_file(self, port: str) -> str: if not self._test_nginx_config(): os.remove(self._outer_proxy_path) + logger.error("Failed creating outer_proxy_conf_file. Check with admin") raise HTTPException( 500, "Failed creating outer_proxy_conf_file. Check with admin" ) @@ -363,6 +368,7 @@ def __init__(self, project_name, branch_name, project_path): vault_url = os.environ.get("VAULT_BASE_URL") vault_token = os.environ.get("VAULT_TOKEN") if not vault_url or not vault_token: + logger.error("Vault is down or not configured correctly.") raise HTTPException(500, "Vault is down or not configured correctly.") self._project_path = project_path self._secrets_namespace = f"{project_name}/{branch_name}" @@ -426,7 +432,7 @@ def _create_env_placeholder(self): def inject_env_variables(self, project_path): secret_data = self._read_secrets_from_vault(self._secret_url) - + if not secret_data: logger.info(f"No secrets found in vault for {self._secrets_namespace}") secret_data = self._create_env_placeholder()