-
Notifications
You must be signed in to change notification settings - Fork 902
fix: report auth errors instead of silently proceeding unauthenticated #446
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@googleworkspace/cli": patch | ||
| --- | ||
|
|
||
| fix: report auth errors instead of silently proceeding unauthenticated |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,7 +151,12 @@ TIPS: | |
| let scopes_str: Vec<&str> = scopes.iter().map(|s| s.as_str()).collect(); | ||
| let (token, auth_method) = match auth::get_token(&scopes_str).await { | ||
| Ok(t) => (Some(t), executor::AuthMethod::OAuth), | ||
| Err(_) => (None, executor::AuthMethod::None), | ||
| Err(_) if matches.get_flag("dry-run") => { | ||
| (None, executor::AuthMethod::None) | ||
| } | ||
| Err(e) => { | ||
| return Err(GwsError::Auth(format!("Calendar auth failed: {e}"))) | ||
| } | ||
| }; | ||
|
Comment on lines
152
to
160
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new authentication handling logic is a great improvement. However, this exact To improve maintainability and avoid potential inconsistencies in the future, consider abstracting this logic into a single, shared helper function. This would centralize the authentication flow, making it easier to update if needed. For example, you could create a function like this in a shared module (e.g., a new pub async fn get_auth_token_or_fail(
scopes: &[&str],
matches: &clap::ArgMatches,
service_name: &str,
) -> Result<(Option<String>, crate::executor::AuthMethod), crate::error::GwsError> {
match crate::auth::get_token(scopes).await {
Ok(t) => Ok((Some(t), crate::executor::AuthMethod::OAuth)),
Err(_) if matches.get_flag("dry-run") => Ok((None, crate::executor::AuthMethod::None)),
Err(e) => Err(crate::error::GwsError::Auth(format!(
"{} auth failed: {}",
service_name, e
))),
}
}Then, each call site could be simplified to a single line: let (token, auth_method) = crate::helpers::auth_utils::get_auth_token_or_fail(&scopes_str, matches, "Calendar").await?;
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed the pattern is duplicated. extracting a shared helper is a good follow-up but would touch 7+ files — keeping this PR scoped to fixing the silent failure. noted for a future refactor |
||
|
|
||
| let events_res = doc.resources.get("events").ok_or_else(|| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.