-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
Calendar commands (e.g. gog calendar events <calendarId>) fail with 404 notFound when using a service account in pure SA mode (no impersonation).
The root cause is getUserTimezone() in internal/cmd/time_helpers.go:56, which unconditionally calls CalendarList.Get("primary") to resolve the user's timezone. A service account running in pure mode has no "primary" calendar, so the Google Calendar API returns 404.
This blocks all calendar commands that go through ResolveTimeRange → getUserTimezone.
Repro
# Set up pure SA mode (SA email matches --account)
gog auth service-account set --key=sa-key.json sa@project.iam.gserviceaccount.com
# Calendar shared with the SA has events, but this fails:
gog calendar events someone@example.com --account sa@project.iam.gserviceaccount.com
# → Google API error (404 notFound): Not Found
# Drive commands work fine in the same setup:
gog drive ls --parent <folderId> --account sa@project.iam.gserviceaccount.com
# → OKExpected: Events listed from the shared calendar.
Actual: 404 notFound from CalendarList.Get("primary") before the actual events request is made.
Analysis
time_helpers.go:56:
func getUserTimezone(ctx context.Context, svc *calendar.Service) (*time.Location, error) {
cal, err := svc.CalendarList.Get("primary").Context(ctx).Do()
// ↑ SA has no primary calendar → 404In impersonation mode (DWD), cfg.Subject is set so the API call runs as the impersonated user who does have a primary calendar. In pure SA mode (introduced in PR #1), no impersonation occurs, so CalendarList.Get("primary") has no user context.
Possible fix
When CalendarList.Get("primary") fails in pure SA mode, fall back to:
- The timezone of the explicitly specified
calendarId(viaCalendarList.Get(calendarId)), or - UTC
✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)