Skip to content

drive: map scope numbers to actual values in config#9136

Open
L4z3x wants to merge 1 commit intorclone:masterfrom
L4z3x:master
Open

drive: map scope numbers to actual values in config#9136
L4z3x wants to merge 1 commit intorclone:masterfrom
L4z3x:master

Conversation

@L4z3x
Copy link

@L4z3x L4z3x commented Feb 1, 2026

What is the purpose of this change?

Fixes an issue where users entering scope numbers during interactive configuration (e.g., 1,4) would have those numbers used literally in OAuth URLs instead of being mapped to the actual scope values (drive,drive.appfolder).

This was causing invalid OAuth scope URLs like https://www.googleapis.com/auth/1 instead of https://www.googleapis.com/auth/drive.

The fix adds a lookup table in driveScopes() to map numeric choices (1-5) to their corresponding scope strings. It still accepts direct scope names and unknown values (with a warning) for backward compatibility and flexibility.

Was the change discussed in an issue or in the forum before?

No prior issue or forum discussion. Discovered during configuration when testing scope selection.

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

Copilot AI review requested due to automatic review settings February 1, 2026 12:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This change fixes how Google Drive OAuth scopes are derived from user input during configuration, ensuring numeric scope selections are mapped to the correct scope strings instead of being used literally.

Changes:

  • Introduced a validScopes lookup in driveScopes to map numeric choices (15) to their corresponding Drive scope names.
  • Allowed direct use of known scope names via the same map to validate and normalize input.
  • Logged a message and still accepted unknown scope values for forward compatibility while avoiding failures on unexpected input.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

} else {
// For unknown values, still accept them (for future-proofing)
// Log as info since this could be a user mistake
fs.Logf(nil, "Using unrecognized scope %q - valid options: 1-5 or drive, drive.readonly, drive.file, drive.appfolder, drive.metadata.readonly", scope)
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "Log as info" but this uses fs.Logf, which logs at the default (notice) level, so the implementation doesn’t match the stated intent. Consider either switching to fs.Infof to align with the comment (and make this a lower-visibility informational message about potentially mistaken scopes) or updating the comment to match the chosen log level.

Suggested change
fs.Logf(nil, "Using unrecognized scope %q - valid options: 1-5 or drive, drive.readonly, drive.file, drive.appfolder, drive.metadata.readonly", scope)
fs.Infof(nil, "Using unrecognized scope %q - valid options: 1-5 or drive, drive.readonly, drive.file, drive.appfolder, drive.metadata.readonly", scope)

Copilot uses AI. Check for mistakes.
Comment on lines +195 to +207
validScopes := map[string]string{
"1": "drive",
"2": "drive.readonly",
"3": "drive.file",
"4": "drive.appfolder",
"5": "drive.metadata.readonly",
// Also allow direct scope names
"drive": "drive",
"drive.readonly": "drive.readonly",
"drive.file": "drive.file",
"drive.appfolder": "drive.appfolder",
"drive.metadata.readonly": "drive.metadata.readonly",
}
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new numeric-to-scope mapping logic in validScopes isn’t covered by tests: TestDriveScopes in backend/drive/drive_internal_test.go only exercises named scopes. Please extend TestDriveScopes with cases like "1,4" (and possibly a mixed input with direct names) to verify that numeric inputs are correctly mapped to drive, drive.appfolder, etc., and to guard against future regressions in this behavior.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant