-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Google Sheets integration for GitHub user verification #4671
Open
rbren
wants to merge
12
commits into
main
Choose a base branch
from
feature/google-sheets-auth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+173
−31
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
674dd2b
Add Google Sheets integration for GitHub user verification
openhands-agent 714aa5b
Remove setup documentation file - will add to main docs instead
openhands-agent 46f8cc8
Add Google Sheets API dependencies
openhands-agent e26c9dd
Update poetry.lock with Google Sheets dependencies
openhands-agent 29e0c62
Simplify Google Sheets auth to use workload identity
openhands-agent 8efc561
Add extensive logging to GitHub auth and Google Sheets integration
openhands-agent 715fe01
fix some stuff
rbren 9983711
empty commit
rbren 03bd146
revert
rbren c90ac31
unrevert
rbren 8395334
remove sheets client
rbren b614217
unrevert
rbren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from typing import List | ||
|
||
from google.auth import default | ||
from googleapiclient.discovery import build | ||
from googleapiclient.errors import HttpError | ||
|
||
from openhands.core.logger import openhands_logger as logger | ||
|
||
|
||
class GoogleSheetsClient: | ||
def __init__(self): | ||
"""Initialize Google Sheets client using workload identity. | ||
Uses application default credentials which supports workload identity when running in GCP. | ||
""" | ||
logger.info('Initializing Google Sheets client with workload identity') | ||
try: | ||
credentials, project = default( | ||
scopes=['https://www.googleapis.com/auth/spreadsheets.readonly'] | ||
) | ||
logger.info(f'Successfully obtained credentials for project: {project}') | ||
self.service = build('sheets', 'v4', credentials=credentials) | ||
logger.info('Successfully initialized Google Sheets API service') | ||
except Exception as e: | ||
logger.error(f'Failed to initialize Google Sheets client: {str(e)}') | ||
self.service = None | ||
|
||
def get_usernames(self, spreadsheet_id: str, range_name: str = 'A:A') -> List[str]: | ||
"""Get list of usernames from specified Google Sheet. | ||
Args: | ||
spreadsheet_id: The ID of the Google Sheet | ||
range_name: The A1 notation of the range to fetch | ||
Returns: | ||
List of usernames from the sheet | ||
""" | ||
if not self.service: | ||
logger.error('Google Sheets service not initialized') | ||
return [] | ||
|
||
try: | ||
logger.info( | ||
f'Fetching usernames from sheet {spreadsheet_id}, range {range_name}' | ||
) | ||
result = ( | ||
self.service.spreadsheets() | ||
.values() | ||
.get(spreadsheetId=spreadsheet_id, range=range_name) | ||
.execute() | ||
) | ||
|
||
values = result.get('values', []) | ||
usernames = [ | ||
str(cell[0]).strip() for cell in values if cell and cell[0].strip() | ||
] | ||
logger.info( | ||
f'Successfully fetched {len(usernames)} usernames from Google Sheet' | ||
) | ||
return usernames | ||
|
||
except HttpError as err: | ||
logger.error(f'Error accessing Google Sheet {spreadsheet_id}: {err}') | ||
return [] | ||
except Exception as e: | ||
logger.error( | ||
f'Unexpected error accessing Google Sheet {spreadsheet_id}: {str(e)}' | ||
) | ||
return [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not necessary, just use
list
and| None
.