Skip to content

Commit

Permalink
feat: add missing error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar5526 committed May 22, 2024
1 parent 401b4be commit 8556ee0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion server/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 7 additions & 1 deletion server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 44 in server/utils.py

View check run for this annotation

Codecov / codecov/patch

server/utils.py#L44

Added line #L44 was not covered by tests
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",
Expand Down Expand Up @@ -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:
Expand All @@ -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")

Check warning on line 291 in server/utils.py

View check run for this annotation

Codecov / codecov/patch

server/utils.py#L291

Added line #L291 was not covered by tests
raise HTTPException(
500, "Failed creating outer_proxy_conf_file. Check with admin"
)
Expand Down Expand Up @@ -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.")

Check warning on line 371 in server/utils.py

View check run for this annotation

Codecov / codecov/patch

server/utils.py#L371

Added line #L371 was not covered by tests
raise HTTPException(500, "Vault is down or not configured correctly.")
self._project_path = project_path
self._secrets_namespace = f"{project_name}/{branch_name}"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8556ee0

Please sign in to comment.