Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CosmosClient: Add check for empty keys #1639

Merged
merged 2 commits into from
Jun 18, 2020
Merged

Conversation

ealsur
Copy link
Member

@ealsur ealsur commented Jun 18, 2020

Description

Currently we check for null parameters on the CosmosClient and CosmosClientBuilder constructor. But if customers are reading the key (for example) from a configuration source (like KeyVault) where the value stored there is an empty string, this leads to a support case for a 401 - Not Authorized.

401 investigations are not easy, and from past experience, this is an easy fix that can rule out one of the most common scenarios.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

@ealsur ealsur added the bug Something isn't working label Jun 18, 2020
@ealsur ealsur self-assigned this Jun 18, 2020
@@ -194,12 +194,12 @@ protected CosmosClient()
string authKeyOrResourceToken,
CosmosClientOptions clientOptions = null)
{
if (accountEndpoint == null)
if (string.IsNullOrEmpty(accountEndpoint))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do string.IsNullOrWhiteSpace?

Copy link
Member Author

Choose a reason for hiding this comment

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

If the text is not empty, it gets checked after because it's used to create a Uri, which would fail

Copy link
Member

Choose a reason for hiding this comment

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

+1 on String.IsNullOrWhietspace for consistency - better to throw here than depend on Uri

Technically I think this can be considered a breaking change - we change the exception type in these cases. I can't think of any use case where customers would actually be broken for scenarios that work today (even when doing some custom error handling on the 401 etc.) - so I definitely don't mean this as a blocking comment - but I would call it out very explicitly in the changelog - does that make sense?

@ealsur ealsur merged commit 5ce8426 into master Jun 18, 2020
@ealsur ealsur deleted the users/ealsur/emptystringctor branch June 18, 2020 21:19
kirankumarkolli pushed a commit that referenced this pull request Jul 11, 2020
@ghost
Copy link

ghost commented Dec 15, 2021

Closing due to in-activity, pease feel free to re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants