Skip to content

Commit d58f314

Browse files
committed
Merge branch 'DavidLievrouw-ServiceProviderConfigurationScheme'
2 parents 2f97913 + 169b333 commit d58f314

27 files changed

+92
-21
lines changed

docs/features/servicediscovery.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ Then add the following to your ConfigureServices method.
2525
The following is required in the GlobalConfiguration. The Provider is required and if you do not specify a host and port the Consul default
2626
will be used.
2727

28+
Please note the Scheme option defauls to HTTP. It was added in this `PR <https://github.com/ThreeMammals/Ocelot/pull/1154>`_. It defaults to HTTP to not introduce a breaking change.
29+
2830
.. code-block:: json
2931
3032
"ServiceDiscoveryProvider": {
33+
"Scheme": "https",
3134
"Host": "localhost",
3235
"Port": 8500,
3336
"Type": "Consul"

src/Ocelot.Provider.Consul/ConsulClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public IConsulClient Get(ConsulRegistryConfiguration config)
99
{
1010
return new ConsulClient(c =>
1111
{
12-
c.Address = new Uri($"http://{config.Host}:{config.Port}");
12+
c.Address = new Uri($"{config.Scheme}://{config.Host}:{config.Port}");
1313

1414
if (!string.IsNullOrEmpty(config?.Token))
1515
{

src/Ocelot.Provider.Consul/ConsulFileConfigurationRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public ConsulFileConfigurationRepository(
3131
_configurationKey = string.IsNullOrWhiteSpace(serviceDiscoveryProvider.ConfigurationKey) ? "InternalConfiguration" :
3232
serviceDiscoveryProvider.ConfigurationKey;
3333

34-
var config = new ConsulRegistryConfiguration(serviceDiscoveryProvider.Host,
34+
var config = new ConsulRegistryConfiguration(serviceDiscoveryProvider.Scheme, serviceDiscoveryProvider.Host,
3535
serviceDiscoveryProvider.Port, _configurationKey, serviceDiscoveryProvider.Token);
3636

3737
_consul = factory.Get(config);

src/Ocelot.Provider.Consul/ConsulProviderFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class ConsulProviderFactory
1212

1313
var consulFactory = provider.GetService<IConsulClientFactory>();
1414

15-
var consulRegistryConfiguration = new ConsulRegistryConfiguration(config.Host, config.Port, reRoute.ServiceName, config.Token);
15+
var consulRegistryConfiguration = new ConsulRegistryConfiguration(config.Scheme, config.Host, config.Port, reRoute.ServiceName, config.Token);
1616

1717
var consulServiceDiscoveryProvider = new Consul(consulRegistryConfiguration, factory, consulFactory);
1818

src/Ocelot.Provider.Consul/ConsulRegistryConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
{
33
public class ConsulRegistryConfiguration
44
{
5-
public ConsulRegistryConfiguration(string host, int port, string keyOfServiceInConsul, string token)
5+
public ConsulRegistryConfiguration(string scheme, string host, int port, string keyOfServiceInConsul, string token)
66
{
77
Host = string.IsNullOrEmpty(host) ? "localhost" : host;
88
Port = port > 0 ? port : 8500;
9+
Scheme = string.IsNullOrEmpty(scheme) ? "http" : scheme;
910
KeyOfServiceInConsul = keyOfServiceInConsul;
1011
Token = token;
1112
}
1213

1314
public string KeyOfServiceInConsul { get; }
15+
public string Scheme { get; }
1416
public string Host { get; }
1517
public int Port { get; }
1618
public string Token { get; }

src/Ocelot/Configuration/Builder/ServiceProviderConfigurationBuilder.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace Ocelot.Configuration.Builder
22
{
33
public class ServiceProviderConfigurationBuilder
44
{
5+
private string _serviceDiscoveryProviderScheme;
56
private string _serviceDiscoveryProviderHost;
67
private int _serviceDiscoveryProviderPort;
78
private string _type;
@@ -10,6 +11,12 @@ public class ServiceProviderConfigurationBuilder
1011
private int _pollingInterval;
1112
private string _namespace;
1213

14+
public ServiceProviderConfigurationBuilder WithScheme(string serviceDiscoveryProviderScheme)
15+
{
16+
_serviceDiscoveryProviderScheme = serviceDiscoveryProviderScheme;
17+
return this;
18+
}
19+
1320
public ServiceProviderConfigurationBuilder WithHost(string serviceDiscoveryProviderHost)
1421
{
1522
_serviceDiscoveryProviderHost = serviceDiscoveryProviderHost;
@@ -54,7 +61,7 @@ public ServiceProviderConfigurationBuilder WithNamespace(string @namespace)
5461

5562
public ServiceProviderConfiguration Build()
5663
{
57-
return new ServiceProviderConfiguration(_type, _serviceDiscoveryProviderHost, _serviceDiscoveryProviderPort, _token, _configurationKey, _pollingInterval, _namespace);
64+
return new ServiceProviderConfiguration(_type, _serviceDiscoveryProviderScheme, _serviceDiscoveryProviderHost, _serviceDiscoveryProviderPort, _token, _configurationKey, _pollingInterval, _namespace);
5865
}
5966
}
6067
}

src/Ocelot/Configuration/Creator/ServiceProviderConfigurationCreator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class ServiceProviderConfigurationCreator : IServiceProviderConfiguration
88
public ServiceProviderConfiguration Create(FileGlobalConfiguration globalConfiguration)
99
{
1010
var port = globalConfiguration?.ServiceDiscoveryProvider?.Port ?? 0;
11+
var scheme = globalConfiguration?.ServiceDiscoveryProvider?.Scheme ?? "http";
1112
var host = globalConfiguration?.ServiceDiscoveryProvider?.Host ?? "localhost";
1213
var type = !string.IsNullOrEmpty(globalConfiguration?.ServiceDiscoveryProvider?.Type)
1314
? globalConfiguration?.ServiceDiscoveryProvider?.Type
@@ -16,6 +17,7 @@ public ServiceProviderConfiguration Create(FileGlobalConfiguration globalConfigu
1617
var k8snamespace = globalConfiguration?.ServiceDiscoveryProvider?.Namespace ?? string.Empty;
1718

1819
return new ServiceProviderConfigurationBuilder()
20+
.WithScheme(scheme)
1921
.WithHost(host)
2022
.WithPort(port)
2123
.WithType(type)

src/Ocelot/Configuration/File/FileServiceDiscoveryProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace Ocelot.Configuration.File
22
{
33
public class FileServiceDiscoveryProvider
44
{
5+
public string Scheme { get; set; }
56
public string Host { get; set; }
67
public int Port { get; set; }
78
public string Type { get; set; }

src/Ocelot/Configuration/ServiceProviderConfiguration.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
{
33
public class ServiceProviderConfiguration
44
{
5-
public ServiceProviderConfiguration(string type, string host, int port, string token, string configurationKey, int pollingInterval, string @namespace = "")
5+
public ServiceProviderConfiguration(string type, string scheme, string host, int port, string token, string configurationKey, int pollingInterval, string @namespace = "")
66
{
77
ConfigurationKey = configurationKey;
8+
Scheme = scheme;
89
Host = host;
910
Port = port;
1011
Token = token;
@@ -13,6 +14,8 @@ public ServiceProviderConfiguration(string type, string host, int port, string t
1314
Namespace = @namespace;
1415
}
1516

17+
public string Scheme { get; }
18+
1619
public string Host { get; }
1720

1821
public int Port { get; }

test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void should_throw_exception_if_cannot_start_because_service_discovery_pro
2424
{
2525
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
2626
{
27+
Scheme = "https",
2728
Host = "localhost",
2829
Type = "consul",
2930
Port = 8500
@@ -66,6 +67,7 @@ public void should_throw_exception_if_cannot_start_because_service_discovery_pro
6667
{
6768
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
6869
{
70+
Scheme = "https",
6971
Host = "localhost",
7072
Type = "consul",
7173
Port = 8500

0 commit comments

Comments
 (0)