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.

VaultSharp.V1.SecretsEngines.Database: JsonException when deserializing a numeric rotation_period

See original GitHub issue

Describe the bug According to the Hashicorp documentation, the rotation_period can be stored as a string or an int. However, System.Text.Json (contrary to Newtonsoft.Json) does not accept non-string values when deserializing to properties of type string (in this case, VaultSharp.V1.SecretsEngines.Database.RotationPeriod).

Since our rotation_period is stored as a number, we’re being hit with a JsonException whenever we try to obtain our credentials using GetStaticCredentialsAsync on the latest version of the library.

Database Secrets Engine (rotation_period): https://developer.hashicorp.com/vault/api-docs/secret/databases#rotation_period System.Text.Json migration (non-string values): https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/migrate-from-newtonsoft?pivots=dotnet-7-0#non-string-values-for-string-properties

VaultSharp Version 1.13.0

Exception Details/Stack Trace/Error Message System.Text.Json.JsonException: ‘The JSON value could not be converted to System.String. Path: $.rotation_period | LineNumber: 0 | BytePositionInLine: 255.’ InvalidOperationException: Cannot get the value of a token type ‘Number’ as a string.

Any additional info I’m thinking a solution would be to create a custom converter that handles converting non-string values to string (similar to how Newtonsoft.Json does it) and then register the JsonConverter on the RotationPeriod property. Idea taken from: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/converters-how-to?pivots=dotnet-7-0#registration-sample---jsonconverter-on-a-property

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rajanadarcommented, Apr 1, 2023

Very cool. I’ll publish it out in a day.

1reaction
rajanadarcommented, Apr 1, 2023

hi @RatserX ,

i published the fix as a beta package: https://www.nuget.org/packages/VaultSharp/1.13.0.1-beta1 Can you try and let me know if any issues? If none, I’ll publish the proper version

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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