Skip to content

feat: resolve ambiguous ServiceAccountConfig constructors (#15886)#16076

Open
antonjfernando2021 wants to merge 1 commit intogoogleapis:mainfrom
antonjfernando2021:feature/Make_better_constructors_ServiceAccountConfig_15886
Open

feat: resolve ambiguous ServiceAccountConfig constructors (#15886)#16076
antonjfernando2021 wants to merge 1 commit intogoogleapis:mainfrom
antonjfernando2021:feature/Make_better_constructors_ServiceAccountConfig_15886

Conversation

@antonjfernando2021
Copy link
Copy Markdown
Contributor

Description

  • Introduced ServiceAccountFilePath and ServiceAccountJsonObject structs.
  • Split the ambiguous constructor into two explicit overloads.
  • Updated internal factory functions and unit tests to ensure compatibility.

Closes #15886

@antonjfernando2021 antonjfernando2021 requested a review from a team as a code owner April 10, 2026 03:28
Copy link
Copy Markdown

@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 refactors the ServiceAccountConfig class to use the C++ type system for constructor disambiguation, replacing the previous approach that used multiple absl::optional parameters. New structs, ServiceAccountFilePath and ServiceAccountJsonObject, have been introduced to wrap the respective string values. The feedback focuses on adhering to the Google C++ Style Guide by adding descriptive comments to the new structs and replacing a redundant comment in the header file with more meaningful documentation.

Options options_;
};

struct ServiceAccountFilePath {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The Google C++ Style Guide requires a comment for every class and struct describing its purpose. This struct is used to disambiguate the ServiceAccountConfig constructors.

/// A wrapper for a service account file path.
struct ServiceAccountFilePath {
References
  1. Every class should have a comment that describes what it is and what it should be used for. (link)

explicit ServiceAccountFilePath(std::string p) : value(std::move(p)) {}
};

struct ServiceAccountJsonObject {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The Google C++ Style Guide requires a comment for every class and struct describing its purpose. This struct is used to disambiguate the ServiceAccountConfig constructors.

/// A wrapper for a service account JSON object string.
struct ServiceAccountJsonObject {
References
  1. Every class should have a comment that describes what it is and what it should be used for. (link)

// enforces this comment.
ServiceAccountConfig(absl::optional<std::string> json_object,
absl::optional<std::string> file_path, Options opts);
// Just declarations ending with a semicolon
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This comment is redundant and does not provide useful information about the class's contract or behavior. Consider removing it or replacing it with a meaningful description of the constructors.

  /// Constructs a configuration from a service account file path.

@antonjfernando2021 antonjfernando2021 force-pushed the feature/Make_better_constructors_ServiceAccountConfig_15886 branch from 0876509 to 6ea8fc0 Compare April 10, 2026 03:42
@antonjfernando2021
Copy link
Copy Markdown
Contributor Author

"I've replaced the ambiguous ServiceAccountConfig constructor with two explicit overloads using new ServiceAccountFilePath and ServiceAccountJsonObject structs, as requested in #15886. This intentionally changes the API to enforce correct usage at compile time."

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.

Make better constructors for ServiceAccountConfig

1 participant