Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
React to configuration model changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarbettini committed Apr 12, 2016
1 parent 3ffeca1 commit 79c9785
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 40 deletions.
17 changes: 11 additions & 6 deletions doc/examples/DocExamples/ClientBuilderExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/DocExamples/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -21,5 +21,5 @@
"tooling": {
"defaultNamespace": "DocExamples"
},
"version": "0.7.1"
"version": "0.8.2"
}
2 changes: 1 addition & 1 deletion src/Stormpath.SDK.Abstractions/Client/IClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Stormpath.SDK.Abstractions/Client/IClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public interface IClientBuilder : ILoggerConsumer<IClientBuilder>, ISerializerCo
/// <example>
/// <code source="ClientBuilderExamples.cs" region="UseBasicAuthentication" lang="C#" title="Use HTTP Basic authentication" />
/// </example>
IClientBuilder SetAuthenticationScheme(Configuration.Abstractions.Model.ClientAuthenticationScheme scheme);
IClientBuilder SetAuthenticationScheme(ClientAuthenticationScheme scheme);

/// <summary>
/// Sets the HTTP connection timeout in milliseconds to observe when making requests.
Expand Down Expand Up @@ -221,7 +221,7 @@ public interface IClientBuilder : ILoggerConsumer<IClientBuilder>, ISerializerCo
/// </summary>
/// <param name="proxyConfiguration">The configuration server to use.</param>
/// <returns>This instance for method chaining.</returns>
IClientBuilder SetProxy(Configuration.Abstractions.Model.ClientProxyConfiguration proxyConfiguration);
IClientBuilder SetProxy(ClientProxyConfiguration proxyConfiguration);

/// <summary>
/// Sets the cache provider that should be used to cache Stormpath resources, reducing round-trips
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ IHttpClientBuilder IHttpClientBuilder.SetProxy(IWebProxy proxy)
}

/// <inheritdoc/>
IHttpClientBuilder IHttpClientBuilder.SetProxy(Configuration.Abstractions.Model.ClientProxyConfiguration clientProxyConfiguration)
IHttpClientBuilder IHttpClientBuilder.SetProxy(Configuration.Abstractions.Immutable.ClientProxyConfiguration clientProxyConfiguration)
{
bool proxyConfigurationMissing = string.IsNullOrEmpty(clientProxyConfiguration?.Host);

Expand Down
2 changes: 1 addition & 1 deletion src/Stormpath.SDK.Abstractions/Http/IHttpClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface IHttpClientBuilder : ILoggerConsumer<IHttpClientBuilder>
/// </summary>
/// <param name="clientProxyConfiguration">The proxy configuration.</param>
/// <returns>This instance for method chaining.</returns>
IHttpClientBuilder SetProxy(Configuration.Abstractions.Model.ClientProxyConfiguration clientProxyConfiguration);
IHttpClientBuilder SetProxy(Configuration.Abstractions.Immutable.ClientProxyConfiguration clientProxyConfiguration);

/// <summary>
/// Builds a new <see cref="IHttpClient"/> instance from the current builder state.
Expand Down
4 changes: 2 additions & 2 deletions src/Stormpath.SDK.Abstractions/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -47,6 +47,6 @@
"tooling": {
"defaultNamespace": "Stormpath.SDK"
},
"version": "0.8.2-beta1",
"version": "0.8.2",
"xmlDoc": true
}
2 changes: 1 addition & 1 deletion src/Stormpath.SDK.Core/Impl/Client/DefaultClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 28 additions & 14 deletions src/Stormpath.SDK.Core/Impl/Client/DefaultClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()
Expand All @@ -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);

Expand Down Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Stormpath.SDK.Core/Impl/Client/ShimClientApiKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.
// </copyright>

using Stormpath.Configuration.Abstractions.Model;
using Stormpath.Configuration.Abstractions.Immutable;
using Stormpath.SDK.Api;

namespace Stormpath.SDK.Impl.Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// </copyright>

using System.IO;
using Stormpath.Configuration.Abstractions.Model;
using Stormpath.Configuration.Abstractions.Immutable;
using Stormpath.SDK.Api;
using Stormpath.SDK.Logging;

Expand Down
6 changes: 3 additions & 3 deletions src/Stormpath.SDK.Core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -56,6 +56,6 @@
"tooling": {
"defaultNamespace": "Stormpath.SDK"
},
"version": "0.8.2-beta1",
"version": "0.8.2",
"xmlDoc": true
}
10 changes: 5 additions & 5 deletions test/Stormpath.SDK.Tests.Common/Integration/TestClients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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))
Expand All @@ -63,7 +63,7 @@ public static class TestClients
});

private static Lazy<StormpathConfiguration> lazyConfiguration =
new Lazy<StormpathConfiguration>(() => Configuration.ConfigurationLoader.Load());
new Lazy<StormpathConfiguration>(() => Configuration.ConfigurationLoader.Initialize().Load());

public static StormpathConfiguration CurrentConfiguration => lazyConfiguration.Value;

Expand Down

0 comments on commit 79c9785

Please sign in to comment.