Skip to content

[management] chores: fix lint error on google workspace - #5907

Merged
jnfrati merged 3 commits into
mainfrom
chores/fix-lint-error-google-workspace
Apr 16, 2026
Merged

jnfrati merged 3 commits into
mainfrom
chores/fix-lint-error-google-workspace

Conversation

@jnfrati

@jnfrati jnfrati commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes

Fix deprecated function on google workspace to make linter pass

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Chores
    • Improved Google Workspace authentication flow to more reliably handle service account credentials and fallback to default credential discovery, reducing authentication failures.
    • Updated Go module dependencies (OAuth, gRPC, Google API and related libraries) to newer minor/patch versions for improved compatibility, security, and performance.

@coderabbitai

coderabbitai Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4bb5df31-6e2a-4d83-a995-173d457afee1

📥 Commits

Reviewing files that changed from the base of the PR and between 771eaff and 9b3eff3.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (1)
  • go.mod
✅ Files skipped from review due to trivial changes (1)
  • go.mod

📝 Walkthrough

Walkthrough

Credentials handling for the Google Workspace manager was refactored to return a Google SDK option.ClientOption from a new getGoogleCredentialsOption. The function base64-decodes ServiceAccountKey and returns option.WithAuthCredentialsJSON(...) when present; otherwise it uses google.FindDefaultCredentials(ctx, ...) and wraps with option.WithCredentials(...).

Changes

Cohort / File(s) Summary
Google Workspace credentials logic
management/server/idp/google_workspace.go
Replaced getGoogleCredentials with getGoogleCredentialsOption. Now decodes base64 ServiceAccountKey and returns option.WithAuthCredentialsJSON(...) when present; otherwise calls google.FindDefaultCredentials(ctx, admin.AdminDirectoryUserReadonlyScope) and wraps with option.WithCredentials(...). Removed prior google.CredentialsFromJSON(...) path and eliminated use of context.Background() during credential resolution.
Module dependency bumps
go.mod
Updated multiple module versions: e.g., golang.org/x/crypto v0.48.0→v0.49.0, google.golang.org/grpc v1.79.3→v1.80.0, golang.org/x/oauth2 v0.34.0→v0.36.0, google.golang.org/api v0.257.0→v0.276.0, plus several other golang.org/x/* and Google client library indirect bumps. No API surface changes.

Sequence Diagram(s)

sequenceDiagram
  participant Manager as Manager
  participant ServiceAccount as ServiceAccount
  participant DefaultCreds as DefaultCreds
  participant GoogleAdminSDK as GoogleAdminSDK

  Manager->>ServiceAccount: read ServiceAccountKey (base64)
  alt key present
    ServiceAccount-->>Manager: decoded JSON
    Manager->>GoogleAdminSDK: option.WithAuthCredentialsJSON(decoded)
  else key empty
    Manager->>DefaultCreds: google.FindDefaultCredentials(ctx, scope)
    DefaultCreds-->>Manager: creds
    Manager->>GoogleAdminSDK: option.WithCredentials(creds)
  end
  GoogleAdminSDK-->>Manager: client ready
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • crn4
  • lixmal

Poem

🐇 I found a key in base64 light,

I hopped and decoded through the night,
If empty fields made me sigh,
I asked defaults to give it a try,
Now clients wake and APIs take flight.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing a deprecated function in Google Workspace integration to resolve a linter error, which is clearly reflected in the code changes.
Description check ✅ Passed The pull request description follows the repository template with all major sections completed: description of changes, checklist selection (bug fix), and documentation status properly documented.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chores/fix-lint-error-google-workspace

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
management/server/idp/google_workspace.go (1)

69-76: Use the caller context consistently during Google service construction.

getGoogleCredentialsOption now correctly uses ctx, but admin.NewService still receives context.Background(). Prefer ctx here to preserve cancellation/deadline behavior from callers.

♻️ Proposed change
-	service, err := admin.NewService(context.Background(),
+	service, err := admin.NewService(ctx,
 		option.WithScopes(admin.AdminDirectoryUserReadonlyScope),
 		credentialsOption,
 	)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@management/server/idp/google_workspace.go` around lines 69 - 76, The
admin.NewService call is using context.Background() which breaks caller
cancellation/deadline propagation; replace context.Background() with the passed
ctx so the caller's context is used when constructing the Google service. Locate
the block around getGoogleCredentialsOption(...) and the admin.NewService(...)
call (references: getGoogleCredentialsOption, credentialsOption,
admin.NewService, config.ServiceAccountKey) and pass ctx into admin.NewService
instead of context.Background(), keeping the existing option.WithScopes and
credentialsOption arguments unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@management/server/idp/google_workspace.go`:
- Around line 232-233: Replace uses of
option.WithAuthCredentialsJSON(option.ServiceAccount, decodeKey) with
option.WithCredentialsJSON(decodeKey) because the pinned google API version
exposes WithCredentialsJSON([]byte) not WithAuthCredentialsJSON; update every
location (e.g., the call inside the function that checks len(decodeKey) and any
similar occurrences) to pass the raw []byte decodeKey to
option.WithCredentialsJSON and remove the option.ServiceAccount argument.

---

Nitpick comments:
In `@management/server/idp/google_workspace.go`:
- Around line 69-76: The admin.NewService call is using context.Background()
which breaks caller cancellation/deadline propagation; replace
context.Background() with the passed ctx so the caller's context is used when
constructing the Google service. Locate the block around
getGoogleCredentialsOption(...) and the admin.NewService(...) call (references:
getGoogleCredentialsOption, credentialsOption, admin.NewService,
config.ServiceAccountKey) and pass ctx into admin.NewService instead of
context.Background(), keeping the existing option.WithScopes and
credentialsOption arguments unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 982834a2-3369-46e8-8a8b-861d7ffb723f

📥 Commits

Reviewing files that changed from the base of the PR and between 53b04e5 and 215a653.

📒 Files selected for processing (1)
  • management/server/idp/google_workspace.go

Comment thread management/server/idp/google_workspace.go
@sonarqubecloud

Copy link
Copy Markdown

@jnfrati
jnfrati merged commit 8ae8f20 into main Apr 16, 2026
65 of 66 checks passed
@jnfrati
jnfrati deleted the chores/fix-lint-error-google-workspace branch April 16, 2026 18:02
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.

2 participants