Skip to content

chore: update Authorized() function in all tools#2182

Merged
Yuan325 merged 1 commit into
config-branchfrom
run-lint
Dec 15, 2025
Merged

chore: update Authorized() function in all tools#2182
Yuan325 merged 1 commit into
config-branchfrom
run-lint

Conversation

@Yuan325

@Yuan325 Yuan325 commented Dec 15, 2025

Copy link
Copy Markdown
Contributor

Update Authorized() function in all tools to take a new input parameter -- resourceManager. This was updated for looker tool previously since that tool require access to the source.

When running lint and unit tests, this PR also updates the following:

  • Remove unit tests that checks for Source compatibility or missing Source during initialization. These tests are not relevant since most of the tools only check for source compatibility when it is needed (e.g. during Invoke())
  • Update sources configs to be exported (specifically alloydbadmin and cloudsqladmin).

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Yuan325, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on a significant refactoring effort to standardize the GetAuthTokenHeaderName function across a wide range of internal tools. The primary goal is to enhance consistency and flexibility in how authorization token header names are obtained, aligning with a pattern previously implemented for the looker tool. This change allows the function to access a resourceManager and handle potential errors, streamlining authorization logic across the codebase.

Highlights

  • Standardized Authorization Header Retrieval: The GetAuthTokenHeaderName function across a multitude of internal tools has been updated to accept a resourceMgr tools.SourceProvider parameter and return a (string, error) tuple. This change standardizes the interface for retrieving authorization token header names.
  • Test File Updates: Integration test files for cloudmonitoring were adjusted to remove direct initialization of BaseURL and Client fields, reflecting the updated interface and potentially centralized dependency management.
  • Minor Refactoring in Postgres Tool: A small refactoring was applied in postgresreplicationstats.go, updating a field access from t.authRequired to t.AuthRequired within the Authorized function.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request primarily updates the GetAuthTokenHeaderName function signature across a large number of tools to include a resourceMgr parameter and return an error, aligning with a new interface definition. This is a significant and necessary refactoring.

While the PR description mentions updating the Authorized function, the main change is to GetAuthTokenHeaderName. The only change to an Authorized function is a bug fix in postgresreplicationstats/postgresreplicationstats.go which is a good correction.

However, a critical issue has been introduced: the tests for the cloudmonitoring tool are now broken. The refactoring removed fields from the Tool struct, but the tests were not updated to provide the necessary dependencies through the new SourceProvider mechanism, which will cause a panic. Please see the specific comments for details on fixing these tests.

I am having trouble creating individual review comments. Click here to see my feedback.

tests/cloudmonitoring/cloud_monitoring_integration_test.go (56-57)

critical

By removing BaseURL and Client from the Tool struct, the Invoke method now relies on a SourceProvider to get these dependencies. However, the test calls Invoke with a nil SourceProvider (on line 65), which will cause a panic. The test needs to be updated to provide a mock SourceProvider and Source that returns the test server's URL and client.

tests/cloudmonitoring/cloud_monitoring_integration_test.go (102-103)

critical

Similar to the TestTool_Invoke test, removing BaseURL and Client here breaks this test. The Invoke call on line 109 passes nil for the SourceProvider, which will lead to a panic. Please update this test to use a mock SourceProvider.

@Yuan325 Yuan325 merged commit 564d9ca into config-branch Dec 15, 2025
10 of 11 checks passed
@Yuan325 Yuan325 deleted the run-lint branch December 15, 2025 23:36
Yuan325 added a commit that referenced this pull request Dec 17, 2025
Update `Authorized()` function in all tools to take a new input
parameter -- resourceManager. This was updated for looker tool
previously since that tool require access to the source.

When running lint and unit tests, this PR also updates the following:
* Remove unit tests that checks for Source compatibility or missing
Source during initialization. These tests are not relevant since most of
the tools only check for source compatibility when it is needed (e.g.
during `Invoke()`)
* Update sources configs to be exported (specifically alloydbadmin and
cloudsqladmin).
Yuan325 added a commit that referenced this pull request Dec 18, 2025
Update `Authorized()` function in all tools to take a new input
parameter -- resourceManager. This was updated for looker tool
previously since that tool require access to the source.

When running lint and unit tests, this PR also updates the following:
* Remove unit tests that checks for Source compatibility or missing
Source during initialization. These tests are not relevant since most of
the tools only check for source compatibility when it is needed (e.g.
during `Invoke()`)
* Update sources configs to be exported (specifically alloydbadmin and
cloudsqladmin).
Yuan325 added a commit that referenced this pull request Dec 19, 2025
Update `Authorized()` function in all tools to take a new input
parameter -- resourceManager. This was updated for looker tool
previously since that tool require access to the source.

When running lint and unit tests, this PR also updates the following:
* Remove unit tests that checks for Source compatibility or missing
Source during initialization. These tests are not relevant since most of
the tools only check for source compatibility when it is needed (e.g.
during `Invoke()`)
* Update sources configs to be exported (specifically alloydbadmin and
cloudsqladmin).
Yuan325 added a commit that referenced this pull request Dec 19, 2025
Update `Authorized()` function in all tools to take a new input
parameter -- resourceManager. This was updated for looker tool
previously since that tool require access to the source.

When running lint and unit tests, this PR also updates the following:
* Remove unit tests that checks for Source compatibility or missing
Source during initialization. These tests are not relevant since most of
the tools only check for source compatibility when it is needed (e.g.
during `Invoke()`)
* Update sources configs to be exported (specifically alloydbadmin and
cloudsqladmin).
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.

3 participants