question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE REQ] KeyVaultKeyIdentifier.TryParse

See original GitHub issue

Library or service name. Azure.Security.KeyVault.Keys

Is your feature request related to a problem? Please describe. If I develop an application that takes user input that should be a key vault key URI I have to write the following code to validate it is a Key Vault URI.

try
{
    identifier = new KeyVaultKeyIdentifier(id);
}
catch (ArgumentException)
{
    // Invalid id
}

Ideally I would like to write

if (KeyVaultKeyIdentifier.TryParse(id, out KeyVaultKeyIdentifier identifier))
{
    // use it
}
else
{
    // Return error
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
heathscommented, Aug 19, 2021

The URI is not parsed. It is a URI, yes, but not necessarily a valid Key Vault URI. That’s why I had KeyVaultSecretIdentifier.TryParse originally. As @tg-msft pointed out from the .NET Framework Guidelines,

DO NOT use exceptions for the normal flow of control, if possible. Prefer Tester–Doer or the Try pattern to throwing exceptions in common cases.

The point of this struct was to parse a URI as a valid Key Vault (or Managed HSM) URI. I agree that we need a TryParse.

1reaction
KrzysztofCwalinacommented, Aug 19, 2021

I am not totally opposed to digging deeper here and possibly solving a problem, but:

It’s not really parsing. The URI is already parsed when it’s passed to the ctor. The issue seems to be that some users (e.g. @jimmyca15) do not like exceptions for invalid arguments. I totally understand issues with C# exception handling (I am myself not a big fan), and I talked with the C# team many times about it, but don’t think TryParse was intended for that. In .NET, we throw exceptions for invalid arguments.

.NET guidelines specifically state that Try methods should not be added because we don’t like exceptions. Try methods are performance optimizations, and so if you add them you need to show that performance is a problem (not in microbenchmarks).

If we started to add Try methods to all places where we don’t like exceptions, we would end up with every BCL API duplicated (try and non-try variants).

@MadsTorgersen, @jaredpar, if would be nice to have try expressions in the language, just like we planned in M# 😃

see “int value1 = try Foo() else 42;” @ http://joeduffyblog.com/2016/02/07/the-error-model/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quickstart: Azure Key Vault secret client library for JavaScript
Learn how to create, retrieve, and delete secrets from an Azure key vault using the JavaScript client library.
Read more >
Handling KeyVault secret rotation changes utilized by an ...
This sample showcases one way to handle when a KeyVault secret used by your Azure Function is "rolled" or updated as part of...
Read more >
Can't read value from Azure Key Vault
As described in the article, I'm using Managed Service Identity (MSI) but looks like I'm unable to read values from Key Vault.
Read more >
Securing Web Application Secrets Through Azure Key Vault
Key Vault can be used to store the cryptographic secrets and keys such as authentication keys, storage account keys, data encryption keys, ...
Read more >
How To Authorize Your Key Vault Secrets To Serverless ...
In this article, we will learn how to authorize our Azure Function to access Key Vault secrets.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found