From 79c978524412ae2fb358864e27f4022f3c915cae Mon Sep 17 00:00:00 2001 From: Nate Barbettini Date: Tue, 12 Apr 2016 15:10:59 -0700 Subject: [PATCH] React to configuration model changes --- .../DocExamples/ClientBuilderExamples.cs | 17 +++++--- doc/examples/DocExamples/project.json | 4 +- .../Client/IClient.cs | 2 +- .../Client/IClientBuilder.cs | 4 +- .../Http/AbstractHttpClientBuilder.cs | 2 +- .../Http/IHttpClientBuilder.cs | 2 +- src/Stormpath.SDK.Abstractions/project.json | 4 +- .../Impl/Client/DefaultClient.cs | 2 +- .../Impl/Client/DefaultClientBuilder.cs | 42 ++++++++++++------- .../Impl/Client/ShimClientApiKey.cs | 2 +- .../Impl/Client/ShimClientApiKeyBuilder.cs | 2 +- src/Stormpath.SDK.Core/project.json | 6 +-- .../Integration/TestClients.cs | 10 ++--- 13 files changed, 59 insertions(+), 40 deletions(-) diff --git a/doc/examples/DocExamples/ClientBuilderExamples.cs b/doc/examples/DocExamples/ClientBuilderExamples.cs index cb879c95..860547cb 100644 --- a/doc/examples/DocExamples/ClientBuilderExamples.cs +++ b/doc/examples/DocExamples/ClientBuilderExamples.cs @@ -16,7 +16,6 @@ using System; using Stormpath.Configuration.Abstractions; -using Stormpath.Configuration.Abstractions.Model; using Stormpath.SDK.Account; using Stormpath.SDK.Cache; using Stormpath.SDK.Client; @@ -48,11 +47,17 @@ public void InstanceClientOptions() // These options can also be specified in a stormpath.json or stormpath.yaml file. // See: https://github.com/stormpath/stormpath-sdk-spec/blob/master/specifications/config.md var client = clientBuilder - .SetConfiguration(new StormpathConfiguration( - client: new ClientConfiguration( - apiKey: new ClientApiKeyConfiguration(file: "my_apiKey.properties"), - cacheManager: null, - authenticationScheme: ClientAuthenticationScheme.Basic))) + .SetConfiguration(new StormpathConfiguration() + { + Client = new ClientConfiguration() + { + ApiKey = new ClientApiKeyConfiguration() + { + File = "my_apiKey.properties" + }, + AuthenticationScheme = ClientAuthenticationScheme.Basic + } + }) .SetHttpClient(HttpClients.Create().RestSharpClient()) .SetSerializer(Serializers.Create().JsonNetSerializer()) .Build(); diff --git a/doc/examples/DocExamples/project.json b/doc/examples/DocExamples/project.json index b15653cf..8cbc97c8 100644 --- a/doc/examples/DocExamples/project.json +++ b/doc/examples/DocExamples/project.json @@ -2,7 +2,7 @@ "authors": [ "Nate Barbettini", "Contributors" ], "copyright": "(c) 2016 Stormpath, Inc.", "dependencies": { - "Stormpath.SDK.Core": "0.7.1", + "Stormpath.SDK.Core": "0.8.2", "Stormpath.SDK.JsonNetSerializer": "0.7.0", "Stormpath.SDK.RestSharpClient": "0.7.0" }, @@ -21,5 +21,5 @@ "tooling": { "defaultNamespace": "DocExamples" }, - "version": "0.7.1" + "version": "0.8.2" } diff --git a/src/Stormpath.SDK.Abstractions/Client/IClient.cs b/src/Stormpath.SDK.Abstractions/Client/IClient.cs index dc76c7f9..3dc83525 100644 --- a/src/Stormpath.SDK.Abstractions/Client/IClient.cs +++ b/src/Stormpath.SDK.Abstractions/Client/IClient.cs @@ -16,7 +16,7 @@ using System.Threading; using System.Threading.Tasks; -using Stormpath.Configuration.Abstractions; +using Stormpath.Configuration.Abstractions.Immutable; using Stormpath.SDK.Cache; using Stormpath.SDK.DataStore; using Stormpath.SDK.Jwt; diff --git a/src/Stormpath.SDK.Abstractions/Client/IClientBuilder.cs b/src/Stormpath.SDK.Abstractions/Client/IClientBuilder.cs index 3392a7fe..3dcb065d 100644 --- a/src/Stormpath.SDK.Abstractions/Client/IClientBuilder.cs +++ b/src/Stormpath.SDK.Abstractions/Client/IClientBuilder.cs @@ -184,7 +184,7 @@ public interface IClientBuilder : ILoggerConsumer, ISerializerCo /// /// /// - IClientBuilder SetAuthenticationScheme(Configuration.Abstractions.Model.ClientAuthenticationScheme scheme); + IClientBuilder SetAuthenticationScheme(ClientAuthenticationScheme scheme); /// /// Sets the HTTP connection timeout in milliseconds to observe when making requests. @@ -221,7 +221,7 @@ public interface IClientBuilder : ILoggerConsumer, ISerializerCo /// /// The configuration server to use. /// This instance for method chaining. - IClientBuilder SetProxy(Configuration.Abstractions.Model.ClientProxyConfiguration proxyConfiguration); + IClientBuilder SetProxy(ClientProxyConfiguration proxyConfiguration); /// /// Sets the cache provider that should be used to cache Stormpath resources, reducing round-trips diff --git a/src/Stormpath.SDK.Abstractions/Http/AbstractHttpClientBuilder.cs b/src/Stormpath.SDK.Abstractions/Http/AbstractHttpClientBuilder.cs index 57af2249..7d7625fd 100644 --- a/src/Stormpath.SDK.Abstractions/Http/AbstractHttpClientBuilder.cs +++ b/src/Stormpath.SDK.Abstractions/Http/AbstractHttpClientBuilder.cs @@ -89,7 +89,7 @@ IHttpClientBuilder IHttpClientBuilder.SetProxy(IWebProxy proxy) } /// - IHttpClientBuilder IHttpClientBuilder.SetProxy(Configuration.Abstractions.Model.ClientProxyConfiguration clientProxyConfiguration) + IHttpClientBuilder IHttpClientBuilder.SetProxy(Configuration.Abstractions.Immutable.ClientProxyConfiguration clientProxyConfiguration) { bool proxyConfigurationMissing = string.IsNullOrEmpty(clientProxyConfiguration?.Host); diff --git a/src/Stormpath.SDK.Abstractions/Http/IHttpClientBuilder.cs b/src/Stormpath.SDK.Abstractions/Http/IHttpClientBuilder.cs index 28f86692..411b5507 100644 --- a/src/Stormpath.SDK.Abstractions/Http/IHttpClientBuilder.cs +++ b/src/Stormpath.SDK.Abstractions/Http/IHttpClientBuilder.cs @@ -52,7 +52,7 @@ public interface IHttpClientBuilder : ILoggerConsumer /// /// The proxy configuration. /// This instance for method chaining. - IHttpClientBuilder SetProxy(Configuration.Abstractions.Model.ClientProxyConfiguration clientProxyConfiguration); + IHttpClientBuilder SetProxy(Configuration.Abstractions.Immutable.ClientProxyConfiguration clientProxyConfiguration); /// /// Builds a new instance from the current builder state. diff --git a/src/Stormpath.SDK.Abstractions/project.json b/src/Stormpath.SDK.Abstractions/project.json index 9f1535b1..4d9831a6 100644 --- a/src/Stormpath.SDK.Abstractions/project.json +++ b/src/Stormpath.SDK.Abstractions/project.json @@ -2,7 +2,7 @@ "authors": [ "Nate Barbettini", "Contributors" ], "copyright": "(c) 2016 Stormpath, Inc.", "dependencies": { - "Stormpath.Configuration.Abstractions": "3.0.1" + "Stormpath.Configuration.Abstractions": "4.0.0" }, "description": "Abstractions for the Stormpath .NET SDK.", "frameworks": { @@ -47,6 +47,6 @@ "tooling": { "defaultNamespace": "Stormpath.SDK" }, - "version": "0.8.2-beta1", + "version": "0.8.2", "xmlDoc": true } diff --git a/src/Stormpath.SDK.Core/Impl/Client/DefaultClient.cs b/src/Stormpath.SDK.Core/Impl/Client/DefaultClient.cs index 4d770560..e95e4be3 100644 --- a/src/Stormpath.SDK.Core/Impl/Client/DefaultClient.cs +++ b/src/Stormpath.SDK.Core/Impl/Client/DefaultClient.cs @@ -17,7 +17,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using Stormpath.Configuration.Abstractions; +using Stormpath.Configuration.Abstractions.Immutable; using Stormpath.SDK.Cache; using Stormpath.SDK.Client; using Stormpath.SDK.Http; diff --git a/src/Stormpath.SDK.Core/Impl/Client/DefaultClientBuilder.cs b/src/Stormpath.SDK.Core/Impl/Client/DefaultClientBuilder.cs index 1b32adf9..4ad8249d 100644 --- a/src/Stormpath.SDK.Core/Impl/Client/DefaultClientBuilder.cs +++ b/src/Stormpath.SDK.Core/Impl/Client/DefaultClientBuilder.cs @@ -19,7 +19,6 @@ using System.Net; using Stormpath.Configuration; using Stormpath.Configuration.Abstractions; -using Stormpath.Configuration.Abstractions.Model; using Stormpath.SDK.Api; using Stormpath.SDK.Cache; using Stormpath.SDK.Client; @@ -57,7 +56,7 @@ internal sealed class DefaultClientBuilder : IClientBuilder private ClientAuthenticationScheme useAuthenticationScheme = Default.Configuration.Client.AuthenticationScheme.Value; private string useBaseUrl = Default.Configuration.Client.BaseUrl; private int useConnectionTimeout = Default.Configuration.Client.ConnectionTimeout.Value; - private ClientProxyConfiguration useProxy = Default.Configuration.Client.Proxy; + private ClientProxyConfiguration useProxy = null; public DefaultClientBuilder(IUserAgentBuilder userAgentBuilder) { @@ -221,17 +220,23 @@ IClientBuilder IClientBuilder.SetProxy(IWebProxy proxy) if (proxyCredentials != null) { username = proxyCredentials.UserName; - username = proxyCredentials.Password; + password = proxyCredentials.Password; } - this.useProxy = new ClientProxyConfiguration(port, host, username, password); + this.useProxy = new ClientProxyConfiguration() + { + Port = port, + Host = host, + Username = username, + Password = password + }; return this; } IClientBuilder IClientBuilder.SetProxy(ClientProxyConfiguration proxyConfiguration) { - this.useProxy = proxyConfiguration ?? Default.Configuration.Client.Proxy; + this.useProxy = proxyConfiguration; return this; } @@ -302,13 +307,22 @@ IClientBuilder IClientBuilder.SetCacheProvider(ICacheProvider cacheProvider) [Obsolete] private StormpathConfiguration CreateSuppliedConfiguration() { - return new StormpathConfiguration( - new ClientConfiguration( - apiKey: new ClientApiKeyConfiguration(this.useApiKeyFileName, this.useApiKeyId, this.useApiKeySecret), - baseUrl: this.useBaseUrl, - connectionTimeout: this.useConnectionTimeout, - authenticationScheme: this.useAuthenticationScheme, - proxy: this.useProxy)); + return new StormpathConfiguration() + { + Client = new ClientConfiguration() + { + ApiKey = new ClientApiKeyConfiguration() + { + File = this.useApiKeyFileName, + Id = this.useApiKeyId, + Secret = this.useApiKeySecret + }, + BaseUrl = this.useBaseUrl, + ConnectionTimeout = this.useConnectionTimeout, + AuthenticationScheme = this.useAuthenticationScheme, + Proxy = this.useProxy + } + }; } IClient IClientBuilder.Build() @@ -321,7 +335,7 @@ IClient IClientBuilder.Build() ?? this.useConfigurationAnonymous ?? CreateSuppliedConfiguration(); - var finalConfiguration = ConfigurationLoader.Load(suppliedConfiguration, logger: logger); + var finalConfiguration = ConfigurationLoader.Initialize().Load(suppliedConfiguration); // TODO: restore logging ThrowForInvalidConfiguration(finalConfiguration); @@ -401,7 +415,7 @@ IClient IClientBuilder.Build() DefaultIdentityMapSlidingExpiration); } - private void ThrowForInvalidConfiguration(StormpathConfiguration configuration) + private void ThrowForInvalidConfiguration(Configuration.Abstractions.Immutable.StormpathConfiguration configuration) { if (string.IsNullOrEmpty(configuration.Client.BaseUrl)) { diff --git a/src/Stormpath.SDK.Core/Impl/Client/ShimClientApiKey.cs b/src/Stormpath.SDK.Core/Impl/Client/ShimClientApiKey.cs index 006f5e8c..127a4f22 100644 --- a/src/Stormpath.SDK.Core/Impl/Client/ShimClientApiKey.cs +++ b/src/Stormpath.SDK.Core/Impl/Client/ShimClientApiKey.cs @@ -14,7 +14,7 @@ // limitations under the License. // -using Stormpath.Configuration.Abstractions.Model; +using Stormpath.Configuration.Abstractions.Immutable; using Stormpath.SDK.Api; namespace Stormpath.SDK.Impl.Client diff --git a/src/Stormpath.SDK.Core/Impl/Client/ShimClientApiKeyBuilder.cs b/src/Stormpath.SDK.Core/Impl/Client/ShimClientApiKeyBuilder.cs index 8a236c15..fdd02494 100644 --- a/src/Stormpath.SDK.Core/Impl/Client/ShimClientApiKeyBuilder.cs +++ b/src/Stormpath.SDK.Core/Impl/Client/ShimClientApiKeyBuilder.cs @@ -15,7 +15,7 @@ // using System.IO; -using Stormpath.Configuration.Abstractions.Model; +using Stormpath.Configuration.Abstractions.Immutable; using Stormpath.SDK.Api; using Stormpath.SDK.Logging; diff --git a/src/Stormpath.SDK.Core/project.json b/src/Stormpath.SDK.Core/project.json index 8295cabe..365481df 100644 --- a/src/Stormpath.SDK.Core/project.json +++ b/src/Stormpath.SDK.Core/project.json @@ -3,8 +3,8 @@ "copyright": "(c) 2016 Stormpath, Inc.", "dependencies": { "Polyglot": "1.0.0", - "Stormpath.Configuration": "3.0.0", - "Stormpath.SDK.Abstractions": "0.8.2-beta1" + "Stormpath.Configuration": "4.0.0", + "Stormpath.SDK.Abstractions": "0.8.2" }, "description": "The official Stormpath SDK for .NET. Don't install this package directly; install the Stormpath.SDK package unless you are bringing your own JSON serializer and HTTP client plugins.", "frameworks": { @@ -56,6 +56,6 @@ "tooling": { "defaultNamespace": "Stormpath.SDK" }, - "version": "0.8.2-beta1", + "version": "0.8.2", "xmlDoc": true } diff --git a/test/Stormpath.SDK.Tests.Common/Integration/TestClients.cs b/test/Stormpath.SDK.Tests.Common/Integration/TestClients.cs index 2c95007e..f1768b5e 100644 --- a/test/Stormpath.SDK.Tests.Common/Integration/TestClients.cs +++ b/test/Stormpath.SDK.Tests.Common/Integration/TestClients.cs @@ -16,7 +16,7 @@ using System; using System.Collections.Generic; -using Stormpath.Configuration.Abstractions; +using Stormpath.Configuration.Abstractions.Immutable; using Stormpath.SDK.Cache; using Stormpath.SDK.Client; using Stormpath.SDK.Http; @@ -31,7 +31,7 @@ public static class TestClients return Clients.Builder() .SetHttpClient(HttpClients.Create().SystemNetHttpClient()) .SetSerializer(Serializers.Create().JsonNetSerializer()) - .SetAuthenticationScheme(Configuration.Abstractions.Model.ClientAuthenticationScheme.Basic) + .SetAuthenticationScheme(Configuration.Abstractions.ClientAuthenticationScheme.Basic) .SetLogger(StaticLogger.Instance) .SetCacheProvider(CacheProviders.Create().DisabledCache()) .Build(); @@ -42,7 +42,7 @@ public static class TestClients return Clients.Builder() .SetHttpClient(HttpClients.Create().SystemNetHttpClient()) .SetSerializer(Serializers.Create().JsonNetSerializer()) - .SetAuthenticationScheme(Configuration.Abstractions.Model.ClientAuthenticationScheme.SAuthc1) + .SetAuthenticationScheme(Configuration.Abstractions.ClientAuthenticationScheme.SAuthc1) .SetLogger(StaticLogger.Instance) .SetCacheProvider(CacheProviders.Create().DisabledCache()) .Build(); @@ -53,7 +53,7 @@ public static class TestClients return Clients.Builder() .SetHttpClient(HttpClients.Create().SystemNetHttpClient()) .SetSerializer(Serializers.Create().JsonNetSerializer()) - .SetAuthenticationScheme(Configuration.Abstractions.Model.ClientAuthenticationScheme.SAuthc1) + .SetAuthenticationScheme(Configuration.Abstractions.ClientAuthenticationScheme.SAuthc1) .SetLogger(StaticLogger.Instance) .SetCacheProvider(CacheProviders.Create().InMemoryCache() .WithDefaultTimeToIdle(TimeSpan.FromMinutes(10)) @@ -63,7 +63,7 @@ public static class TestClients }); private static Lazy lazyConfiguration = - new Lazy(() => Configuration.ConfigurationLoader.Load()); + new Lazy(() => Configuration.ConfigurationLoader.Initialize().Load()); public static StormpathConfiguration CurrentConfiguration => lazyConfiguration.Value;