Skip to content

fix(Spanner.Data): Specify credential type when loading from file.#15565

Open
robertvoinescu-work wants to merge 1 commit intogoogleapis:mainfrom
robertvoinescu-work:spannerData/windyEagle
Open

fix(Spanner.Data): Specify credential type when loading from file.#15565
robertvoinescu-work wants to merge 1 commit intogoogleapis:mainfrom
robertvoinescu-work:spannerData/windyEagle

Conversation

@robertvoinescu-work
Copy link
Copy Markdown
Contributor

b/453009677

@robertvoinescu-work robertvoinescu-work requested a review from a team as a code owner April 13, 2026 23:15
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Apr 13, 2026
Copy link
Copy Markdown
Contributor

@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 the CredentialType property to the SpannerConnectionStringBuilder and SpannerClientCreationOptions, allowing users to specify the expected credential type when using a credential file. The changes include updates to client creation logic, equality checks, and documentation. Feedback suggests improving test assertions by verifying exception messages and refining the ToString output to nest the credential type within the credential file check for better clarity.

{
var builder = new SpannerConnectionStringBuilder("CredentialFile=SpannerEF-8dfc036f6000.json;CredentialType=authorized_user");
var options = new SpannerClientCreationOptions(builder);
await Assert.ThrowsAsync<InvalidOperationException>(() => options.CreateSpannerClientAsync(new Spanner.V1.SpannerSettings()));
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.

medium

According to the general rules, when asserting that an exception is thrown in a test, the exception message should also be asserted to ensure the correct exception is being propagated.

            var exception = await Assert.ThrowsAsync<InvalidOperationException>(() => options.CreateSpannerClientAsync(new Spanner.V1.SpannerSettings()));
            Assert.Contains("credential type", exception.Message);
References
  1. When asserting that an exception is thrown in a test, also assert on the exception message to ensure the correct exception is being propagated.

@amanda-tarafa amanda-tarafa added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 16, 2026
@amanda-tarafa
Copy link
Copy Markdown
Contributor

(Marking as do not merge as we need to wait for Spanner's major version to have been at least configured and we can't do that just yet).


/// <summary>
/// The expected type of the credential provided via <see cref="CredentialFile"/>.
/// Defaults to <see cref="JsonCredentialParameters.ServiceAccountCredentialType"/>.
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.

Leave a note also saying that the rest of accepted values are the ones defined in JsonCredentialParameters

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

CredentialsPath = builder.CredentialFile == "" ? null: builder.CredentialFile,
#pragma warning restore CS0618
ChannelCredentials = builder.CredentialOverride,
GoogleCredential = builder.GoogleCredential,
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.

Should you call here GetEffectiveGoogleCredential instead of later on? Also to avoid creating a new credential every time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah good point, I was keeping the original google credential override around for equality considerations, but we can just add a reference field for that. Removed.

return builder.ToString();
}

private GoogleCredential GetEffectiveGoogleCredential() =>
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.

Can't this go into SpannerConnectionStringBuilder? You can still keep the path and the type for ToString?

Or is it to avoid both places knowing how the effective credential is obtained?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes you are correct, just to keep it in one place. I chose here because it's the lowest layer in Spanner.Data that we can add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API. do not merge Indicates a pull request not ready for merge, due to either quality or timing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants