From 2bfa3f2724ba762cf0b88de2d1acf119f5ce46c2 Mon Sep 17 00:00:00 2001 From: vnugent Date: Fri, 21 Jun 2024 17:07:01 -0400 Subject: latest server changes + better validation --- .../src/VnCacheClientConfig.cs | 41 ++++++++-------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs') 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 { /// @@ -100,40 +102,27 @@ namespace VNLib.Data.Caching.Providers.VNCache } /// - 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" + ); } } } -- cgit