diff options
author | vnugent <public@vaughnnugent.com> | 2024-06-21 17:07:01 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-06-21 17:07:01 -0400 |
commit | 2bfa3f2724ba762cf0b88de2d1acf119f5ce46c2 (patch) | |
tree | acd03c866087b96fe0ed5c2b6a5a8a319d9dc9e6 /plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs | |
parent | b21ee53a99b30a21cecd1687ca337d713c919877 (diff) |
latest server changes + better validation
Diffstat (limited to 'plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs')
-rw-r--r-- | plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs b/plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs index 0d6cd34..6ee410c 100644 --- a/plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs +++ b/plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs @@ -26,6 +26,8 @@ using System; using System.Linq; using System.Text.Json.Serialization; +using VNLib.Plugins.Extensions.Loading.Configuration; + namespace VNLib.Data.Caching.Providers.VNCache { /// <summary> @@ -100,40 +102,27 @@ namespace VNLib.Data.Caching.Providers.VNCache } ///<inheritdoc/> - public override void Validate() + public override void OnValidate() { - base.Validate(); + base.OnValidate(); - if (!DiscoveryIntervalSeconds.HasValue || DiscoveryIntervalSeconds.Value < 1) - { - throw new ArgumentException("You must specify a discovery interval period greater than 0", "retry_interval_sec"); - } + Validate.Assert(DiscoveryIntervalSeconds.HasValue, "A discovery interval is required"); + Validate.Range(DiscoveryIntervalSeconds.Value, 1, int.MaxValue); - //Allow a 0 timeout to disable timeouts, not recommended, but allowed - if (!RequestTimeoutSeconds.HasValue || RequestTimeoutSeconds.Value < 0) - { - throw new ArgumentException("You must specify a positive integer FBM message timoeut", "request_timeout_sec"); - } + Validate.Assert(RequestTimeoutSeconds.HasValue, "A request timeout is required"); + Validate.Range(RequestTimeoutSeconds.Value, 1, int.MaxValue); - //Validate initial nodes - if (InitialNodes == null || InitialNodes.Length == 0) - { - throw new ArgumentException("You must specify at least one initial peer", "initial_peers"); - } + Validate.NotNull(InitialNodes, "You must specify at least one initial cache node to connect to"); + Validate.Assert(InitialNodes.Length > 0, "You must specify at least one initial cache node to connect to"); //Validate initial nodes foreach (Uri peer in GetInitialNodeUris()) { - if (!peer.IsAbsoluteUri) - { - throw new ArgumentException("You must specify an absolute URI for each initial node", "initial_nodes"); - } - - //Verify http connection - if (peer.Scheme != Uri.UriSchemeHttp && peer.Scheme != Uri.UriSchemeHttps) - { - throw new ArgumentException("You must specify an HTTP or HTTPS URI for each initial node", "initial_nodes"); - } + Validate.Assert(peer.IsAbsoluteUri, "You must specify an absolute URI for each initial node"); + Validate.Assert( + peer.Scheme == Uri.UriSchemeHttp || peer.Scheme == Uri.UriSchemeHttps, + message: "You must specify an HTTP or HTTPS URI for each initial node" + ); } } } |