Skip to content

Conversation

@robertvoinescu-work
Copy link
Contributor

This change introduces new overloads to the that allow specifying the credential type as a string parameter. This provides a way to create credentials from JSON data without having to specify the type statically.

@robertvoinescu-work robertvoinescu-work requested a review from a team as a code owner October 28, 2025 19:24
@gemini-code-assist
Copy link

Summary of Changes

Hello @robertvoinescu-work, 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 introduces significant enhancements to the CredentialFactory by adding new method overloads that allow specifying the credential type as a string parameter. This change provides a more flexible and dynamic way to create credentials from JSON data, removing the need for static type declarations in certain scenarios. It also improves the robustness of JSON deserialization by centralizing error handling and includes thorough unit tests to validate the new functionality.

Highlights

  • Dynamic Credential Creation: New CredentialFactory overloads (FromFileAsync, FromFile, FromStreamAsync, FromStream, FromJson) now accept a credentialType string, enabling dynamic specification of credential types from JSON data.
  • Centralized Error Handling: Introduced HandleDeserializationErrors and HandleDeserializationErrorsAsync methods to consolidate and improve error handling for JSON deserialization operations within the CredentialFactory.
  • Explicit Type Validation: An internal FromJsonParameters overload was added to enforce explicit validation of the credentialType against the type found in the JSON data, preventing mismatches.
  • Code Clarity: The internal helper method CreateCredential was renamed to CreateCredentialFromParameters for better descriptive clarity.
  • Comprehensive Testing: Extensive unit tests have been added to GoogleCredentialTests.cs to cover the new CredentialFactory overloads, including both successful credential creation and expected failure scenarios.
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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

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 introduces new overloads to CredentialFactory that allow specifying the credential type as a string, which is a useful enhancement. The implementation is clean, with good refactoring to reduce code duplication, particularly in error handling for JSON deserialization. The accompanying tests are thorough, covering both success and failure cases for the new functionality. I have one high-severity comment regarding a missing null check that could lead to an unhandled exception.

robertomiramon50-stack

This comment was marked as spam.

@robertvoinescu-work robertvoinescu-work force-pushed the feat/credential-factory-parameter branch 2 times, most recently from 8e94bfa to 75fc034 Compare November 10, 2025 19:46
@robertvoinescu-work robertvoinescu-work force-pushed the feat/credential-factory-parameter branch 5 times, most recently from 7b27ca5 to d0b9008 Compare November 11, 2025 19:57
@robertvoinescu-work robertvoinescu-work force-pushed the feat/credential-factory-parameter branch 2 times, most recently from 41ddc03 to 783d7a5 Compare November 12, 2025 20:21
Copy link
Contributor

@amanda-tarafa amanda-tarafa left a comment

Choose a reason for hiding this comment

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

Just a couple of minor changes. Thanks!

};

[Fact]
public void FromStream_WrapsDeserializationException()
Copy link
Contributor

Choose a reason for hiding this comment

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

Try one with a bad JSON also, you don't need to write the bad JSON to a file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the additional test.

@robertvoinescu-work robertvoinescu-work merged commit 9efc68a into googleapis:main Nov 14, 2025
4 checks passed
robertvoinescu-work added a commit to robertvoinescu-work/google-api-dotnet-client that referenced this pull request Nov 18, 2025
Features:
- googleapis#3064 Introduces methods to create a google credential by specifying
  the type and either a path to the credential or the credential as a
  json string.
- googleapis#3059 Support loading scopes of impersonated credentials from file.
robertvoinescu-work added a commit to robertvoinescu-work/google-api-dotnet-client that referenced this pull request Nov 18, 2025
Features:
- googleapis#3064 Adds methods to load a credential by specifying the type and either file path or json string.
- googleapis#3059 Supports loading scopes for impersonated credentials from new optional `scopes` field.
amanda-tarafa pushed a commit that referenced this pull request Nov 20, 2025
Features:
- #3064 Adds methods to load a credential by specifying the type and either file path or json string.
- #3059 Supports loading scopes for impersonated credentials from new optional `scopes` field.
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