From ab208f252603387331b5bbb69626daf989f02292 Mon Sep 17 00:00:00 2001 From: bbartels Date: Fri, 20 Feb 2026 23:40:18 +0000 Subject: [PATCH 1/6] Adds aot support --- src/VaultSharp/Core/AotRequestModels.cs | 344 ++++++++++++++++++ src/VaultSharp/Core/Polymath.cs | 33 +- src/VaultSharp/Core/VaultApiException.cs | 24 +- src/VaultSharp/Core/VaultSharpJsonContext.cs | 298 +++++++++++++++ .../AppRole/AppRoleAuthMethodProvider.cs | 24 +- .../Cert/CertAuthMethodLoginProvider.cs | 2 +- .../CloudFoundryAuthMethodLoginProvider.cs | 10 +- .../LDAP/LDAPAuthMethodProvider.cs | 4 +- .../Token/TokenAuthMethodProvider.cs | 4 +- .../V1/Commons/BackendListingVisibility.cs | 4 + .../SecretsEngines/AWS/AWSCredentialsType.cs | 4 + .../ActiveDirectoryLibraryProvider.cs | 6 +- .../Models/CreateAliCloudRoleModel.cs | 11 + .../Consul/Models/ConsulTokenType.cs | 4 + .../Enterprise/KMIP/CertificateFormat.cs | 4 + .../KMIP/KMIPSecretsEngineProvider.cs | 2 +- .../GoogleCloud/ServiceAccountKeyAlgorithm.cs | 4 + .../ServiceAccountPrivateKeyType.cs | 4 + .../Identity/IdentitySecretsEngineProvider.cs | 2 +- .../V2/KeyValueSecretsEngineV2Provider.cs | 8 +- .../SecretsEngines/PKI/CertificateFormat.cs | 4 + .../SecretsEngines/PKI/CertificateKeyType.cs | 4 + .../PKI/CertificateTidyState.cs | 4 + .../PKI/PKISecretsEngineProvider.cs | 2 +- .../V1/SecretsEngines/PKI/PrivateKeyFormat.cs | 4 + .../V1/SecretsEngines/SSH/SSHKeyType.cs | 4 + .../SSH/SSHSecretsEngineProvider.cs | 2 +- .../TOTP/TOTPSecretsEngineProvider.cs | 2 +- .../Transit/OutputEncodingFormat.cs | 4 + .../Transit/RandomBytesSource.cs | 4 + .../Transit/SignRequestOptions.cs | 8 + .../Transit/TransitDataKeyType.cs | 4 + .../Transit/TransitHashFunction.cs | 4 + .../V1/SystemBackend/AbstractAuditBackend.cs | 3 - .../AuditBackendJsonConverter.cs | 18 +- .../V1/SystemBackend/CustomAuditBackend.cs | 1 + .../Enterprise/EnterpriseProvider.cs | 6 +- .../V1/SystemBackend/FileAuditBackend.cs | 1 + .../V1/SystemBackend/SyslogAuditBackend.cs | 1 + .../V1/SystemBackend/SystemBackendProvider.cs | 86 ++--- src/VaultSharp/VaultClientSettings.cs | 9 + src/VaultSharp/VaultSharp.csproj | 9 + 42 files changed, 865 insertions(+), 115 deletions(-) create mode 100644 src/VaultSharp/Core/AotRequestModels.cs create mode 100644 src/VaultSharp/Core/VaultSharpJsonContext.cs diff --git a/src/VaultSharp/Core/AotRequestModels.cs b/src/VaultSharp/Core/AotRequestModels.cs new file mode 100644 index 00000000..64853dfd --- /dev/null +++ b/src/VaultSharp/Core/AotRequestModels.cs @@ -0,0 +1,344 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace VaultSharp.Core +{ + // Shape: { token } + internal sealed class TokenRequest + { + [JsonPropertyName("token")] + public string Token { get; set; } + } + + // Shape: { token, client_id } + internal sealed class TokenClientIdRequest + { + [JsonPropertyName("token")] + public string Token { get; set; } + + [JsonPropertyName("client_id")] + public string ClientId { get; set; } + } + + // Shape: { input } + internal sealed class InputRequest + { + [JsonPropertyName("input")] + public string Input { get; set; } + } + + // Shape: { path, token } + internal sealed class PathTokenRequest + { + [JsonPropertyName("path")] + public string Path { get; set; } + + [JsonPropertyName("token")] + public string Token { get; set; } + } + + // Shape: { path, accessor } + internal sealed class PathAccessorRequest + { + [JsonPropertyName("path")] + public string Path { get; set; } + + [JsonPropertyName("accessor")] + public string Accessor { get; set; } + } + + // Shape: { path } + internal sealed class PathRequest + { + [JsonPropertyName("path")] + public string Path { get; set; } + } + + // Shape: { otp, pgpKey } — note: the original anonymous type uses "pgpKey" as the C# property name, and STJ without custom naming policy serializes it as "pgpKey" + internal sealed class OtpPgpKeyRequest + { + [JsonPropertyName("otp")] + public string Otp { get; set; } + + [JsonPropertyName("pgpKey")] + public string PgpKey { get; set; } + } + + // Shape: { key, nonce } — used in root token generation AND rekey + internal sealed class KeyNonceRequest + { + [JsonPropertyName("key")] + public string Key { get; set; } + + [JsonPropertyName("nonce")] + public string Nonce { get; set; } + } + + // Shape: { value } — string value + internal sealed class ValueRequest + { + [JsonPropertyName("value")] + public string Value { get; set; } + } + + // Shape: { secret_shares, secret_threshold, pgp_keys, backup } + internal sealed class RekeyInitRequest + { + [JsonPropertyName("secret_shares")] + public int SecretShares { get; set; } + + [JsonPropertyName("secret_threshold")] + public int SecretThreshold { get; set; } + + [JsonPropertyName("pgp_keys")] + public string[] PgpKeys { get; set; } + + [JsonPropertyName("backup")] + public bool Backup { get; set; } + } + + // Shape: { key, reset } + internal sealed class KeyResetRequest + { + [JsonPropertyName("key")] + public string Key { get; set; } + + [JsonPropertyName("reset")] + public bool Reset { get; set; } + } + + // Shape: { max_ttl } + internal sealed class MaxTtlRequest + { + [JsonPropertyName("max_ttl")] + public string MaxTtl { get; set; } + } + + // Shape: { accessor } + internal sealed class AccessorRequest + { + [JsonPropertyName("accessor")] + public string Accessor { get; set; } + } + + // Shape: { code } + internal sealed class CodeRequest + { + [JsonPropertyName("code")] + public string Code { get; set; } + } + + // Shape: { ip, username } + internal sealed class IpUsernameRequest + { + [JsonPropertyName("ip")] + public string Ip { get; set; } + + [JsonPropertyName("username")] + public string Username { get; set; } + } + + // Shape: { serial_number } + internal sealed class SerialNumberRequest + { + [JsonPropertyName("serial_number")] + public string SerialNumber { get; set; } + } + + // Shape: { cas } — used nested inside a dictionary + internal sealed class CasRequest + { + [JsonPropertyName("cas")] + public int Cas { get; set; } + } + + // Shape: { versions } + internal sealed class VersionsRequest + { + [JsonPropertyName("versions")] + public System.Collections.Generic.IList Versions { get; set; } + } + + // Shape: { format } — used with KMIP CertificateFormat enum + internal sealed class FormatRequest + { + [JsonPropertyName("format")] + public string Format { get; set; } + } + + // Shape: { ttl } — nullable long + internal sealed class TtlRequest + { + [JsonPropertyName("ttl")] + public long? Ttl { get; set; } + } + + // Shape: { service_account_names } + internal sealed class ServiceAccountNamesRequest + { + [JsonPropertyName("service_account_names")] + public List ServiceAccountNames { get; set; } + } + + // Shape: { increment } + internal sealed class IncrementRequest + { + [JsonPropertyName("increment")] + public string Increment { get; set; } + } + + // Shape: { policies } — string + internal sealed class PoliciesRequest + { + [JsonPropertyName("policies")] + public string Policies { get; set; } + } + + // Shape: { policies, groups } + internal sealed class PoliciesGroupsRequest + { + [JsonPropertyName("policies")] + public string Policies { get; set; } + + [JsonPropertyName("groups")] + public string Groups { get; set; } + } + + // Shape: { name } + internal sealed class NameRequest + { + [JsonPropertyName("name")] + public string Name { get; set; } + } + + // Shape: { secret_id } + internal sealed class SecretIdRequest + { + [JsonPropertyName("secret_id")] + public string SecretId { get; set; } + } + + // Shape: { secret_id_accessor } + internal sealed class SecretIdAccessorRequest + { + [JsonPropertyName("secret_id_accessor")] + public string SecretIdAccessor { get; set; } + } + + // Shape: { secret_id_num_uses } + internal sealed class SecretIdNumUsesRequest + { + [JsonPropertyName("secret_id_num_uses")] + public long SecretIdNumUses { get; set; } + } + + // Shape: { secret_id_ttl } + internal sealed class SecretIdTtlRequest + { + [JsonPropertyName("secret_id_ttl")] + public long SecretIdTtl { get; set; } + } + + // Shape: { token_ttl } + internal sealed class TokenTtlRequest + { + [JsonPropertyName("token_ttl")] + public long TokenTtl { get; set; } + } + + // Shape: { token_max_ttl } + internal sealed class TokenMaxTtlRequest + { + [JsonPropertyName("token_max_ttl")] + public long TokenMaxTtl { get; set; } + } + + // Shape: { bind_secret_id } + internal sealed class BindSecretIdRequest + { + [JsonPropertyName("bind_secret_id")] + public bool BindSecretId { get; set; } + } + + // Shape: { secret_id_bound_cidrs } + internal sealed class SecretIdBoundCidrsRequest + { + [JsonPropertyName("secret_id_bound_cidrs")] + public List SecretIdBoundCidrs { get; set; } + } + + // Shape: { token_bound_cidrs } + internal sealed class TokenBoundCidrsRequest + { + [JsonPropertyName("token_bound_cidrs")] + public List TokenBoundCidrs { get; set; } + } + + // Shape: { token_period } + internal sealed class TokenPeriodRequest + { + [JsonPropertyName("token_period")] + public long TokenPeriod { get; set; } + } + + // Shape: { hmac } + internal sealed class HmacRequest + { + [JsonPropertyName("hmac")] + public bool Hmac { get; set; } + } + + // Shape: { lease_id } + internal sealed class LeaseIdRequest + { + [JsonPropertyName("lease_id")] + public string LeaseId { get; set; } + } + + // Shape: { lease_id, increment } + internal sealed class LeaseRenewRequest + { + [JsonPropertyName("lease_id")] + public string LeaseId { get; set; } + + [JsonPropertyName("increment")] + public int Increment { get; set; } + } + + // Shape: { level } + internal sealed class LevelRequest + { + [JsonPropertyName("level")] + public string Level { get; set; } + } + + // Shape: { rules } + internal sealed class RulesRequest + { + [JsonPropertyName("rules")] + public string Rules { get; set; } + } + + // Shape: { policy } + internal sealed class PolicyTextRequest + { + [JsonPropertyName("policy")] + public string Policy { get; set; } + } + + // Shape: { role, cf_instance_cert, signing_time, signature } — for CloudFoundry login + internal sealed class CloudFoundryLoginRequest + { + [JsonPropertyName("role")] + public string Role { get; set; } + + [JsonPropertyName("cf_instance_cert")] + public string CfInstanceCert { get; set; } + + [JsonPropertyName("signing_time")] + public string SigningTime { get; set; } + + [JsonPropertyName("signature")] + public string Signature { get; set; } + } +} diff --git a/src/VaultSharp/Core/Polymath.cs b/src/VaultSharp/Core/Polymath.cs index 0a4b208f..a0acfc21 100644 --- a/src/VaultSharp/Core/Polymath.cs +++ b/src/VaultSharp/Core/Polymath.cs @@ -12,6 +12,9 @@ using VaultSharp.V1.Commons; using System.Text.Json.Nodes; using System.Text.Json; +#if NET8_0_OR_GREATER +using System.Text.Json.Serialization.Metadata; +#endif namespace VaultSharp.Core { @@ -28,15 +31,26 @@ internal class Polymath private readonly HttpClient _httpClient; private Lazy> _lazyVaultToken; private readonly IAuthMethodLoginProvider _authMethodLoginProvider; + private readonly JsonSerializerOptions _jsonSerializerOptions; public HttpMethod ListHttpMethod { get; } = new HttpMethod("LIST"); public VaultClientSettings VaultClientSettings { get; } + internal JsonSerializerOptions JsonSerializerOptions => _jsonSerializerOptions; public Polymath(VaultClientSettings vaultClientSettings) { VaultClientSettings = vaultClientSettings; + _jsonSerializerOptions = VaultClientSettings.JsonSerializerOptions ?? new JsonSerializerOptions(); + +#if NET8_0_OR_GREATER + if (!_jsonSerializerOptions.TypeInfoResolverChain.Contains(VaultSharpJsonContext.Default)) + { + _jsonSerializerOptions.TypeInfoResolverChain.Insert(0, VaultSharpJsonContext.Default); + } +#endif + #if NET45 var handler = new WebRequestHandler(); @@ -200,7 +214,11 @@ protected async Task MakeRequestAsync(string resourcePath, { var requestUri = new Uri(_httpClient.BaseAddress, new Uri(resourcePath, UriKind.Relative)); - string requestJson = requestData != null ? JsonSerializer.Serialize(requestData) : null; +#if NET8_0_OR_GREATER + string requestJson = requestData != null ? JsonSerializer.Serialize(requestData, _jsonSerializerOptions.GetTypeInfo(requestData.GetType())) : null; +#else + string requestJson = requestData != null ? JsonSerializer.Serialize(requestData, requestData.GetType(), _jsonSerializerOptions) : null; +#endif var requestContent = requestJson != null ? new StringContent(requestJson, Encoding.UTF8) @@ -237,7 +255,11 @@ protected async Task MakeRequestAsync(string resourcePath, httpRequestMessage = new HttpRequestMessage(httpMethod, requestUri) { Content = requestData != null - ? new StringContent(JsonSerializer.Serialize(requestData), Encoding.UTF8, "application/merge-patch+json") +#if NET8_0_OR_GREATER + ? new StringContent(JsonSerializer.Serialize(requestData, _jsonSerializerOptions.GetTypeInfo(requestData.GetType())), Encoding.UTF8, "application/merge-patch+json") +#else + ? new StringContent(JsonSerializer.Serialize(requestData, requestData.GetType(), _jsonSerializerOptions), Encoding.UTF8, "application/merge-patch+json") +#endif : null }; @@ -275,7 +297,12 @@ protected async Task MakeRequestAsync(string resourcePath, { if (!string.IsNullOrWhiteSpace(responseText)) { - var response = rawResponse ? (responseText as TResponse) : JsonSerializer.Deserialize(responseText); + +#if NET8_0_OR_GREATER + var response = rawResponse ? (responseText as TResponse) : (TResponse)JsonSerializer.Deserialize(responseText, _jsonSerializerOptions.GetTypeInfo(typeof(TResponse))); +#else + var response = rawResponse ? (responseText as TResponse) : JsonSerializer.Deserialize(responseText, _jsonSerializerOptions); +#endif return response; } diff --git a/src/VaultSharp/Core/VaultApiException.cs b/src/VaultSharp/Core/VaultApiException.cs index aa4d48f7..040dccce 100644 --- a/src/VaultSharp/Core/VaultApiException.cs +++ b/src/VaultSharp/Core/VaultApiException.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Net; using System.Text.Json; -using System.Text.Json.Serialization; namespace VaultSharp.Core { @@ -67,16 +66,29 @@ public VaultApiException(HttpStatusCode httpStatusCode, string message) : base(m try { - var structured = JsonSerializer.Deserialize>>(message); + using (var document = JsonDocument.Parse(message)) + { + var root = document.RootElement; - if (structured.ContainsKey("errors")) + if (root.TryGetProperty("errors", out var errorsElement) && errorsElement.ValueKind == JsonValueKind.Array) { - ApiErrors = structured["errors"]; + var errors = new List(); + foreach (var item in errorsElement.EnumerateArray()) + { + errors.Add(item.GetString()); + } + ApiErrors = errors; } - if (structured.ContainsKey("warnings")) + if (root.TryGetProperty("warnings", out var warningsElement) && warningsElement.ValueKind == JsonValueKind.Array) { - ApiWarnings = structured["warnings"]; + var warnings = new List(); + foreach (var item in warningsElement.EnumerateArray()) + { + warnings.Add(item.GetString()); + } + ApiWarnings = warnings; + } } } catch diff --git a/src/VaultSharp/Core/VaultSharpJsonContext.cs b/src/VaultSharp/Core/VaultSharpJsonContext.cs new file mode 100644 index 00000000..53c7a6a2 --- /dev/null +++ b/src/VaultSharp/Core/VaultSharpJsonContext.cs @@ -0,0 +1,298 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; + +namespace VaultSharp.Core +{ +#if NET8_0_OR_GREATER + + [JsonSourceGenerationOptions( + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + PropertyNamingPolicy = JsonKnownNamingPolicy.Unspecified)] + + // === Response types (Secret wrappers) === + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret>))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret>))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret>>))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret>>>))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret>))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret>))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret>))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + + // === Standalone response types === + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.HealthStatus))] + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.Leader))] + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.MasterCredentials))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.ReadNamedKeyResponse))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.ReadRoleResponse))] + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.RekeyProgress))] + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.RekeyStatus))] + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.RootTokenGenerationStatus))] + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.SealStatus))] + [JsonSerializable(typeof(JsonObject))] + + // === Audit backend concrete types (for AuditBackendJsonConverter) === + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.FileAuditBackend))] + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.SyslogAuditBackend))] + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.CustomAuditBackend))] + + // === Dictionary types === + [JsonSerializable(typeof(Dictionary))] + [JsonSerializable(typeof(Dictionary))] + + // === AliCloud policy list types (serialized inline as JSON strings) === + [JsonSerializable(typeof(List))] + [JsonSerializable(typeof(List))] + + // === Request model types (from AotRequestModels.cs) === + [JsonSerializable(typeof(TokenRequest))] + [JsonSerializable(typeof(TokenClientIdRequest))] + [JsonSerializable(typeof(InputRequest))] + [JsonSerializable(typeof(PathTokenRequest))] + [JsonSerializable(typeof(PathAccessorRequest))] + [JsonSerializable(typeof(PathRequest))] + [JsonSerializable(typeof(OtpPgpKeyRequest))] + [JsonSerializable(typeof(KeyNonceRequest))] + [JsonSerializable(typeof(ValueRequest))] + [JsonSerializable(typeof(RekeyInitRequest))] + [JsonSerializable(typeof(KeyResetRequest))] + [JsonSerializable(typeof(MaxTtlRequest))] + [JsonSerializable(typeof(AccessorRequest))] + [JsonSerializable(typeof(CodeRequest))] + [JsonSerializable(typeof(IpUsernameRequest))] + [JsonSerializable(typeof(SerialNumberRequest))] + [JsonSerializable(typeof(CasRequest))] + [JsonSerializable(typeof(VersionsRequest))] + [JsonSerializable(typeof(FormatRequest))] + [JsonSerializable(typeof(TtlRequest))] + [JsonSerializable(typeof(ServiceAccountNamesRequest))] + [JsonSerializable(typeof(IncrementRequest))] + [JsonSerializable(typeof(PoliciesRequest))] + [JsonSerializable(typeof(PoliciesGroupsRequest))] + [JsonSerializable(typeof(NameRequest))] + [JsonSerializable(typeof(SecretIdRequest))] + [JsonSerializable(typeof(SecretIdAccessorRequest))] + [JsonSerializable(typeof(SecretIdNumUsesRequest))] + [JsonSerializable(typeof(SecretIdTtlRequest))] + [JsonSerializable(typeof(TokenTtlRequest))] + [JsonSerializable(typeof(TokenMaxTtlRequest))] + [JsonSerializable(typeof(BindSecretIdRequest))] + [JsonSerializable(typeof(SecretIdBoundCidrsRequest))] + [JsonSerializable(typeof(TokenBoundCidrsRequest))] + [JsonSerializable(typeof(TokenPeriodRequest))] + [JsonSerializable(typeof(HmacRequest))] + [JsonSerializable(typeof(LeaseIdRequest))] + [JsonSerializable(typeof(LeaseRenewRequest))] + [JsonSerializable(typeof(LevelRequest))] + [JsonSerializable(typeof(RulesRequest))] + [JsonSerializable(typeof(PolicyTextRequest))] + [JsonSerializable(typeof(CloudFoundryLoginRequest))] + + // === Named request/model types used as requestData === + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.AbstractAuditBackend))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AuthMethod))] + [JsonSerializable(typeof(VaultSharp.Core.BackendConfig))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.SecretsEngine))] + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.CORSConfig))] + [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.InitOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.KeyValue.V2.KeyValue2ConfigModel))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.KeyValue.V2.PatchSecretDataRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.KeyValue.V2.CustomMetadataRequest))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AppRole.Models.AppRoleRoleModel))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AppRole.Models.RoleIdInfo))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AppRole.Models.PullSecretIdRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AppRole.Models.PushSecretIdRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Database.Models.ConnectionConfigModel))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Database.Role))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Database.StaticRole))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.CreateKeyRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.UpdateKeyRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.EncryptRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.DecryptRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.RewrapRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.DataKeyRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.SignRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.VerifyRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.HashRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.HmacRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.RandomBytesRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.TrimKeyRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.ImportKeyRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.ImportKeyVersionRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.RestoreKeyRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.CacheConfigRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.PKI.CertificateCredentialsRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.PKI.SignCertificatesRequestOptions))] + // TODO: PKITidyRequest does not exist; the actual class is CertificateTidyRequest in VaultSharp.V1.SecretsEngines.PKI + // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.PKI.PKITidyRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.PKI.CertificateAutoTidyRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.SSH.SignKeyRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.TOTP.TOTPCreateKeyRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.RabbitMQ.RabbitMQRole))] + // TODO: ConsulAccessConfigModel does not exist; the actual class is AccessConfigModel in VaultSharp.V1.SecretsEngines.Consul.Models + // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Consul.Models.ConsulAccessConfigModel))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Consul.Models.CreateConsulRoleModel))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.AWS.CreateAWSRoleModel))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.AliCloud.Models.CreateAliCloudRoleModel))] + // TODO: CreateAliCloudRootCredentialsConfigModel does not exist; the actual class is CreateRootCredentialsConfigModel in VaultSharp.V1.SecretsEngines.AliCloud.Models + // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.AliCloud.CreateAliCloudRootCredentialsConfigModel))] + // TODO: CreateADConnectionConfigModel does not exist; the actual class is CreateConnectionConfigModel in VaultSharp.V1.SecretsEngines.ActiveDirectory.Models + // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.ActiveDirectory.CreateADConnectionConfigModel))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.ActiveDirectory.Models.CreateActiveDirectoryRoleModel))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.ActiveDirectory.Models.CreateServiceAccountSetModel))] + // TODO: CreateOpenLDAPDynamicRole does not exist in the codebase + // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.OpenLDAP.CreateOpenLDAPDynamicRole))] + // TODO: CreateOpenLDAPStaticRole does not exist in the codebase + // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.OpenLDAP.CreateOpenLDAPStaticRole))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.Token.CreateTokenRequest))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.Token.CreateTokenRoleRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.CreateEntityRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.UpdateEntityRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.CreateEntityByNameRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.UpdateEntityByNameRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.MergeEntitiesRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.BatchDeleteEntitiesRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.CreateNamedKeyRequest))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.CreateRoleRequest))] + // TODO: CreateKubernetesCredentialRequestOptions does not exist in the codebase + // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Kubernetes.CreateKubernetesCredentialRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Enterprise.Transform.EncodeRequestOptions))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Enterprise.Transform.DecodeRequestOptions))] + + // === Auth method login types === + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AWS.AbstractAWSAuthMethodInfo))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AliCloud.AliCloudAuthMethodInfo))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.Azure.AzureAuthMethodInfo))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.GoogleCloud.GoogleCloudAuthMethodInfo))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.JWT.JWTAuthMethodInfo))] + [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.Kubernetes.KubernetesAuthMethodInfo))] + + internal partial class VaultSharpJsonContext : JsonSerializerContext + { + } + +#else + + // Fallback for older TFMs: a no-op resolver that always returns null, + // causing System.Text.Json to fall back to reflection-based serialization. + internal class VaultSharpJsonContext : IJsonTypeInfoResolver + { + public static VaultSharpJsonContext Default { get; } = new VaultSharpJsonContext(); + + public JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options) => null; + } + +#endif +} diff --git a/src/VaultSharp/V1/AuthMethods/AppRole/AppRoleAuthMethodProvider.cs b/src/VaultSharp/V1/AuthMethods/AppRole/AppRoleAuthMethodProvider.cs index cac4393a..bd2eddd9 100644 --- a/src/VaultSharp/V1/AuthMethods/AppRole/AppRoleAuthMethodProvider.cs +++ b/src/VaultSharp/V1/AuthMethods/AppRole/AppRoleAuthMethodProvider.cs @@ -90,7 +90,7 @@ public async Task> ReadSecretIdInfoAsync(string roleNam Checker.NotNull(roleName, "roleName"); Checker.NotNull(secretId, "secretId"); - return await _polymath.MakeVaultApiRequest>("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id/lookup", HttpMethod.Post, requestData: new { secret_id = secretId }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + return await _polymath.MakeVaultApiRequest>("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id/lookup", HttpMethod.Post, requestData: new SecretIdRequest { SecretId = secretId }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task DestroySecretIdAsync(string roleName, string secretId, string mountPoint = AuthMethodDefaultPaths.AppRole) @@ -99,7 +99,7 @@ public async Task DestroySecretIdAsync(string roleName, string secretId, string Checker.NotNull(roleName, "roleName"); Checker.NotNull(secretId, "secretId"); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id/destroy", HttpMethod.Post, requestData: new { secret_id = secretId }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id/destroy", HttpMethod.Post, requestData: new SecretIdRequest { SecretId = secretId }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task> ReadSecretIdInfoByAccessorAsync(string roleName, string secretIdAccessor, string mountPoint = AuthMethodDefaultPaths.AppRole) @@ -108,7 +108,7 @@ public async Task> ReadSecretIdInfoByAccessorAsync(stri Checker.NotNull(roleName, "roleName"); Checker.NotNull(secretIdAccessor, "secretIdAccessor"); - return await _polymath.MakeVaultApiRequest>("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id-accessor/lookup", HttpMethod.Post, requestData: new { secret_id_accessor = secretIdAccessor }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + return await _polymath.MakeVaultApiRequest>("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id-accessor/lookup", HttpMethod.Post, requestData: new SecretIdAccessorRequest { SecretIdAccessor = secretIdAccessor }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task DestroySecretIdByAccessorAsync(string roleName, string secretIdAccessor, string mountPoint = AuthMethodDefaultPaths.AppRole) @@ -117,7 +117,7 @@ public async Task DestroySecretIdByAccessorAsync(string roleName, string secretI Checker.NotNull(roleName, "roleName"); Checker.NotNull(secretIdAccessor, "secretIdAccessor"); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id-accessor/destroy", HttpMethod.Post, requestData: new { secret_id_accessor = secretIdAccessor }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id-accessor/destroy", HttpMethod.Post, requestData: new SecretIdAccessorRequest { SecretIdAccessor = secretIdAccessor }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task> PushNewSecretIdAsync(string roleName, PushSecretIdRequestOptions secretIdRequestOptions = null, string mountPoint = AuthMethodDefaultPaths.AppRole) @@ -167,7 +167,7 @@ public async Task WriteRoleSecretIdNumberOfUsesAsync(string roleName, long secre Checker.NotNull(mountPoint, "mountPoint"); Checker.NotNull(roleName, "roleName"); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id-num-uses", HttpMethod.Post, new { secret_id_num_uses = secretIdNumberOfUses }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id-num-uses", HttpMethod.Post, new SecretIdNumUsesRequest { SecretIdNumUses = secretIdNumberOfUses }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task DeleteRoleSecretIdNumberOfUsesAsync(string roleName, string mountPoint = AuthMethodDefaultPaths.AppRole) @@ -193,7 +193,7 @@ public async Task WriteRoleSecretIdTimeToLiveAsync(string roleName, long secretI Checker.NotNull(mountPoint, "mountPoint"); Checker.NotNull(roleName, "roleName"); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id-ttl", HttpMethod.Post, new { secret_id_ttl = secretIdTimeToLive }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id-ttl", HttpMethod.Post, new SecretIdTtlRequest { SecretIdTtl = secretIdTimeToLive }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task DeleteRoleSecretIdTimeToLiveAsync(string roleName, string mountPoint = AuthMethodDefaultPaths.AppRole) @@ -219,7 +219,7 @@ public async Task WriteRoleTokenTimeToLiveAsync(string roleName, long tokenTimeT Checker.NotNull(mountPoint, "mountPoint"); Checker.NotNull(roleName, "roleName"); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/token-ttl", HttpMethod.Post, new { token_ttl = tokenTimeToLive }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/token-ttl", HttpMethod.Post, new TokenTtlRequest { TokenTtl = tokenTimeToLive }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task DeleteRoleTokenTimeToLiveAsync(string roleName, string mountPoint = AuthMethodDefaultPaths.AppRole) @@ -245,7 +245,7 @@ public async Task WriteRoleTokenMaximumTimeToLiveAsync(string roleName, long tok Checker.NotNull(mountPoint, "mountPoint"); Checker.NotNull(roleName, "roleName"); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/token-max-ttl", HttpMethod.Post, new { token_max_ttl = tokenMaximumTimeToLive }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/token-max-ttl", HttpMethod.Post, new TokenMaxTtlRequest { TokenMaxTtl = tokenMaximumTimeToLive }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task DeleteRoleTokenMaximumTimeToLiveAsync(string roleName, string mountPoint = AuthMethodDefaultPaths.AppRole) @@ -271,7 +271,7 @@ public async Task WriteRoleBindSecretIdAsync(string roleName, bool bindSecretId, Checker.NotNull(mountPoint, "mountPoint"); Checker.NotNull(roleName, "roleName"); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/bind-secret-id", HttpMethod.Post, new { bind_secret_id = bindSecretId }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/bind-secret-id", HttpMethod.Post, new BindSecretIdRequest { BindSecretId = bindSecretId }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task DeleteRoleBindSecretIdAsync(string roleName, string mountPoint = AuthMethodDefaultPaths.AppRole) @@ -310,7 +310,7 @@ public async Task WriteRoleSecretIdBoundCIDRsAsync(string roleName, List Checker.NotNull(mountPoint, "mountPoint"); Checker.NotNull(roleName, "roleName"); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id-bound-cidrs", HttpMethod.Post, new { secret_id_bound_cidrs = secretIdBoundCIDRs }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/secret-id-bound-cidrs", HttpMethod.Post, new SecretIdBoundCidrsRequest { SecretIdBoundCidrs = secretIdBoundCIDRs }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task DeleteRoleSecretIdBoundCIDRsAsync(string roleName, string mountPoint = AuthMethodDefaultPaths.AppRole) @@ -355,7 +355,7 @@ public async Task WriteRoleTokenBoundCIDRsAsync(string roleName, List to Checker.NotNull(mountPoint, "mountPoint"); Checker.NotNull(roleName, "roleName"); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/token-bound-cidrs", HttpMethod.Post, new { token_bound_cidrs = tokenBoundCIDRs }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/token-bound-cidrs", HttpMethod.Post, new TokenBoundCidrsRequest { TokenBoundCidrs = tokenBoundCIDRs }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task DeleteRoleTokenBoundCIDRsAsync(string roleName, string mountPoint = AuthMethodDefaultPaths.AppRole) @@ -381,7 +381,7 @@ public async Task WriteRolePeriodAsync(string roleName, long period, string moun Checker.NotNull(mountPoint, "mountPoint"); Checker.NotNull(roleName, "roleName"); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/period", HttpMethod.Post, new { token_period = period }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/role/" + roleName.Trim('/') + "/period", HttpMethod.Post, new TokenPeriodRequest { TokenPeriod = period }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task DeleteRolePeriodAsync(string roleName, string mountPoint = AuthMethodDefaultPaths.AppRole) diff --git a/src/VaultSharp/V1/AuthMethods/Cert/CertAuthMethodLoginProvider.cs b/src/VaultSharp/V1/AuthMethods/Cert/CertAuthMethodLoginProvider.cs index c46ac85f..92ba5889 100644 --- a/src/VaultSharp/V1/AuthMethods/Cert/CertAuthMethodLoginProvider.cs +++ b/src/VaultSharp/V1/AuthMethods/Cert/CertAuthMethodLoginProvider.cs @@ -28,7 +28,7 @@ public async Task GetVaultTokenAsync() (await _polymath.MakeVaultApiRequest>(LoginResourcePath, HttpMethod.Post, unauthenticated: true).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext)) : - (await _polymath.MakeVaultApiRequest>(LoginResourcePath, HttpMethod.Post, new { name = _certAuthMethodInfo.RoleName }, unauthenticated: true).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext)); + (await _polymath.MakeVaultApiRequest>(LoginResourcePath, HttpMethod.Post, new NameRequest { Name = _certAuthMethodInfo.RoleName }, unauthenticated: true).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext)); _certAuthMethodInfo.ReturnedLoginAuthInfo = response?.AuthInfo; diff --git a/src/VaultSharp/V1/AuthMethods/CloudFoundry/CloudFoundryAuthMethodLoginProvider.cs b/src/VaultSharp/V1/AuthMethods/CloudFoundry/CloudFoundryAuthMethodLoginProvider.cs index 9e8628b5..4acddcc0 100644 --- a/src/VaultSharp/V1/AuthMethods/CloudFoundry/CloudFoundryAuthMethodLoginProvider.cs +++ b/src/VaultSharp/V1/AuthMethods/CloudFoundry/CloudFoundryAuthMethodLoginProvider.cs @@ -26,12 +26,12 @@ public static string GetFormattedSigningTime(DateTime signingTime) public async Task GetVaultTokenAsync() { - var requestData = new + var requestData = new CloudFoundryLoginRequest { - role = _cloudFoundryAuthMethodInfo.RoleName, - cf_instance_cert = _cloudFoundryAuthMethodInfo.CFInstanceCertContent, - signing_time = GetFormattedSigningTime(_cloudFoundryAuthMethodInfo.SignatureDateTime), - signature = _cloudFoundryAuthMethodInfo.Signature + Role = _cloudFoundryAuthMethodInfo.RoleName, + CfInstanceCert = _cloudFoundryAuthMethodInfo.CFInstanceCertContent, + SigningTime = GetFormattedSigningTime(_cloudFoundryAuthMethodInfo.SignatureDateTime), + Signature = _cloudFoundryAuthMethodInfo.Signature }; // make an unauthenticated call to Vault, since this is the call to get the token. diff --git a/src/VaultSharp/V1/AuthMethods/LDAP/LDAPAuthMethodProvider.cs b/src/VaultSharp/V1/AuthMethods/LDAP/LDAPAuthMethodProvider.cs index df853833..43fc4fff 100644 --- a/src/VaultSharp/V1/AuthMethods/LDAP/LDAPAuthMethodProvider.cs +++ b/src/VaultSharp/V1/AuthMethods/LDAP/LDAPAuthMethodProvider.cs @@ -23,7 +23,7 @@ public async Task WriteGroupAsync(string groupName, IList policies, stri var flatPolicies = string.Join(",", policies); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/groups/" + groupName.Trim('/'), HttpMethod.Post, new { policies = flatPolicies }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/groups/" + groupName.Trim('/'), HttpMethod.Post, new PoliciesRequest { Policies = flatPolicies }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task>> ReadGroupAsync(string groupName, string mountPoint = AuthMethodDefaultPaths.LDAP, string wrapTimeToLive = null) @@ -57,7 +57,7 @@ public async Task WriteUserAsync(string username, IList policies, IList< var flatPolicies = string.Join(",", policies ?? new List()); var flatGroups = string.Join(",", groups ?? new List()); - await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/users/" + username.Trim('/'), HttpMethod.Post, new { policies = flatPolicies, groups = flatGroups }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/auth/" + mountPoint.Trim('/') + "/users/" + username.Trim('/'), HttpMethod.Post, new PoliciesGroupsRequest { Policies = flatPolicies, Groups = flatGroups }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task>> ReadUserAsync(string username, string mountPoint = "ldap", string wrapTimeToLive = null) diff --git a/src/VaultSharp/V1/AuthMethods/Token/TokenAuthMethodProvider.cs b/src/VaultSharp/V1/AuthMethods/Token/TokenAuthMethodProvider.cs index f68f8389..bd43ad60 100644 --- a/src/VaultSharp/V1/AuthMethods/Token/TokenAuthMethodProvider.cs +++ b/src/VaultSharp/V1/AuthMethods/Token/TokenAuthMethodProvider.cs @@ -62,7 +62,7 @@ public async Task> LookupAsync(string clientToken) { Checker.NotNull(clientToken, nameof(clientToken)); - var requestData = new { token = clientToken }; + var requestData = new TokenRequest { Token = clientToken }; return await _polymath.MakeVaultApiRequest>("v1/auth/token/lookup", HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -80,7 +80,7 @@ public async Task> ReadTokenRoleAsync(string roleName) public async Task RenewSelfAsync(string increment = null) { - var requestData = !string.IsNullOrWhiteSpace(increment) ? new { increment = increment } : null; + var requestData = !string.IsNullOrWhiteSpace(increment) ? new IncrementRequest { Increment = increment } : null; var result = await _polymath.MakeVaultApiRequest>("v1/auth/token/renew-self", HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); return result.AuthInfo; diff --git a/src/VaultSharp/V1/Commons/BackendListingVisibility.cs b/src/VaultSharp/V1/Commons/BackendListingVisibility.cs index 43e1608f..0a9a8e3b 100644 --- a/src/VaultSharp/V1/Commons/BackendListingVisibility.cs +++ b/src/VaultSharp/V1/Commons/BackendListingVisibility.cs @@ -6,7 +6,11 @@ namespace VaultSharp.Core /// /// Represents the BackendListingVisibility /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum BackendListingVisibility { hidden, diff --git a/src/VaultSharp/V1/SecretsEngines/AWS/AWSCredentialsType.cs b/src/VaultSharp/V1/SecretsEngines/AWS/AWSCredentialsType.cs index 38f07bd6..4629f064 100644 --- a/src/VaultSharp/V1/SecretsEngines/AWS/AWSCredentialsType.cs +++ b/src/VaultSharp/V1/SecretsEngines/AWS/AWSCredentialsType.cs @@ -3,7 +3,11 @@ namespace VaultSharp.V1.SecretsEngines.AWS { +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum AWSCredentialsType { iam_user, diff --git a/src/VaultSharp/V1/SecretsEngines/Active Directory/ActiveDirectoryLibraryProvider.cs b/src/VaultSharp/V1/SecretsEngines/Active Directory/ActiveDirectoryLibraryProvider.cs index 64c5ba8d..f1adab33 100644 --- a/src/VaultSharp/V1/SecretsEngines/Active Directory/ActiveDirectoryLibraryProvider.cs +++ b/src/VaultSharp/V1/SecretsEngines/Active Directory/ActiveDirectoryLibraryProvider.cs @@ -43,17 +43,17 @@ public async Task DeleteServiceAccountSetAsync(string setName, string mountPoint public async Task> CheckoutCredentialsAsync(string setName, long? timeToLive = null, string mountPoint = null, string wrapTimeToLive = null) { - return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.ActiveDirectory, "/library/" + setName + "/check-out", HttpMethod.Post, requestData: new { ttl = timeToLive }, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.ActiveDirectory, "/library/" + setName + "/check-out", HttpMethod.Post, requestData: new TtlRequest { Ttl = timeToLive }, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task> CheckinCredentialsAsync(string setName, List serviceAccountNames = null, string mountPoint = null, string wrapTimeToLive = null) { - return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.ActiveDirectory, "/library/" + setName + "/check-in", HttpMethod.Post, requestData: new { service_account_names = serviceAccountNames }, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.ActiveDirectory, "/library/" + setName + "/check-in", HttpMethod.Post, requestData: new ServiceAccountNamesRequest { ServiceAccountNames = serviceAccountNames }, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task> ForceCheckinCredentialsAsync(string setName, List serviceAccountNames = null, string mountPoint = null, string wrapTimeToLive = null) { - return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.ActiveDirectory, "/library/manage/" + setName + "/check-in", HttpMethod.Post, requestData: new { service_account_names = serviceAccountNames }, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.ActiveDirectory, "/library/manage/" + setName + "/check-in", HttpMethod.Post, requestData: new ServiceAccountNamesRequest { ServiceAccountNames = serviceAccountNames }, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } } } \ No newline at end of file diff --git a/src/VaultSharp/V1/SecretsEngines/AliCloud/Models/CreateAliCloudRoleModel.cs b/src/VaultSharp/V1/SecretsEngines/AliCloud/Models/CreateAliCloudRoleModel.cs index 9911367d..29693acd 100644 --- a/src/VaultSharp/V1/SecretsEngines/AliCloud/Models/CreateAliCloudRoleModel.cs +++ b/src/VaultSharp/V1/SecretsEngines/AliCloud/Models/CreateAliCloudRoleModel.cs @@ -3,6 +3,9 @@ using System.Text.Json; using System.Text.Json.Serialization; using VaultSharp.Core; +#if NET8_0_OR_GREATER +using System.Text.Json.Serialization.Metadata; +#endif namespace VaultSharp.V1.SecretsEngines.AliCloud.Models { @@ -16,7 +19,11 @@ public string RemotePoliciesJson { get { +#if NET8_0_OR_GREATER + return JsonSerializer.Serialize(RemotePolicies, (JsonTypeInfo>)VaultSharpJsonContext.Default.GetTypeInfo(typeof(List))); +#else return JsonSerializer.Serialize(RemotePolicies); +#endif } } @@ -28,7 +35,11 @@ public string InlinePoliciesJson { get { +#if NET8_0_OR_GREATER + return JsonSerializer.Serialize(InlinePolicies, (JsonTypeInfo>)VaultSharpJsonContext.Default.GetTypeInfo(typeof(List))); +#else return JsonSerializer.Serialize(InlinePolicies); +#endif } } diff --git a/src/VaultSharp/V1/SecretsEngines/Consul/Models/ConsulTokenType.cs b/src/VaultSharp/V1/SecretsEngines/Consul/Models/ConsulTokenType.cs index ee74d7d2..a4171d55 100644 --- a/src/VaultSharp/V1/SecretsEngines/Consul/Models/ConsulTokenType.cs +++ b/src/VaultSharp/V1/SecretsEngines/Consul/Models/ConsulTokenType.cs @@ -4,7 +4,11 @@ namespace VaultSharp.V1.SecretsEngines.Consul.Models { +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum ConsulTokenType { client, diff --git a/src/VaultSharp/V1/SecretsEngines/Enterprise/KMIP/CertificateFormat.cs b/src/VaultSharp/V1/SecretsEngines/Enterprise/KMIP/CertificateFormat.cs index 9c099e9d..58fb05e0 100644 --- a/src/VaultSharp/V1/SecretsEngines/Enterprise/KMIP/CertificateFormat.cs +++ b/src/VaultSharp/V1/SecretsEngines/Enterprise/KMIP/CertificateFormat.cs @@ -6,7 +6,11 @@ namespace VaultSharp.V1.SecretsEngines.Enterprise.KMIP /// /// Represents the Certificate format. /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum CertificateFormat { /// diff --git a/src/VaultSharp/V1/SecretsEngines/Enterprise/KMIP/KMIPSecretsEngineProvider.cs b/src/VaultSharp/V1/SecretsEngines/Enterprise/KMIP/KMIPSecretsEngineProvider.cs index 5b429fbf..929e0198 100644 --- a/src/VaultSharp/V1/SecretsEngines/Enterprise/KMIP/KMIPSecretsEngineProvider.cs +++ b/src/VaultSharp/V1/SecretsEngines/Enterprise/KMIP/KMIPSecretsEngineProvider.cs @@ -19,7 +19,7 @@ public async Task> GetCredentialsAsync(string scopeName, Checker.NotNull(scopeName, "scopeName"); Checker.NotNull(roleName, "roleName"); - return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.KMIP, "/scope/" + scopeName.Trim('/') + "/role/" + scopeName.Trim('/') + "/credential/generate", HttpMethod.Post, new { format }, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.KMIP, "/scope/" + scopeName.Trim('/') + "/role/" + scopeName.Trim('/') + "/credential/generate", HttpMethod.Post, new FormatRequest { Format = format.ToString() }, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } } } \ No newline at end of file diff --git a/src/VaultSharp/V1/SecretsEngines/GoogleCloud/ServiceAccountKeyAlgorithm.cs b/src/VaultSharp/V1/SecretsEngines/GoogleCloud/ServiceAccountKeyAlgorithm.cs index 6da04f5f..4352c994 100644 --- a/src/VaultSharp/V1/SecretsEngines/GoogleCloud/ServiceAccountKeyAlgorithm.cs +++ b/src/VaultSharp/V1/SecretsEngines/GoogleCloud/ServiceAccountKeyAlgorithm.cs @@ -7,7 +7,11 @@ namespace VaultSharp.V1.SecretsEngines.GoogleCloud /// Represents the ServiceAccountKeyAlgorithm. /// https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts.keys#ServiceAccountKeyAlgorithm /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum ServiceAccountKeyAlgorithm { /// diff --git a/src/VaultSharp/V1/SecretsEngines/GoogleCloud/ServiceAccountPrivateKeyType.cs b/src/VaultSharp/V1/SecretsEngines/GoogleCloud/ServiceAccountPrivateKeyType.cs index 874dbe19..b0b14b64 100644 --- a/src/VaultSharp/V1/SecretsEngines/GoogleCloud/ServiceAccountPrivateKeyType.cs +++ b/src/VaultSharp/V1/SecretsEngines/GoogleCloud/ServiceAccountPrivateKeyType.cs @@ -7,7 +7,11 @@ namespace VaultSharp.V1.SecretsEngines.GoogleCloud /// Represents the ServiceAccountPrivateKeyType. /// https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts.keys#ServiceAccountPrivateKeyType /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum ServiceAccountPrivateKeyType { /// diff --git a/src/VaultSharp/V1/SecretsEngines/Identity/IdentitySecretsEngineProvider.cs b/src/VaultSharp/V1/SecretsEngines/Identity/IdentitySecretsEngineProvider.cs index ac900c1d..176634cd 100644 --- a/src/VaultSharp/V1/SecretsEngines/Identity/IdentitySecretsEngineProvider.cs +++ b/src/VaultSharp/V1/SecretsEngines/Identity/IdentitySecretsEngineProvider.cs @@ -27,7 +27,7 @@ public async Task> IntrospectTokenAsync(string token, string client { Checker.NotNull(token, "token"); - return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.Identity, "/oidc/introspect", HttpMethod.Post, new { token, client_id = clientId }, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.Identity, "/oidc/introspect", HttpMethod.Post, new TokenClientIdRequest { Token = token, ClientId = clientId }, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task> CreateEntityAsync(CreateEntityRequest createEntityRequest, string mountPoint = null, string wrapTimeToLive = null) diff --git a/src/VaultSharp/V1/SecretsEngines/KeyValue/V2/KeyValueSecretsEngineV2Provider.cs b/src/VaultSharp/V1/SecretsEngines/KeyValue/V2/KeyValueSecretsEngineV2Provider.cs index 4f7fd920..26b6cba5 100644 --- a/src/VaultSharp/V1/SecretsEngines/KeyValue/V2/KeyValueSecretsEngineV2Provider.cs +++ b/src/VaultSharp/V1/SecretsEngines/KeyValue/V2/KeyValueSecretsEngineV2Provider.cs @@ -50,7 +50,7 @@ public async Task> WriteSecretAsync(string path if (checkAndSet != null) { - requestData.Add("options", new { cas = checkAndSet.Value }); + requestData.Add("options", new CasRequest { Cas = checkAndSet.Value }); } return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.KeyValueV2, "/data/" + path.Trim('/'), HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); @@ -81,7 +81,7 @@ public async Task DeleteSecretVersionsAsync(string path, IList versions, st Checker.NotNull(path, "path"); Checker.NotNull(versions, "versions"); - var requestData = new { versions = versions }; + var requestData = new VersionsRequest { Versions = versions }; await _polymath.MakeVaultApiRequest(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.KeyValueV2, "/delete/" + path.Trim('/'), HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -91,7 +91,7 @@ public async Task UndeleteSecretVersionsAsync(string path, IList versions, Checker.NotNull(path, "path"); Checker.NotNull(versions, "versions"); - var requestData = new { versions = versions }; + var requestData = new VersionsRequest { Versions = versions }; await _polymath.MakeVaultApiRequest(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.KeyValueV2, "/undelete/" + path.Trim('/'), HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -101,7 +101,7 @@ public async Task DestroySecretVersionsAsync(string path, IList versions, s Checker.NotNull(path, "path"); Checker.NotNull(versions, "versions"); - var requestData = new { versions = versions }; + var requestData = new VersionsRequest { Versions = versions }; await _polymath.MakeVaultApiRequest(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.KeyValueV2, "/destroy/" + path.Trim('/'), HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } diff --git a/src/VaultSharp/V1/SecretsEngines/PKI/CertificateFormat.cs b/src/VaultSharp/V1/SecretsEngines/PKI/CertificateFormat.cs index d0155512..82abb522 100644 --- a/src/VaultSharp/V1/SecretsEngines/PKI/CertificateFormat.cs +++ b/src/VaultSharp/V1/SecretsEngines/PKI/CertificateFormat.cs @@ -6,7 +6,11 @@ namespace VaultSharp.V1.SecretsEngines.PKI /// /// Represents the Certificate format. /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum CertificateFormat { /// diff --git a/src/VaultSharp/V1/SecretsEngines/PKI/CertificateKeyType.cs b/src/VaultSharp/V1/SecretsEngines/PKI/CertificateKeyType.cs index 54b04837..7d43fcf6 100644 --- a/src/VaultSharp/V1/SecretsEngines/PKI/CertificateKeyType.cs +++ b/src/VaultSharp/V1/SecretsEngines/PKI/CertificateKeyType.cs @@ -6,7 +6,11 @@ namespace VaultSharp.V1.SecretsEngines.PKI /// /// Represents the Certificate key type. /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum CertificateKeyType { /// diff --git a/src/VaultSharp/V1/SecretsEngines/PKI/CertificateTidyState.cs b/src/VaultSharp/V1/SecretsEngines/PKI/CertificateTidyState.cs index 5c20a9ed..84fcbe53 100644 --- a/src/VaultSharp/V1/SecretsEngines/PKI/CertificateTidyState.cs +++ b/src/VaultSharp/V1/SecretsEngines/PKI/CertificateTidyState.cs @@ -6,7 +6,11 @@ namespace VaultSharp.V1.SecretsEngines.PKI /// /// Represents the Certificate tidy state. /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum CertificateTidyState { Inactive, diff --git a/src/VaultSharp/V1/SecretsEngines/PKI/PKISecretsEngineProvider.cs b/src/VaultSharp/V1/SecretsEngines/PKI/PKISecretsEngineProvider.cs index 2e89fca9..b19b2680 100644 --- a/src/VaultSharp/V1/SecretsEngines/PKI/PKISecretsEngineProvider.cs +++ b/src/VaultSharp/V1/SecretsEngines/PKI/PKISecretsEngineProvider.cs @@ -42,7 +42,7 @@ public async Task> RevokeCertificateAsync(stri { Checker.NotNull(serialNumber, "serialNumber"); - return await _polymath.MakeVaultApiRequest>(pkiBackendMountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.PKI, "/revoke", HttpMethod.Post, new { serial_number = serialNumber }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + return await _polymath.MakeVaultApiRequest>(pkiBackendMountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.PKI, "/revoke", HttpMethod.Post, new SerialNumberRequest { SerialNumber = serialNumber }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task TidyAsync(CertificateTidyRequest certificateTidyRequest = null, string pkiBackendMountPoint = null) diff --git a/src/VaultSharp/V1/SecretsEngines/PKI/PrivateKeyFormat.cs b/src/VaultSharp/V1/SecretsEngines/PKI/PrivateKeyFormat.cs index bbdd5dc2..95fd69fb 100644 --- a/src/VaultSharp/V1/SecretsEngines/PKI/PrivateKeyFormat.cs +++ b/src/VaultSharp/V1/SecretsEngines/PKI/PrivateKeyFormat.cs @@ -6,7 +6,11 @@ namespace VaultSharp.V1.SecretsEngines.PKI /// /// Represents the Private key format. /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum PrivateKeyFormat { /// diff --git a/src/VaultSharp/V1/SecretsEngines/SSH/SSHKeyType.cs b/src/VaultSharp/V1/SecretsEngines/SSH/SSHKeyType.cs index 30024533..4e40f6b1 100644 --- a/src/VaultSharp/V1/SecretsEngines/SSH/SSHKeyType.cs +++ b/src/VaultSharp/V1/SecretsEngines/SSH/SSHKeyType.cs @@ -6,7 +6,11 @@ namespace VaultSharp.V1.SecretsEngines.SSH /// /// Represents the type of SSH key to be generated. /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum SSHKeyType { /// diff --git a/src/VaultSharp/V1/SecretsEngines/SSH/SSHSecretsEngineProvider.cs b/src/VaultSharp/V1/SecretsEngines/SSH/SSHSecretsEngineProvider.cs index eb0f9607..5063fda0 100644 --- a/src/VaultSharp/V1/SecretsEngines/SSH/SSHSecretsEngineProvider.cs +++ b/src/VaultSharp/V1/SecretsEngines/SSH/SSHSecretsEngineProvider.cs @@ -19,7 +19,7 @@ public async Task> GetCredentialsAsync(string roleName, s Checker.NotNull(roleName, "roleName"); Checker.NotNull(ipAddress, "ipAddress"); - var requestData = new { ip = ipAddress, username = username }; + var requestData = new IpUsernameRequest { Ip = ipAddress, Username = username }; return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.SSH, "/creds/" + roleName.Trim('/'), HttpMethod.Post, requestData, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } diff --git a/src/VaultSharp/V1/SecretsEngines/TOTP/TOTPSecretsEngineProvider.cs b/src/VaultSharp/V1/SecretsEngines/TOTP/TOTPSecretsEngineProvider.cs index 4b4e5b7b..1f0557c8 100644 --- a/src/VaultSharp/V1/SecretsEngines/TOTP/TOTPSecretsEngineProvider.cs +++ b/src/VaultSharp/V1/SecretsEngines/TOTP/TOTPSecretsEngineProvider.cs @@ -92,7 +92,7 @@ public async Task> ValidateCodeAsync(string keyName, st Checker.NotNull(keyName, "keyName"); Checker.NotNull(code, "code"); - var requestData = new { code = code }; + var requestData = new CodeRequest { Code = code }; return await _polymath.MakeVaultApiRequest>(mountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.TOTP, "/code/" + keyName.Trim('/'), HttpMethod.Post, requestData, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } } diff --git a/src/VaultSharp/V1/SecretsEngines/Transit/OutputEncodingFormat.cs b/src/VaultSharp/V1/SecretsEngines/Transit/OutputEncodingFormat.cs index 5fbf093d..94ad193a 100644 --- a/src/VaultSharp/V1/SecretsEngines/Transit/OutputEncodingFormat.cs +++ b/src/VaultSharp/V1/SecretsEngines/Transit/OutputEncodingFormat.cs @@ -6,7 +6,11 @@ namespace VaultSharp.V1.SecretsEngines.Transit /// /// The output encoding format options for a request. /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum OutputEncodingFormat { /// diff --git a/src/VaultSharp/V1/SecretsEngines/Transit/RandomBytesSource.cs b/src/VaultSharp/V1/SecretsEngines/Transit/RandomBytesSource.cs index 48145945..e4e526cd 100644 --- a/src/VaultSharp/V1/SecretsEngines/Transit/RandomBytesSource.cs +++ b/src/VaultSharp/V1/SecretsEngines/Transit/RandomBytesSource.cs @@ -6,7 +6,11 @@ namespace VaultSharp.V1.SecretsEngines.Transit /// /// The the source of the requested bytes /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum RandomBytesSource { /// diff --git a/src/VaultSharp/V1/SecretsEngines/Transit/SignRequestOptions.cs b/src/VaultSharp/V1/SecretsEngines/Transit/SignRequestOptions.cs index 8ccc1705..791c5882 100644 --- a/src/VaultSharp/V1/SecretsEngines/Transit/SignRequestOptions.cs +++ b/src/VaultSharp/V1/SecretsEngines/Transit/SignRequestOptions.cs @@ -83,7 +83,11 @@ public class SignSingleInput /// /// The RSA signature algorithm to use for signing, if applicable. /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum SignatureAlgorithm { pss, @@ -93,7 +97,11 @@ public enum SignatureAlgorithm /// /// The way in which the signature should be marshaled, if applicable. /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum MarshalingAlgorithm { asn1, diff --git a/src/VaultSharp/V1/SecretsEngines/Transit/TransitDataKeyType.cs b/src/VaultSharp/V1/SecretsEngines/Transit/TransitDataKeyType.cs index 1e6339e0..d3d2cf0f 100644 --- a/src/VaultSharp/V1/SecretsEngines/Transit/TransitDataKeyType.cs +++ b/src/VaultSharp/V1/SecretsEngines/Transit/TransitDataKeyType.cs @@ -5,7 +5,11 @@ namespace VaultSharp.V1.SecretsEngines.Transit { +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum TransitDataKeyType { plaintext, diff --git a/src/VaultSharp/V1/SecretsEngines/Transit/TransitHashFunction.cs b/src/VaultSharp/V1/SecretsEngines/Transit/TransitHashFunction.cs index ab2fee38..0595ae59 100644 --- a/src/VaultSharp/V1/SecretsEngines/Transit/TransitHashFunction.cs +++ b/src/VaultSharp/V1/SecretsEngines/Transit/TransitHashFunction.cs @@ -7,7 +7,11 @@ namespace VaultSharp.V1.SecretsEngines.Transit /// /// The set of hash functions that are currently supported by Vault. /// +#if NET8_0_OR_GREATER + [JsonConverter(typeof(JsonStringEnumConverter))] +#else [JsonConverter(typeof(JsonStringEnumConverter))] +#endif public enum TransitHashFunction { SHA1, diff --git a/src/VaultSharp/V1/SystemBackend/AbstractAuditBackend.cs b/src/VaultSharp/V1/SystemBackend/AbstractAuditBackend.cs index 83553de7..c60d13ec 100644 --- a/src/VaultSharp/V1/SystemBackend/AbstractAuditBackend.cs +++ b/src/VaultSharp/V1/SystemBackend/AbstractAuditBackend.cs @@ -6,9 +6,6 @@ namespace VaultSharp.V1.SystemBackend /// Represents an audit backend. /// [JsonConverter(typeof(AuditBackendJsonConverter))] - [JsonDerivedType(typeof(FileAuditBackend))] - [JsonDerivedType(typeof(SyslogAuditBackend))] - [JsonDerivedType(typeof(CustomAuditBackend))] public abstract class AbstractAuditBackend { /// diff --git a/src/VaultSharp/V1/SystemBackend/AuditBackendJsonConverter.cs b/src/VaultSharp/V1/SystemBackend/AuditBackendJsonConverter.cs index 99be9dd7..291529f8 100644 --- a/src/VaultSharp/V1/SystemBackend/AuditBackendJsonConverter.cs +++ b/src/VaultSharp/V1/SystemBackend/AuditBackendJsonConverter.cs @@ -130,15 +130,27 @@ public override AbstractAuditBackend Read(ref Utf8JsonReader reader, Type type, if (auditBackendType == AuditBackendType.File) { - return JsonSerializer.Deserialize(jsonString); +#if NET8_0_OR_GREATER + return (FileAuditBackend)JsonSerializer.Deserialize(jsonString, options.GetTypeInfo(typeof(FileAuditBackend))); +#else + return JsonSerializer.Deserialize(jsonString, options); +#endif } if (auditBackendType == AuditBackendType.Syslog) { - return JsonSerializer.Deserialize(jsonString); +#if NET8_0_OR_GREATER + return (SyslogAuditBackend)JsonSerializer.Deserialize(jsonString, options.GetTypeInfo(typeof(SyslogAuditBackend))); +#else + return JsonSerializer.Deserialize(jsonString, options); +#endif } - return JsonSerializer.Deserialize(jsonString); +#if NET8_0_OR_GREATER + return (CustomAuditBackend)JsonSerializer.Deserialize(jsonString, options.GetTypeInfo(typeof(CustomAuditBackend))); +#else + return JsonSerializer.Deserialize(jsonString, options); +#endif } } } diff --git a/src/VaultSharp/V1/SystemBackend/CustomAuditBackend.cs b/src/VaultSharp/V1/SystemBackend/CustomAuditBackend.cs index 5fa19b80..e6f5cf91 100644 --- a/src/VaultSharp/V1/SystemBackend/CustomAuditBackend.cs +++ b/src/VaultSharp/V1/SystemBackend/CustomAuditBackend.cs @@ -34,6 +34,7 @@ public CustomAuditBackend(AuditBackendType auditBackendType) /// /// The type of the backend. /// + [JsonPropertyName("type")] public override AuditBackendType Type { get; } } } \ No newline at end of file diff --git a/src/VaultSharp/V1/SystemBackend/Enterprise/EnterpriseProvider.cs b/src/VaultSharp/V1/SystemBackend/Enterprise/EnterpriseProvider.cs index 143d3b91..22abe66a 100644 --- a/src/VaultSharp/V1/SystemBackend/Enterprise/EnterpriseProvider.cs +++ b/src/VaultSharp/V1/SystemBackend/Enterprise/EnterpriseProvider.cs @@ -24,7 +24,7 @@ public async Task> GetControlGroupConfigAsync() public async Task ConfigureControlGroupAsync(string maxTimeToLive) { - await _polymath.MakeVaultApiRequest("v1/sys/config/control-group", HttpMethod.Put, new { max_ttl = maxTimeToLive }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + await _polymath.MakeVaultApiRequest("v1/sys/config/control-group", HttpMethod.Put, new MaxTtlRequest { MaxTtl = maxTimeToLive }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task DeleteControlGroupConfigAsync() @@ -34,12 +34,12 @@ public async Task DeleteControlGroupConfigAsync() public async Task> AuthorizeControlGroupAsync(string accessor) { - return await _polymath.MakeVaultApiRequest>("v1/sys/control-group/authorize", HttpMethod.Post, new { accessor = accessor }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + return await _polymath.MakeVaultApiRequest>("v1/sys/control-group/authorize", HttpMethod.Post, new AccessorRequest { Accessor = accessor }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task> CheckControlGroupStatusAsync(string accessor) { - return await _polymath.MakeVaultApiRequest>("v1/sys/control-group/request", HttpMethod.Post, new { accessor = accessor }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); + return await _polymath.MakeVaultApiRequest>("v1/sys/control-group/request", HttpMethod.Post, new AccessorRequest { Accessor = accessor }).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task> GetLicenseAsync() diff --git a/src/VaultSharp/V1/SystemBackend/FileAuditBackend.cs b/src/VaultSharp/V1/SystemBackend/FileAuditBackend.cs index 8990541e..7d698f91 100644 --- a/src/VaultSharp/V1/SystemBackend/FileAuditBackend.cs +++ b/src/VaultSharp/V1/SystemBackend/FileAuditBackend.cs @@ -17,6 +17,7 @@ public class FileAuditBackend : AbstractAuditBackend /// /// The type of the backend. /// + [JsonPropertyName("type")] public override AuditBackendType Type { get; } = AuditBackendType.File; /// diff --git a/src/VaultSharp/V1/SystemBackend/SyslogAuditBackend.cs b/src/VaultSharp/V1/SystemBackend/SyslogAuditBackend.cs index 318cbc2f..120ad58e 100644 --- a/src/VaultSharp/V1/SystemBackend/SyslogAuditBackend.cs +++ b/src/VaultSharp/V1/SystemBackend/SyslogAuditBackend.cs @@ -17,6 +17,7 @@ public class SyslogAuditBackend : AbstractAuditBackend /// /// The type of the backend. /// + [JsonPropertyName("type")] public override AuditBackendType Type { get; } = AuditBackendType.Syslog; /// diff --git a/src/VaultSharp/V1/SystemBackend/SystemBackendProvider.cs b/src/VaultSharp/V1/SystemBackend/SystemBackendProvider.cs index 55571e97..7b476136 100644 --- a/src/VaultSharp/V1/SystemBackend/SystemBackendProvider.cs +++ b/src/VaultSharp/V1/SystemBackend/SystemBackendProvider.cs @@ -68,7 +68,7 @@ public async Task UnmountAuditBackendAsync(string path) public async Task> AuditHashAsync(string path, string inputToHash) { - var requestData = new { input = inputToHash }; + var requestData = new InputRequest { Input = inputToHash }; return await _polymath.MakeVaultApiRequest>("v1/sys/audit-hash/" + path.Trim('/'), HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -116,19 +116,19 @@ public async Task ConfigureAuthBackendAsync(string path, BackendConfig backendCo public async Task> GetTokenCapabilitiesAsync(string path, string token) { - var requestData = new { path = path, token = token }; + var requestData = new PathTokenRequest { Path = path, Token = token }; return await _polymath.MakeVaultApiRequest>("v1/sys/capabilities", HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task> GetTokenCapabilitiesByAcessorAsync(string path, string tokenAccessor) { - var requestData = new { path = path, accessor = tokenAccessor }; + var requestData = new PathAccessorRequest { Path = path, Accessor = tokenAccessor }; return await _polymath.MakeVaultApiRequest>("v1/sys/capabilities-accessor", HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task> GetCallingTokenCapabilitiesAsync(string path) { - var requestData = new { path = path }; + var requestData = new PathRequest { Path = path }; return await _polymath.MakeVaultApiRequest>("v1/sys/capabilities-self", HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -174,10 +174,7 @@ public async Task> GetAuditRequestHeaderAsync(string name) public async Task PutAuditRequestHeaderAsync(string name, bool hmac = false) { - var requestData = new - { - hmac = hmac - }; + var requestData = new HmacRequest { Hmac = hmac }; await _polymath.MakeVaultApiRequest("v1/sys/config/auditing/request-headers/" + name, HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -209,7 +206,7 @@ public async Task GetRootTokenGenerationStatusAsync() public async Task InitiateRootTokenGenerationAsync(string base64EncodedOneTimePassword, string pgpKey) { - var requestData = new { otp = base64EncodedOneTimePassword, pgpKey = pgpKey }; + var requestData = new OtpPgpKeyRequest { Otp = base64EncodedOneTimePassword, PgpKey = pgpKey }; return await _polymath.MakeVaultApiRequest("v1/sys/generate-root/attempt", HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -220,11 +217,7 @@ public async Task CancelRootTokenGenerationAsync() public async Task ContinueRootTokenGenerationAsync(string masterShareKey, string nonce) { - var requestData = new - { - key = masterShareKey, - nonce = nonce - }; + var requestData = new KeyNonceRequest { Key = masterShareKey, Nonce = nonce }; return await _polymath.MakeVaultApiRequest("v1/sys/generate-root/update", HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -304,7 +297,7 @@ public async Task GetHealthStatusAsync(bool standbyOk = false, } // for head calls, the response is empty. So return a null object, to avoid misleading callers. - var healthStatus = JsonSerializer.Deserialize(vaultApiException.Message); + var healthStatus = JsonSerializer.Deserialize(vaultApiException.Message, _polymath.JsonSerializerOptions); healthStatus.HttpStatusCode = vaultApiException.StatusCode; return healthStatus; @@ -335,10 +328,7 @@ public async Task GetLeaderAsync() public async Task> GetLeaseAsync(string leaseId) { - var requestData = new - { - lease_id = leaseId - }; + var requestData = new LeaseIdRequest { LeaseId = leaseId }; return await _polymath.MakeVaultApiRequest>("v1/sys/leases/lookup", HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -350,21 +340,14 @@ public async Task> GetAllLeasesAsync(string prefix) public async Task> RenewLeaseAsync(string leaseId, int incrementSeconds) { - var requestData = new - { - lease_id = leaseId, - increment = incrementSeconds - }; + var requestData = new LeaseRenewRequest { LeaseId = leaseId, Increment = incrementSeconds }; return await _polymath.MakeVaultApiRequest>("v1/sys/leases/renew", HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task RevokeLeaseAsync(string leaseId) { - var requestData = new - { - lease_id = leaseId - }; + var requestData = new LeaseIdRequest { LeaseId = leaseId }; await _polymath.MakeVaultApiRequest("v1/sys/leases/revoke", HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -391,20 +374,14 @@ public async Task>> GetVerbosityLevelOfLoggerA public async Task ModifyVerbosityLevelForAllLoggersAsync(LogVerbosityLevel logVerbosityLevel) { - var requestData = new - { - level = logVerbosityLevel.ToString() - }; + var requestData = new LevelRequest { Level = logVerbosityLevel.ToString() }; await _polymath.MakeVaultApiRequest("v1/sys/loggers", HttpMethod.Post, requestData: requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task ModifyVerbosityLevelForLoggerAsync(string loggerName, LogVerbosityLevel logVerbosityLevel) { - var requestData = new - { - level = logVerbosityLevel.ToString() - }; + var requestData = new LevelRequest { Level = logVerbosityLevel.ToString() }; await _polymath.MakeVaultApiRequest("v1/sys/loggers/" + loggerName, HttpMethod.Post, requestData: requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -478,10 +455,7 @@ public async Task> GetPolicyAsync(string policyName) public async Task WritePolicyAsync(Policy policy) { - var requestData = new - { - rules = policy.Rules - }; + var requestData = new RulesRequest { Rules = policy.Rules }; await _polymath.MakeVaultApiRequest("v1/sys/policy/" + policy.Name, HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -503,10 +477,7 @@ public async Task> GetACLPolicyAsync(string policyName) public async Task WriteACLPolicyAsync(ACLPolicy policy) { - var requestData = new - { - policy = policy.Policy - }; + var requestData = new PolicyTextRequest { Policy = policy.Policy }; await _polymath.MakeVaultApiRequest("v1/sys/policies/acl/" + policy.Name, HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -538,17 +509,14 @@ public async Task>> ReadRawSecretAsync(string var response = await _polymath.MakeVaultApiRequest>("v1/sys/raw/" + storagePath.Trim('/'), HttpMethod.Get).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); string value = response.Data["value"].ToString(); - var data = JsonSerializer.Deserialize>(value); + var data = JsonSerializer.Deserialize>(value, _polymath.JsonSerializerOptions); return _polymath.GetMappedSecret(response, data); } public async Task WriteRawSecretAsync(string storagePath, Dictionary values) { - var requestData = new - { - value = JsonSerializer.Serialize(values) - }; + var requestData = new ValueRequest { Value = JsonSerializer.Serialize(values, _polymath.JsonSerializerOptions) }; await _polymath.MakeVaultApiRequest("v1/sys/raw/" + storagePath.Trim('/'), HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -565,7 +533,7 @@ public async Task GetRekeyStatusAsync() public async Task InitiateRekeyAsync(int secretShares, int secretThreshold, string[] pgpKeys = null, bool backup = false) { - var requestData = new { secret_shares = secretShares, secret_threshold = secretThreshold, pgp_keys = pgpKeys, backup = backup }; + var requestData = new RekeyInitRequest { SecretShares = secretShares, SecretThreshold = secretThreshold, PgpKeys = pgpKeys, Backup = backup }; return await _polymath.MakeVaultApiRequest("v1/sys/rekey/init", HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -586,11 +554,7 @@ public async Task DeleteRekeyBackupKeysAsync() public async Task ContinueRekeyAsync(string masterShareKey, string rekeyNonce) { - var requestData = new - { - key = masterShareKey, - nonce = rekeyNonce - }; + var requestData = new KeyNonceRequest { Key = masterShareKey, Nonce = rekeyNonce }; return await _polymath.MakeVaultApiRequest("v1/sys/rekey/update", HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -628,11 +592,7 @@ public async Task GetSealStatusAsync() public async Task UnsealAsync(string masterShareKey = null, bool resetCompletely = false) { - var requestData = new - { - key = masterShareKey, - reset = resetCompletely - }; + var requestData = new KeyResetRequest { Key = masterShareKey, Reset = resetCompletely }; return await _polymath.MakeVaultApiRequest("v1/sys/unseal", HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } @@ -657,19 +617,19 @@ public async Task QuickUnsealAsync(string[] allMasterShareKeys) public async Task> LookupTokenWrapInfoAsync(string tokenId) { - var requestData = new { token = tokenId }; + var requestData = new TokenRequest { Token = tokenId }; return await _polymath.MakeVaultApiRequest>("v1/sys/wrapping/lookup", HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task> RewrapWrappedResponseDataAsync(string tokenId) { - var requestData = new { token = tokenId }; + var requestData = new TokenRequest { Token = tokenId }; return await _polymath.MakeVaultApiRequest>("v1/sys/wrapping/rewrap", HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } public async Task> UnwrapWrappedResponseDataAsync(string tokenId) { - var requestData = new { token = tokenId }; + var requestData = new TokenRequest { Token = tokenId }; return await _polymath.MakeVaultApiRequest>("v1/sys/wrapping/unwrap", HttpMethod.Post, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } diff --git a/src/VaultSharp/VaultClientSettings.cs b/src/VaultSharp/VaultClientSettings.cs index 768fe5b1..68ad8f33 100644 --- a/src/VaultSharp/VaultClientSettings.cs +++ b/src/VaultSharp/VaultClientSettings.cs @@ -85,5 +85,14 @@ public VaultClientSettings(string vaultServerUriWithPort, IAuthMethodInfo authMe /// See for defaults. /// public SecretsEngineMountPoints SecretsEngineMountPoints { get; set; } = new SecretsEngineMountPoints(); + + /// + /// Optional for serialization. + /// Use this to provide a custom + /// for Native AOT support. VaultSharp's built-in types are handled automatically; + /// register your own types (e.g. for KV secrets) via + /// . + /// + public System.Text.Json.JsonSerializerOptions JsonSerializerOptions { get; set; } } } diff --git a/src/VaultSharp/VaultSharp.csproj b/src/VaultSharp/VaultSharp.csproj index 1e0b3d6c..ae12699e 100644 --- a/src/VaultSharp/VaultSharp.csproj +++ b/src/VaultSharp/VaultSharp.csproj @@ -37,6 +37,7 @@ This library is built with .NET Standard 2.0, .NET Standard 2.1, 4.6.2, 4.7.2*, True True CA2007 + true @@ -194,6 +195,14 @@ This library is built with .NET Standard 2.0, .NET Standard 2.1, 4.6.2, 4.7.2*, VaultSharp .NET 8 + + VaultSharp .NET 9 + + + + VaultSharp .NET 10 + + 5 From 23505bb73f2d4c958028783d1cbe14a58fd28d26 Mon Sep 17 00:00:00 2001 From: Benjamin Bartels Date: Fri, 20 Feb 2026 23:49:18 +0000 Subject: [PATCH 2/6] Update VaultSharp.csproj --- src/VaultSharp/VaultSharp.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VaultSharp/VaultSharp.csproj b/src/VaultSharp/VaultSharp.csproj index ae12699e..6f208d44 100644 --- a/src/VaultSharp/VaultSharp.csproj +++ b/src/VaultSharp/VaultSharp.csproj @@ -1,7 +1,7 @@  - net462;net47;net471;net472;net48;net481;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0 + net462;net47;net471;net472;net48;net481;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0;net9.0;net10.0 true false VaultSharp.snk From 22bee34cc0aab50694319f2def5bd60d874db686 Mon Sep 17 00:00:00 2001 From: bbartels Date: Sat, 21 Feb 2026 00:49:33 +0000 Subject: [PATCH 3/6] fixes --- src/VaultSharp/Core/VaultSharpJsonContext.cs | 3 ++- .../V1/SystemBackend/SystemBackendProvider.cs | 12 ++++++++++++ src/VaultSharp/VaultSharp.csproj | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/VaultSharp/Core/VaultSharpJsonContext.cs b/src/VaultSharp/Core/VaultSharpJsonContext.cs index 53c7a6a2..ce0f8db8 100644 --- a/src/VaultSharp/Core/VaultSharpJsonContext.cs +++ b/src/VaultSharp/Core/VaultSharpJsonContext.cs @@ -40,6 +40,7 @@ namespace VaultSharp.Core [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.ActiveDirectory.Models.ConnectionConfigModel), TypeInfoPropertyName = "ActiveDirectoryConnectionConfigModel")] [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] @@ -214,7 +215,7 @@ namespace VaultSharp.Core [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AppRole.Models.RoleIdInfo))] [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AppRole.Models.PullSecretIdRequestOptions))] [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AppRole.Models.PushSecretIdRequestOptions))] - [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Database.Models.ConnectionConfigModel))] + [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Database.Models.ConnectionConfigModel), TypeInfoPropertyName = "DatabaseConnectionConfigModel")] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Database.Role))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Database.StaticRole))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.CreateKeyRequestOptions))] diff --git a/src/VaultSharp/V1/SystemBackend/SystemBackendProvider.cs b/src/VaultSharp/V1/SystemBackend/SystemBackendProvider.cs index 7b476136..dce7ed96 100644 --- a/src/VaultSharp/V1/SystemBackend/SystemBackendProvider.cs +++ b/src/VaultSharp/V1/SystemBackend/SystemBackendProvider.cs @@ -297,7 +297,11 @@ public async Task GetHealthStatusAsync(bool standbyOk = false, } // for head calls, the response is empty. So return a null object, to avoid misleading callers. +#if NET8_0_OR_GREATER + var healthStatus = (HealthStatus)JsonSerializer.Deserialize(vaultApiException.Message, _polymath.JsonSerializerOptions.GetTypeInfo(typeof(HealthStatus))); +#else var healthStatus = JsonSerializer.Deserialize(vaultApiException.Message, _polymath.JsonSerializerOptions); +#endif healthStatus.HttpStatusCode = vaultApiException.StatusCode; return healthStatus; @@ -509,14 +513,22 @@ public async Task>> ReadRawSecretAsync(string var response = await _polymath.MakeVaultApiRequest>("v1/sys/raw/" + storagePath.Trim('/'), HttpMethod.Get).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); string value = response.Data["value"].ToString(); +#if NET8_0_OR_GREATER + var data = (Dictionary)JsonSerializer.Deserialize(value, _polymath.JsonSerializerOptions.GetTypeInfo(typeof(Dictionary))); +#else var data = JsonSerializer.Deserialize>(value, _polymath.JsonSerializerOptions); +#endif return _polymath.GetMappedSecret(response, data); } public async Task WriteRawSecretAsync(string storagePath, Dictionary values) { +#if NET8_0_OR_GREATER + var requestData = new ValueRequest { Value = JsonSerializer.Serialize(values, _polymath.JsonSerializerOptions.GetTypeInfo(typeof(Dictionary))) }; +#else var requestData = new ValueRequest { Value = JsonSerializer.Serialize(values, _polymath.JsonSerializerOptions) }; +#endif await _polymath.MakeVaultApiRequest("v1/sys/raw/" + storagePath.Trim('/'), HttpMethod.Put, requestData).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); } diff --git a/src/VaultSharp/VaultSharp.csproj b/src/VaultSharp/VaultSharp.csproj index 6f208d44..ae12699e 100644 --- a/src/VaultSharp/VaultSharp.csproj +++ b/src/VaultSharp/VaultSharp.csproj @@ -1,7 +1,7 @@  - net462;net47;net471;net472;net48;net481;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0;net9.0;net10.0 + net462;net47;net471;net472;net48;net481;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0 true false VaultSharp.snk From 37c2ed9c31b8bfef3ae4d90d9267891bf3484da4 Mon Sep 17 00:00:00 2001 From: Benjamin Bartels Date: Mon, 23 Feb 2026 19:11:33 +0000 Subject: [PATCH 4/6] Update AotRequestModels.cs --- src/VaultSharp/Core/AotRequestModels.cs | 228 ++++++------------------ 1 file changed, 57 insertions(+), 171 deletions(-) diff --git a/src/VaultSharp/Core/AotRequestModels.cs b/src/VaultSharp/Core/AotRequestModels.cs index 64853dfd..dc7921cb 100644 --- a/src/VaultSharp/Core/AotRequestModels.cs +++ b/src/VaultSharp/Core/AotRequestModels.cs @@ -3,342 +3,228 @@ namespace VaultSharp.Core { - // Shape: { token } internal sealed class TokenRequest { - [JsonPropertyName("token")] - public string Token { get; set; } + [JsonPropertyName("token")] public string Token { get; set; } } - // Shape: { token, client_id } internal sealed class TokenClientIdRequest { - [JsonPropertyName("token")] - public string Token { get; set; } - - [JsonPropertyName("client_id")] - public string ClientId { get; set; } + [JsonPropertyName("token")] public string Token { get; set; } + [JsonPropertyName("client_id")] public string ClientId { get; set; } } - // Shape: { input } internal sealed class InputRequest { - [JsonPropertyName("input")] - public string Input { get; set; } + [JsonPropertyName("input")] public string Input { get; set; } } - // Shape: { path, token } internal sealed class PathTokenRequest { - [JsonPropertyName("path")] - public string Path { get; set; } - - [JsonPropertyName("token")] - public string Token { get; set; } + [JsonPropertyName("path")] public string Path { get; set; } + [JsonPropertyName("token")] public string Token { get; set; } } - // Shape: { path, accessor } internal sealed class PathAccessorRequest { - [JsonPropertyName("path")] - public string Path { get; set; } - - [JsonPropertyName("accessor")] - public string Accessor { get; set; } + [JsonPropertyName("path")] public string Path { get; set; } + [JsonPropertyName("accessor")] public string Accessor { get; set; } } - // Shape: { path } internal sealed class PathRequest { - [JsonPropertyName("path")] - public string Path { get; set; } + [JsonPropertyName("path")] public string Path { get; set; } } - // Shape: { otp, pgpKey } — note: the original anonymous type uses "pgpKey" as the C# property name, and STJ without custom naming policy serializes it as "pgpKey" internal sealed class OtpPgpKeyRequest { - [JsonPropertyName("otp")] - public string Otp { get; set; } - - [JsonPropertyName("pgpKey")] - public string PgpKey { get; set; } + [JsonPropertyName("otp")] public string Otp { get; set; } + [JsonPropertyName("pgpKey")]public string PgpKey { get; set; } } - // Shape: { key, nonce } — used in root token generation AND rekey internal sealed class KeyNonceRequest { - [JsonPropertyName("key")] - public string Key { get; set; } - - [JsonPropertyName("nonce")] - public string Nonce { get; set; } + [JsonPropertyName("key")] public string Key { get; set; } + [JsonPropertyName("nonce")] public string Nonce { get; set; } } - // Shape: { value } — string value internal sealed class ValueRequest { - [JsonPropertyName("value")] - public string Value { get; set; } + [JsonPropertyName("value")] public string Value { get; set; } } - // Shape: { secret_shares, secret_threshold, pgp_keys, backup } internal sealed class RekeyInitRequest { - [JsonPropertyName("secret_shares")] - public int SecretShares { get; set; } - - [JsonPropertyName("secret_threshold")] - public int SecretThreshold { get; set; } - - [JsonPropertyName("pgp_keys")] - public string[] PgpKeys { get; set; } - - [JsonPropertyName("backup")] - public bool Backup { get; set; } + [JsonPropertyName("secret_shares")] public int SecretShares { get; set; } + [JsonPropertyName("secret_threshold")] public int SecretThreshold { get; set; } + [JsonPropertyName("pgp_keys")] public string[] PgpKeys { get; set; } + [JsonPropertyName("backup")] public bool Backup { get; set; } } - // Shape: { key, reset } internal sealed class KeyResetRequest { - [JsonPropertyName("key")] - public string Key { get; set; } - - [JsonPropertyName("reset")] - public bool Reset { get; set; } + [JsonPropertyName("key")] public string Key { get; set; } + [JsonPropertyName("reset")] public bool Reset { get; set; } } - // Shape: { max_ttl } internal sealed class MaxTtlRequest { - [JsonPropertyName("max_ttl")] - public string MaxTtl { get; set; } + [JsonPropertyName("max_ttl")] public string MaxTtl { get; set; } } - // Shape: { accessor } internal sealed class AccessorRequest { - [JsonPropertyName("accessor")] - public string Accessor { get; set; } + [JsonPropertyName("accessor")] public string Accessor { get; set; } } - // Shape: { code } internal sealed class CodeRequest { - [JsonPropertyName("code")] - public string Code { get; set; } + [JsonPropertyName("code")] public string Code { get; set; } } - // Shape: { ip, username } internal sealed class IpUsernameRequest { - [JsonPropertyName("ip")] - public string Ip { get; set; } - - [JsonPropertyName("username")] - public string Username { get; set; } + [JsonPropertyName("ip")] public string Ip { get; set; } + [JsonPropertyName("username")] public string Username { get; set; } } - // Shape: { serial_number } internal sealed class SerialNumberRequest { - [JsonPropertyName("serial_number")] - public string SerialNumber { get; set; } + [JsonPropertyName("serial_number")] public string SerialNumber { get; set; } } - // Shape: { cas } — used nested inside a dictionary internal sealed class CasRequest { - [JsonPropertyName("cas")] - public int Cas { get; set; } + [JsonPropertyName("cas")] public int Cas { get; set; } } - // Shape: { versions } internal sealed class VersionsRequest { - [JsonPropertyName("versions")] - public System.Collections.Generic.IList Versions { get; set; } + [JsonPropertyName("versions")] public System.Collections.Generic.IList Versions { get; set; } } - // Shape: { format } — used with KMIP CertificateFormat enum internal sealed class FormatRequest { - [JsonPropertyName("format")] - public string Format { get; set; } + [JsonPropertyName("format")] public string Format { get; set; } } - // Shape: { ttl } — nullable long internal sealed class TtlRequest { - [JsonPropertyName("ttl")] - public long? Ttl { get; set; } + [JsonPropertyName("ttl")] public long? Ttl { get; set; } } - // Shape: { service_account_names } internal sealed class ServiceAccountNamesRequest { - [JsonPropertyName("service_account_names")] - public List ServiceAccountNames { get; set; } + [JsonPropertyName("service_account_names")] public List ServiceAccountNames { get; set; } } - // Shape: { increment } internal sealed class IncrementRequest { - [JsonPropertyName("increment")] - public string Increment { get; set; } + [JsonPropertyName("increment")] public string Increment { get; set; } } - // Shape: { policies } — string internal sealed class PoliciesRequest { - [JsonPropertyName("policies")] - public string Policies { get; set; } + [JsonPropertyName("policies")] public string Policies { get; set; } } - // Shape: { policies, groups } internal sealed class PoliciesGroupsRequest { - [JsonPropertyName("policies")] - public string Policies { get; set; } - - [JsonPropertyName("groups")] - public string Groups { get; set; } + [JsonPropertyName("policies")] public string Policies { get; set; } + [JsonPropertyName("groups")] public string Groups { get; set; } } - // Shape: { name } internal sealed class NameRequest { - [JsonPropertyName("name")] - public string Name { get; set; } + [JsonPropertyName("name")] public string Name { get; set; } } - // Shape: { secret_id } internal sealed class SecretIdRequest { - [JsonPropertyName("secret_id")] - public string SecretId { get; set; } + [JsonPropertyName("secret_id")] public string SecretId { get; set; } } - // Shape: { secret_id_accessor } internal sealed class SecretIdAccessorRequest { - [JsonPropertyName("secret_id_accessor")] - public string SecretIdAccessor { get; set; } + [JsonPropertyName("secret_id_accessor")] public string SecretIdAccessor { get; set; } } - // Shape: { secret_id_num_uses } internal sealed class SecretIdNumUsesRequest { - [JsonPropertyName("secret_id_num_uses")] - public long SecretIdNumUses { get; set; } + [JsonPropertyName("secret_id_num_uses")] public long SecretIdNumUses { get; set; } } - // Shape: { secret_id_ttl } internal sealed class SecretIdTtlRequest { - [JsonPropertyName("secret_id_ttl")] - public long SecretIdTtl { get; set; } + [JsonPropertyName("secret_id_ttl")] public long SecretIdTtl { get; set; } } - // Shape: { token_ttl } internal sealed class TokenTtlRequest { - [JsonPropertyName("token_ttl")] - public long TokenTtl { get; set; } + [JsonPropertyName("token_ttl")] public long TokenTtl { get; set; } } - // Shape: { token_max_ttl } internal sealed class TokenMaxTtlRequest { - [JsonPropertyName("token_max_ttl")] - public long TokenMaxTtl { get; set; } + [JsonPropertyName("token_max_ttl")] public long TokenMaxTtl { get; set; } } - // Shape: { bind_secret_id } internal sealed class BindSecretIdRequest { - [JsonPropertyName("bind_secret_id")] - public bool BindSecretId { get; set; } + [JsonPropertyName("bind_secret_id")] public bool BindSecretId { get; set; } } - // Shape: { secret_id_bound_cidrs } internal sealed class SecretIdBoundCidrsRequest { - [JsonPropertyName("secret_id_bound_cidrs")] - public List SecretIdBoundCidrs { get; set; } + [JsonPropertyName("secret_id_bound_cidrs")] public List SecretIdBoundCidrs { get; set; } } - // Shape: { token_bound_cidrs } internal sealed class TokenBoundCidrsRequest { - [JsonPropertyName("token_bound_cidrs")] - public List TokenBoundCidrs { get; set; } + [JsonPropertyName("token_bound_cidrs")] public List TokenBoundCidrs { get; set; } } - // Shape: { token_period } internal sealed class TokenPeriodRequest { - [JsonPropertyName("token_period")] - public long TokenPeriod { get; set; } + [JsonPropertyName("token_period")] public long TokenPeriod { get; set; } } - // Shape: { hmac } internal sealed class HmacRequest { - [JsonPropertyName("hmac")] - public bool Hmac { get; set; } + [JsonPropertyName("hmac")] public bool Hmac { get; set; } } - // Shape: { lease_id } internal sealed class LeaseIdRequest { - [JsonPropertyName("lease_id")] - public string LeaseId { get; set; } + [JsonPropertyName("lease_id")] public string LeaseId { get; set; } } - // Shape: { lease_id, increment } internal sealed class LeaseRenewRequest { - [JsonPropertyName("lease_id")] - public string LeaseId { get; set; } - - [JsonPropertyName("increment")] - public int Increment { get; set; } + [JsonPropertyName("lease_id")] public string LeaseId { get; set; } + [JsonPropertyName("increment")] public int Increment { get; set; } } - // Shape: { level } internal sealed class LevelRequest { - [JsonPropertyName("level")] - public string Level { get; set; } + [JsonPropertyName("level")] public string Level { get; set; } } - // Shape: { rules } internal sealed class RulesRequest { - [JsonPropertyName("rules")] - public string Rules { get; set; } + [JsonPropertyName("rules")] public string Rules { get; set; } } - // Shape: { policy } internal sealed class PolicyTextRequest { - [JsonPropertyName("policy")] - public string Policy { get; set; } + [JsonPropertyName("policy")] public string Policy { get; set; } } - // Shape: { role, cf_instance_cert, signing_time, signature } — for CloudFoundry login internal sealed class CloudFoundryLoginRequest { - [JsonPropertyName("role")] - public string Role { get; set; } - - [JsonPropertyName("cf_instance_cert")] - public string CfInstanceCert { get; set; } - - [JsonPropertyName("signing_time")] - public string SigningTime { get; set; } - - [JsonPropertyName("signature")] - public string Signature { get; set; } + [JsonPropertyName("role")] public string Role { get; set; } + [JsonPropertyName("cf_instance_cert")] public string CfInstanceCert { get; set; } + [JsonPropertyName("signing_time")] public string SigningTime { get; set; } + [JsonPropertyName("signature")] public string Signature { get; set; } } } From 40fef8a764ffd306343acad1acaaa84c4eee3b0c Mon Sep 17 00:00:00 2001 From: Benjamin Bartels Date: Mon, 23 Feb 2026 19:11:56 +0000 Subject: [PATCH 5/6] Fix formatting of PgpKey property in OtpPgpKeyRequest --- src/VaultSharp/Core/AotRequestModels.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VaultSharp/Core/AotRequestModels.cs b/src/VaultSharp/Core/AotRequestModels.cs index dc7921cb..24f5910e 100644 --- a/src/VaultSharp/Core/AotRequestModels.cs +++ b/src/VaultSharp/Core/AotRequestModels.cs @@ -39,7 +39,7 @@ internal sealed class PathRequest internal sealed class OtpPgpKeyRequest { [JsonPropertyName("otp")] public string Otp { get; set; } - [JsonPropertyName("pgpKey")]public string PgpKey { get; set; } + [JsonPropertyName("pgpKey")] public string PgpKey { get; set; } } internal sealed class KeyNonceRequest From b848faa4002f57f91e4a3baa45aadb595a379fc3 Mon Sep 17 00:00:00 2001 From: Benjamin Bartels Date: Mon, 23 Feb 2026 19:16:31 +0000 Subject: [PATCH 6/6] Update VaultSharpJsonContext.cs --- src/VaultSharp/Core/VaultSharpJsonContext.cs | 32 -------------------- 1 file changed, 32 deletions(-) diff --git a/src/VaultSharp/Core/VaultSharpJsonContext.cs b/src/VaultSharp/Core/VaultSharpJsonContext.cs index ce0f8db8..37a9f28d 100644 --- a/src/VaultSharp/Core/VaultSharpJsonContext.cs +++ b/src/VaultSharp/Core/VaultSharpJsonContext.cs @@ -8,12 +8,9 @@ namespace VaultSharp.Core { #if NET8_0_OR_GREATER - [JsonSourceGenerationOptions( DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, PropertyNamingPolicy = JsonKnownNamingPolicy.Unspecified)] - - // === Response types (Secret wrappers) === [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] @@ -131,8 +128,6 @@ namespace VaultSharp.Core [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] [JsonSerializable(typeof(VaultSharp.V1.Commons.Secret))] - - // === Standalone response types === [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.HealthStatus))] [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.Leader))] [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.MasterCredentials))] @@ -143,21 +138,13 @@ namespace VaultSharp.Core [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.RootTokenGenerationStatus))] [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.SealStatus))] [JsonSerializable(typeof(JsonObject))] - - // === Audit backend concrete types (for AuditBackendJsonConverter) === [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.FileAuditBackend))] [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.SyslogAuditBackend))] [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.CustomAuditBackend))] - - // === Dictionary types === [JsonSerializable(typeof(Dictionary))] [JsonSerializable(typeof(Dictionary))] - - // === AliCloud policy list types (serialized inline as JSON strings) === [JsonSerializable(typeof(List))] [JsonSerializable(typeof(List))] - - // === Request model types (from AotRequestModels.cs) === [JsonSerializable(typeof(TokenRequest))] [JsonSerializable(typeof(TokenClientIdRequest))] [JsonSerializable(typeof(InputRequest))] @@ -200,8 +187,6 @@ namespace VaultSharp.Core [JsonSerializable(typeof(RulesRequest))] [JsonSerializable(typeof(PolicyTextRequest))] [JsonSerializable(typeof(CloudFoundryLoginRequest))] - - // === Named request/model types used as requestData === [JsonSerializable(typeof(VaultSharp.V1.SystemBackend.AbstractAuditBackend))] [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AuthMethod))] [JsonSerializable(typeof(VaultSharp.Core.BackendConfig))] @@ -236,27 +221,15 @@ namespace VaultSharp.Core [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Transit.CacheConfigRequestOptions))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.PKI.CertificateCredentialsRequestOptions))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.PKI.SignCertificatesRequestOptions))] - // TODO: PKITidyRequest does not exist; the actual class is CertificateTidyRequest in VaultSharp.V1.SecretsEngines.PKI - // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.PKI.PKITidyRequest))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.PKI.CertificateAutoTidyRequest))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.SSH.SignKeyRequest))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.TOTP.TOTPCreateKeyRequest))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.RabbitMQ.RabbitMQRole))] - // TODO: ConsulAccessConfigModel does not exist; the actual class is AccessConfigModel in VaultSharp.V1.SecretsEngines.Consul.Models - // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Consul.Models.ConsulAccessConfigModel))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Consul.Models.CreateConsulRoleModel))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.AWS.CreateAWSRoleModel))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.AliCloud.Models.CreateAliCloudRoleModel))] - // TODO: CreateAliCloudRootCredentialsConfigModel does not exist; the actual class is CreateRootCredentialsConfigModel in VaultSharp.V1.SecretsEngines.AliCloud.Models - // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.AliCloud.CreateAliCloudRootCredentialsConfigModel))] - // TODO: CreateADConnectionConfigModel does not exist; the actual class is CreateConnectionConfigModel in VaultSharp.V1.SecretsEngines.ActiveDirectory.Models - // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.ActiveDirectory.CreateADConnectionConfigModel))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.ActiveDirectory.Models.CreateActiveDirectoryRoleModel))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.ActiveDirectory.Models.CreateServiceAccountSetModel))] - // TODO: CreateOpenLDAPDynamicRole does not exist in the codebase - // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.OpenLDAP.CreateOpenLDAPDynamicRole))] - // TODO: CreateOpenLDAPStaticRole does not exist in the codebase - // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.OpenLDAP.CreateOpenLDAPStaticRole))] [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.Token.CreateTokenRequest))] [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.Token.CreateTokenRoleRequest))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.CreateEntityRequest))] @@ -267,19 +240,14 @@ namespace VaultSharp.Core [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.BatchDeleteEntitiesRequest))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.CreateNamedKeyRequest))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Identity.CreateRoleRequest))] - // TODO: CreateKubernetesCredentialRequestOptions does not exist in the codebase - // [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Kubernetes.CreateKubernetesCredentialRequestOptions))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Enterprise.Transform.EncodeRequestOptions))] [JsonSerializable(typeof(VaultSharp.V1.SecretsEngines.Enterprise.Transform.DecodeRequestOptions))] - - // === Auth method login types === [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AWS.AbstractAWSAuthMethodInfo))] [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.AliCloud.AliCloudAuthMethodInfo))] [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.Azure.AzureAuthMethodInfo))] [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.GoogleCloud.GoogleCloudAuthMethodInfo))] [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.JWT.JWTAuthMethodInfo))] [JsonSerializable(typeof(VaultSharp.V1.AuthMethods.Kubernetes.KubernetesAuthMethodInfo))] - internal partial class VaultSharpJsonContext : JsonSerializerContext { }