Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion crates/google-workspace-cli/src/auth_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ pub const FULL_SCOPES: &[&str] = &[
"https://www.googleapis.com/auth/documents",
"https://www.googleapis.com/auth/presentations",
"https://www.googleapis.com/auth/tasks",
"https://www.googleapis.com/auth/admin.reports.audit.readonly",
"https://www.googleapis.com/auth/admin.reports.usage.readonly",
"https://www.googleapis.com/auth/pubsub",
"https://www.googleapis.com/auth/cloud-platform",
];
Expand All @@ -306,6 +308,8 @@ const READONLY_SCOPES: &[&str] = &[
"https://www.googleapis.com/auth/documents.readonly",
"https://www.googleapis.com/auth/presentations.readonly",
"https://www.googleapis.com/auth/tasks.readonly",
"https://www.googleapis.com/auth/admin.reports.audit.readonly",
"https://www.googleapis.com/auth/admin.reports.usage.readonly",
];

pub fn config_dir() -> PathBuf {
Expand Down Expand Up @@ -841,6 +845,7 @@ fn map_service_to_scope_prefixes(service: &str) -> Vec<&str> {
"slides" => vec!["presentations"],
"docs" => vec!["documents"],
"people" => vec!["contacts", "directory"],
"admin-reports" => vec!["admin.reports"],
s => vec![s],
}
}
Expand Down Expand Up @@ -1565,6 +1570,14 @@ const SCOPE_ENTRIES: &[ScopeEntry] = &[
scope: "https://www.googleapis.com/auth/tasks",
label: "Google Tasks",
},
ScopeEntry {
scope: "https://www.googleapis.com/auth/admin.reports.audit.readonly",
label: "Admin Reports Audit",
},
ScopeEntry {
scope: "https://www.googleapis.com/auth/admin.reports.usage.readonly",
label: "Admin Reports Usage",
},
ScopeEntry {
scope: "https://www.googleapis.com/auth/pubsub",
label: "Cloud Pub/Sub",
Expand Down Expand Up @@ -1595,6 +1608,7 @@ fn is_app_only_scope(url: &str) -> bool {
/// They are excluded from the "Recommended" preset to avoid login failures.
///
/// Affected scope families:
/// - `admin.reports.*` — Admin Reports API audit and usage reports
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The documentation for excluded scope families is incomplete. Since all admin.* scopes require Workspace admin privileges and are excluded from the Recommended preset, it is better to document the entire family rather than just admin.reports.*.

/// - admin.*            — Admin SDK (Directory, Reports, etc.)
References
  1. Avoid introducing changes that are outside the primary goal of a pull request to prevent scope creep.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in df4b7e8. I generalized the documented family and the implementation to admin.*, and added coverage for both Admin Directory and Admin Reports scopes.

/// - `apps.*` — Alert Center, Groups Settings, Licensing, Reseller
/// - `cloud-identity.*` — Cloud Identity: devices, groups, inbound SSO, policies
/// - `ediscovery` — Google Vault
Expand All @@ -1604,7 +1618,8 @@ fn is_workspace_admin_scope(url: &str) -> bool {
let short = url
.strip_prefix("https://www.googleapis.com/auth/")
.unwrap_or(url);
short.starts_with("apps.")
short.starts_with("admin.reports.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Checking specifically for admin.reports. is redundant because the caller (is_recommended_scope at line 923) already checks for the admin. prefix. Generalizing this check to admin. makes the function a consistent source of truth for identifying admin-only scopes and ensures all admin-related scopes are handled uniformly.

    short.starts_with("admin.")
References
  1. Avoid introducing changes that are outside the primary goal of a pull request to prevent scope creep.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in df4b7e8. I generalized the documented family and the implementation to admin.*, and added coverage for both Admin Directory and Admin Reports scopes.

|| short.starts_with("apps.")
|| short.starts_with("cloud-identity.")
|| short.starts_with("chat.admin.")
|| short.starts_with("classroom.")
Expand Down Expand Up @@ -1791,6 +1806,18 @@ mod tests {
assert_eq!(scopes.len(), FULL_SCOPES.len());
}

#[test]
fn admin_reports_scopes_are_available_in_presets_and_picker() {
for scope in [
"https://www.googleapis.com/auth/admin.reports.audit.readonly",
"https://www.googleapis.com/auth/admin.reports.usage.readonly",
] {
assert!(FULL_SCOPES.contains(&scope));
assert!(READONLY_SCOPES.contains(&scope));
assert!(SCOPE_ENTRIES.iter().any(|entry| entry.scope == scope));
}
}

#[test]
#[serial_test::serial]
fn resolve_client_credentials_from_env_vars() {
Expand Down Expand Up @@ -2236,6 +2263,19 @@ mod tests {
));
}

#[test]
fn scope_matches_service_admin_reports() {
let services: HashSet<String> = ["admin-reports"].iter().map(|s| s.to_string()).collect();
assert!(scope_matches_service(
"https://www.googleapis.com/auth/admin.reports.audit.readonly",
&services
));
assert!(scope_matches_service(
"https://www.googleapis.com/auth/admin.reports.usage.readonly",
&services
));
}

// ── services filter integration tests ────────────────────────────────

#[test]
Expand Down
Loading