Skip to content

Commit

Permalink
more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rbren committed Nov 13, 2024
1 parent 12f77ed commit ad6b91e
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions openhands/server/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class UserVerifier:
def __init__(self) -> None:
logger.debug('Initializing UserVerifier')
logger.info('Initializing UserVerifier')
self.file_users: list[str] | None = None
self.sheets_client: GoogleSheetsClient | None = None
self.spreadsheet_id: str | None = None
Expand All @@ -28,7 +28,7 @@ def _init_file_users(self) -> None:
"""Load users from text file if configured"""
waitlist = os.getenv('GITHUB_USER_LIST_FILE')
if not waitlist:
logger.debug('GITHUB_USER_LIST_FILE not configured')
logger.info('GITHUB_USER_LIST_FILE not configured')
return

if not os.path.exists(waitlist):
Expand All @@ -49,10 +49,10 @@ def _init_sheets_client(self) -> None:
sheet_id = os.getenv('GITHUB_USERS_SHEET_ID')

if not sheet_id:
logger.debug('GITHUB_USERS_SHEET_ID not configured')
logger.info('GITHUB_USERS_SHEET_ID not configured')
return

logger.debug('Initializing Google Sheets integration')
logger.info('Initializing Google Sheets integration')
self.sheets_client = GoogleSheetsClient()
self.spreadsheet_id = sheet_id

Expand All @@ -65,42 +65,44 @@ def is_user_allowed(self, username: str) -> bool:
if not self.is_active():
return True

logger.debug(f'Checking if GitHub user {username} is allowed')
logger.info(f'Checking if GitHub user {username} is allowed')
if self.file_users:
if username in self.file_users:
logger.debug(f'User {username} found in text file allowlist')
logger.info(f'User {username} found in text file allowlist')
return True
logger.debug(f'User {username} not found in text file allowlist')
logger.info(f'User {username} not found in text file allowlist')

logger.info(f'Took {time.time() - start_time:.2f} seconds to check file users')

if self.sheets_client and self.spreadsheet_id:
sheet_users = self.sheets_client.get_usernames(self.spreadsheet_id)
if username in sheet_users:
logger.debug(f'User {username} found in Google Sheets allowlist')
logger.info(f'User {username} found in Google Sheets allowlist')
return True
logger.debug(f'User {username} not found in Google Sheets allowlist')
logger.info(f'User {username} not found in Google Sheets allowlist')

logger.info(f'Took {time.time() - start_time:.2f} seconds to check sheet users')

logger.debug(f'User {username} not found in any allowlist')
logger.info(f'User {username} not found in any allowlist')
return False


async def authenticate_github_user(auth_token) -> bool:
user_verifier = UserVerifier()
logger.info('Initialized user verifier')

if not user_verifier.is_active():
logger.debug('No user verification sources configured - allowing all users')
logger.info('No user verification sources configured - allowing all users')
return True

logger.debug('Checking GitHub token')
logger.info('Checking GitHub token')

if not auth_token:
logger.warning('No GitHub token provided')
return False

start_time = time.time()
logger.info('Getting GitHub user from token')
login = await get_github_user(auth_token)
logger.info(f'Took {time.time() - start_time:.2f} seconds to get GitHub user')

Expand All @@ -122,7 +124,7 @@ async def get_github_user(token: str) -> str:
Returns:
github handle of the user
"""
logger.debug('Fetching GitHub user info from token')
logger.info('Fetching GitHub user info from token')
try:
g = Github(token)
user = await call_sync_from_async(g.get_user)
Expand Down

0 comments on commit ad6b91e

Please sign in to comment.