Skip to content

Commit

Permalink
feat: Change logger to include full rquest path
Browse files Browse the repository at this point in the history
  • Loading branch information
mansab committed Jul 20, 2023
1 parent c21a734 commit 9151e3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Helpers Module"""
import datetime
import re
import base64
import argparse
from concurrent.futures import ThreadPoolExecutor
Expand Down Expand Up @@ -27,6 +28,15 @@ def decode_base64(value):
return base64.b64decode(value).decode("utf-8")


def redact_token(uri):
"""Redacts the 'token' value from the URI
Returns:
uri: token=<REDACTED>
"""
return re.sub(r'(\?|&)token=.*?(&|$)', r'\1token=<REDACTED>\2', uri)


def get_token():
"""Sets the GitHub API token based on the selected mode
Expand Down
7 changes: 4 additions & 3 deletions src/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import requests
from flask import Flask, request, make_response, jsonify
from flask_basicauth import BasicAuth
from helpers import get_token, get_all_workflow_runs
from helpers import get_token, get_all_workflow_runs, redact_token
from config import BASIC_AUTH_USERNAME, BASIC_AUTH_PASSWORD, TIMEOUT

logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -74,7 +74,7 @@ def index():
response.headers['Content-Type'] = 'application/xml'

logger.info("Request URI: %s Response Code: %d",
request.path, response.status_code)
redact_token(request.full_path), response.status_code)

return response

Expand Down Expand Up @@ -154,6 +154,7 @@ def handle_error(exception):
Returns:
str: The error message response.
"""
logger.error("An error occurred: %s", str(exception))
logger.error("An error occurred: %s Request URI: %s", str(exception),
redact_token(request.full_path))
error_message = f"An error occurred: {str(exception)}"
return error_message, 500

0 comments on commit 9151e3f

Please sign in to comment.