Naming refactor
This commit is contained in:
Родитель
81b9dcb5e4
Коммит
e1d3af6eb5
|
@ -7,20 +7,20 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{68054802-1B1
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{51AE05BE-C7D3-48A4-9B30-4D7B90283CD8}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Spring.Extensions.Configuration.Server", "src\Spring.Extensions.Configuration.Server\Spring.Extensions.Configuration.Server.xproj", "{D06283B3-995E-4AC2-B45F-DF6A6C377644}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Spring.Extensions.Configuration.Server.Test", "test\Spring.Extensions.Configuration.Server.Test\Spring.Extensions.Configuration.Server.Test.xproj", "{ECCB52BE-A124-4213-95A3-0C4842AA55A1}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{88DEBC60-4E70-4A1C-9CD5-72A1F9DD86FF}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
global.json = global.json
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Spring.Extensions.Configuration.Server.IntegrationTest", "test\Spring.Extensions.Configuration.Server.IntegrationTest\Spring.Extensions.Configuration.Server.IntegrationTest.xproj", "{8D43B1B0-0C20-4AA5-B510-332E1190D0C3}"
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SteelToe.Extensions.Configuration.ConfigServer", "src\SteelToe.Extensions.Configuration.ConfigServer\SteelToe.Extensions.Configuration.ConfigServer.xproj", "{23413532-9D6D-4777-9560-3EBCDEC0AC03}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Spring.Extensions.Configuration.Common", "src\Spring.Extensions.Configuration.Common\Spring.Extensions.Configuration.Common.xproj", "{D06283B3-995E-4AC2-B45F-DF6A6C377655}"
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SteelToe.Extensions.Configuration.ConfigServer.Test", "test\SteelToe.Extensions.Configuration.ConfigServer.Test\SteelToe.Extensions.Configuration.ConfigServer.Test.xproj", "{85B94F1C-0F93-44B2-AF3E-1F3E05346C7D}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Spring.Extensions.Configuration.Common.Test", "test\Spring.Extensions.Configuration.Common.Test\Spring.Extensions.Configuration.Common.Test.xproj", "{ECCB52BE-A124-4213-95A3-0C4842AA55A2}"
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SteelToe.Extensions.Configuration.ConfigServer.ITest", "test\SteelToe.Extensions.Configuration.ConfigServer.ITest\SteelToe.Extensions.Configuration.ConfigServer.ITest.xproj", "{3D9B0677-D184-4E30-8503-C9F291FA1335}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SteelToe.Extensions.Configuration.CloudFoundry", "src\SteelToe.Extensions.Configuration.CloudFoundry\SteelToe.Extensions.Configuration.CloudFoundry.xproj", "{CD4399C7-81FB-49A6-8A9B-164C02CF2128}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SteelToe.Extensions.Configuration.CloudFoundry.Test", "test\SteelToe.Extensions.Configuration.CloudFoundry.Test\SteelToe.Extensions.Configuration.CloudFoundry.Test.xproj", "{6C872C62-7B97-43C7-827C-5AB8B3D7BA41}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -28,35 +28,35 @@ Global
|
|||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D06283B3-995E-4AC2-B45F-DF6A6C377644}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D06283B3-995E-4AC2-B45F-DF6A6C377644}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D06283B3-995E-4AC2-B45F-DF6A6C377644}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D06283B3-995E-4AC2-B45F-DF6A6C377644}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ECCB52BE-A124-4213-95A3-0C4842AA55A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ECCB52BE-A124-4213-95A3-0C4842AA55A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ECCB52BE-A124-4213-95A3-0C4842AA55A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ECCB52BE-A124-4213-95A3-0C4842AA55A1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8D43B1B0-0C20-4AA5-B510-332E1190D0C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8D43B1B0-0C20-4AA5-B510-332E1190D0C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8D43B1B0-0C20-4AA5-B510-332E1190D0C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8D43B1B0-0C20-4AA5-B510-332E1190D0C3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D06283B3-995E-4AC2-B45F-DF6A6C377655}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D06283B3-995E-4AC2-B45F-DF6A6C377655}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D06283B3-995E-4AC2-B45F-DF6A6C377655}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D06283B3-995E-4AC2-B45F-DF6A6C377655}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ECCB52BE-A124-4213-95A3-0C4842AA55A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ECCB52BE-A124-4213-95A3-0C4842AA55A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ECCB52BE-A124-4213-95A3-0C4842AA55A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ECCB52BE-A124-4213-95A3-0C4842AA55A2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{23413532-9D6D-4777-9560-3EBCDEC0AC03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{23413532-9D6D-4777-9560-3EBCDEC0AC03}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{23413532-9D6D-4777-9560-3EBCDEC0AC03}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{23413532-9D6D-4777-9560-3EBCDEC0AC03}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{85B94F1C-0F93-44B2-AF3E-1F3E05346C7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{85B94F1C-0F93-44B2-AF3E-1F3E05346C7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{85B94F1C-0F93-44B2-AF3E-1F3E05346C7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{85B94F1C-0F93-44B2-AF3E-1F3E05346C7D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3D9B0677-D184-4E30-8503-C9F291FA1335}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3D9B0677-D184-4E30-8503-C9F291FA1335}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3D9B0677-D184-4E30-8503-C9F291FA1335}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3D9B0677-D184-4E30-8503-C9F291FA1335}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CD4399C7-81FB-49A6-8A9B-164C02CF2128}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CD4399C7-81FB-49A6-8A9B-164C02CF2128}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CD4399C7-81FB-49A6-8A9B-164C02CF2128}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CD4399C7-81FB-49A6-8A9B-164C02CF2128}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6C872C62-7B97-43C7-827C-5AB8B3D7BA41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6C872C62-7B97-43C7-827C-5AB8B3D7BA41}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6C872C62-7B97-43C7-827C-5AB8B3D7BA41}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6C872C62-7B97-43C7-827C-5AB8B3D7BA41}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{D06283B3-995E-4AC2-B45F-DF6A6C377644} = {68054802-1B15-4550-8ED5-1899E5EA3DD9}
|
||||
{ECCB52BE-A124-4213-95A3-0C4842AA55A1} = {51AE05BE-C7D3-48A4-9B30-4D7B90283CD8}
|
||||
{8D43B1B0-0C20-4AA5-B510-332E1190D0C3} = {51AE05BE-C7D3-48A4-9B30-4D7B90283CD8}
|
||||
{D06283B3-995E-4AC2-B45F-DF6A6C377655} = {68054802-1B15-4550-8ED5-1899E5EA3DD9}
|
||||
{ECCB52BE-A124-4213-95A3-0C4842AA55A2} = {51AE05BE-C7D3-48A4-9B30-4D7B90283CD8}
|
||||
{23413532-9D6D-4777-9560-3EBCDEC0AC03} = {68054802-1B15-4550-8ED5-1899E5EA3DD9}
|
||||
{85B94F1C-0F93-44B2-AF3E-1F3E05346C7D} = {51AE05BE-C7D3-48A4-9B30-4D7B90283CD8}
|
||||
{3D9B0677-D184-4E30-8503-C9F291FA1335} = {51AE05BE-C7D3-48A4-9B30-4D7B90283CD8}
|
||||
{CD4399C7-81FB-49A6-8A9B-164C02CF2128} = {68054802-1B15-4550-8ED5-1899E5EA3DD9}
|
||||
{6C872C62-7B97-43C7-827C-5AB8B3D7BA41} = {51AE05BE-C7D3-48A4-9B30-4D7B90283CD8}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
{
|
||||
"projects": [ "src", "test" ],
|
||||
{
|
||||
"projects": [
|
||||
"src",
|
||||
"test"
|
||||
],
|
||||
"sdk": {
|
||||
"version": "1.0.0-rc1-final"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,8 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Simple.Model;
|
||||
using Spring.Extensions.Configuration.Server;
|
||||
using SteelToe.Extensions.Configuration.ConfigServer;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Simple.Controllers
|
||||
{
|
||||
|
@ -15,7 +16,9 @@ namespace Simple.Controllers
|
|||
|
||||
private ConfigServerClientSettingsOptions ConfigServerClientSettingsOptions { get; set; }
|
||||
|
||||
public HomeController(IOptions<ConfigServerData> configServerData, IOptions<ConfigServerClientSettingsOptions> confgServerSettings)
|
||||
private IConfigurationRoot Config { get; set; }
|
||||
|
||||
public HomeController(IConfigurationRoot config, IOptions<ConfigServerData> configServerData, IOptions<ConfigServerClientSettingsOptions> confgServerSettings)
|
||||
{
|
||||
// The ASP.NET DI mechanism injects the data retrieved from the Spring Cloud Config Server
|
||||
// as an IOptions<ConfigServerData>. This happens because we added the call to:
|
||||
|
@ -26,6 +29,8 @@ namespace Simple.Controllers
|
|||
// The settings used in communicating with the Spring Cloud Config Server
|
||||
if (confgServerSettings != null)
|
||||
ConfigServerClientSettingsOptions = confgServerSettings.Value;
|
||||
|
||||
Config = config;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
|
@ -54,6 +59,32 @@ namespace Simple.Controllers
|
|||
|
||||
public IActionResult ConfigServer()
|
||||
{
|
||||
CreateConfigServerDataViewData();
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Reload()
|
||||
{
|
||||
if (Config != null)
|
||||
{
|
||||
Config.Reload();
|
||||
|
||||
|
||||
// TODO: When moving to RC2 use Options track change feature
|
||||
// CreateConfigServerDataViewData();
|
||||
ViewData["Bar"] = Config["bar"] ?? "Not returned";
|
||||
ViewData["Foo"] = Config["foo"] ?? "Not returned";
|
||||
|
||||
ViewData["Info.Url"] = Config["info:url"] ?? "Not returned";
|
||||
ViewData["Info.Description"] = Config["info:description"] ??"Not returned";
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
private void CreateConfigServerDataViewData()
|
||||
{
|
||||
|
||||
// ConfigServerData property is set to a ConfigServerData POCO that has been
|
||||
// initialized with the configuration data returned from the Spring Cloud Config Server
|
||||
if (ConfigServerData != null)
|
||||
|
@ -61,14 +92,14 @@ namespace Simple.Controllers
|
|||
ViewData["Bar"] = ConfigServerData.Bar ?? "Not returned";
|
||||
ViewData["Foo"] = ConfigServerData.Foo ?? "Not returned";
|
||||
|
||||
ViewData["Info.Url"] = "Not returned";
|
||||
ViewData["Info.Url"] = "Not returned";
|
||||
ViewData["Info.Description"] = "Not returned";
|
||||
|
||||
if (ConfigServerData.Info != null)
|
||||
{
|
||||
ViewData["Info.Url"] = ConfigServerData.Info.Url ?? "Not returned";
|
||||
ViewData["Info.Description"] = ConfigServerData.Info.Description ?? "Not returned";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ViewData["Bar"] = "Not Available";
|
||||
|
@ -77,7 +108,6 @@ namespace Simple.Controllers
|
|||
ViewData["Info.Description"] = "Not Available";
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult ConfigServerSettings()
|
||||
|
|
|
@ -7,9 +7,10 @@ using Microsoft.AspNet.Hosting;
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Spring.Extensions.Configuration.Server;
|
||||
using Simple.Model;
|
||||
|
||||
using SteelToe.Extensions.Configuration;
|
||||
|
||||
namespace Simple
|
||||
{
|
||||
//
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
@{
|
||||
ViewData["Title"] = "Configuration Data reloaded from Spring Cloud Config Server";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"]</h2>
|
||||
<h4>Property bar=@ViewData["Bar"]</h4>
|
||||
<h4>Property foo=@ViewData["Foo"]</h4>
|
||||
<h4>Property info.url=@ViewData["Info.Url"]</h4>
|
||||
<h4>Property info.description=@ViewData["Info.Description"]</h4>
|
|
@ -35,6 +35,7 @@
|
|||
<li><a asp-controller="Home" asp-action="Contact">Contact</a></li>
|
||||
<li><a asp-controller="Home" asp-action="ConfigServerSettings">Config Server Settings</a></li>
|
||||
<li><a asp-controller="Home" asp-action="ConfigServer">Config Server Data</a></li>
|
||||
<li><a asp-controller="Home" asp-action="Reload">Reload</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"version": "1.0.0",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
|
@ -12,13 +12,14 @@
|
|||
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
|
||||
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
|
||||
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
|
||||
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
|
||||
"Spring.Extensions.Configuration.Server": "1.0.7-*"
|
||||
"SteelToe.Extensions.Configuration.ConfigServer": "1.0.0"
|
||||
},
|
||||
|
||||
"commands": {
|
||||
|
@ -26,7 +27,10 @@
|
|||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnx451": {
|
||||
"dependencies": {
|
||||
}
|
||||
},
|
||||
"dnxcore50": { }
|
||||
},
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Spring.Extensions.Configuration.Server;
|
||||
using SteelToe.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
|
@ -113,12 +113,8 @@
|
|||
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Spring.Extensions.Configuration.Common, Version=1.0.7.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Spring.Extensions.Configuration.Common.1.0.7\lib\net451\Spring.Extensions.Configuration.Common.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Spring.Extensions.Configuration.Server, Version=1.0.6.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Spring.Extensions.Configuration.Server.1.0.6\lib\net451\Spring.Extensions.Configuration.Server.dll</HintPath>
|
||||
<Reference Include="SteelToe.Extensions.Configuration.ConfigServer, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SteelToe.Extensions.Configuration.ConfigServer.1.0.0\lib\net451\SteelToe.Extensions.Configuration.ConfigServer.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
|
|
|
@ -30,8 +30,7 @@
|
|||
<package id="Modernizr" version="2.6.2" targetFramework="net451" />
|
||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net451" />
|
||||
<package id="Respond" version="1.2.0" targetFramework="net451" />
|
||||
<package id="Spring.Extensions.Configuration.Common" version="1.0.7" targetFramework="net451" />
|
||||
<package id="Spring.Extensions.Configuration.Server" version="1.0.6" targetFramework="net451" />
|
||||
<package id="SteelToe.Extensions.Configuration.ConfigServer" version="1.0.0" targetFramework="net451" />
|
||||
<package id="System.Net.Http" version="4.0.0" targetFramework="net451" />
|
||||
<package id="WebGrease" version="1.5.2" targetFramework="net451" />
|
||||
</packages>
|
|
@ -1,28 +0,0 @@
|
|||
{
|
||||
"version": "1.0.7-*",
|
||||
"description": "ASP.NET 5 Spring Cloud Config Server Configuration Provider - Common Code",
|
||||
"authors": [ "Pivotal", "dtillman" ],
|
||||
"tags": [ "CloudFoundry", "ASPNET5", "Spring", "Spring Cloud Services", "Spring Cloud Config Server" ],
|
||||
"projectUrl": "http://steeltoe.io",
|
||||
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
|
||||
"copyright": "Copyright 2015 the original authors",
|
||||
"frameworks": {
|
||||
"net451": {
|
||||
"dependencies": {
|
||||
}
|
||||
},
|
||||
"dnxcore50": {
|
||||
"dependencies": {
|
||||
"System.Net.Http.WinHttpHandler": "4.0.0-beta-*"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Hosting.Abstractions": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc1-final",
|
||||
"Newtonsoft.Json": "7.0.1",
|
||||
"System.Net.Http": "4.0.0"
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
//
|
||||
// Copyright 2015 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
using Spring.Extensions.Configuration.Common;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the settings used to configure the Spring Cloud Config Server provider
|
||||
/// <see cref="ConfigServerConfigurationProvider"/>.
|
||||
/// </summary>
|
||||
public class ConfigServerClientSettings : ConfigServerClientSettingsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Default Config Server address used by provider
|
||||
/// </summary>
|
||||
public const string DEFAULT_URI = "http://localhost:8888";
|
||||
|
||||
/// <summary>
|
||||
/// Default enironment used when accessing configuration data
|
||||
/// </summary>
|
||||
public const string DEFAULT_ENVIRONMENT = "Production";
|
||||
|
||||
/// <summary>
|
||||
/// Default fail fast setting
|
||||
/// </summary>
|
||||
public const bool DEFAULT_FAILFAST = false;
|
||||
|
||||
/// <summary>
|
||||
/// Default Config Server provider enabled setting
|
||||
/// </summary>
|
||||
public const bool DEFAULT_PROVIDER_ENABLED = true;
|
||||
|
||||
/// <summary>
|
||||
/// Default certifcate validation enabled setting
|
||||
/// </summary>
|
||||
public const bool DEFAULT_CERTIFICATE_VALIDATION = true;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize Config Server client settings with defaults
|
||||
/// </summary>
|
||||
public ConfigServerClientSettings() : base()
|
||||
{
|
||||
ValidateCertificates = DEFAULT_CERTIFICATE_VALIDATION;
|
||||
FailFast = DEFAULT_FAILFAST;
|
||||
Environment = DEFAULT_ENVIRONMENT;
|
||||
Enabled = DEFAULT_PROVIDER_ENABLED;
|
||||
Uri = DEFAULT_URI;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
//
|
||||
// Copyright 2015 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
|
||||
using System.Net.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Spring.Extensions.Configuration.Common;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// A Spring Cloud Config Server based <see cref="ConfigurationProvider"/>.
|
||||
/// </summary>
|
||||
public class ConfigServerConfigurationProvider : ConfigServerConfigurationProviderBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="ConfigServerConfigurationProvider"/> with default
|
||||
/// configuration settings. <see cref="ConfigServerClientSettings"/>
|
||||
/// <param name="logFactory">optional logging factory</param>
|
||||
/// </summary>
|
||||
public ConfigServerConfigurationProvider(ILoggerFactory logFactory = null) :
|
||||
base(new ConfigServerClientSettings(), logFactory)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="ConfigServerConfigurationProvider"/>.
|
||||
/// </summary>
|
||||
/// <param name="settings">the configuration settings the provider uses when
|
||||
/// accessing the server.</param>
|
||||
/// <param name="logFactory">optional logging factory</param>
|
||||
/// </summary>
|
||||
public ConfigServerConfigurationProvider(ConfigServerClientSettings settings, ILoggerFactory logFactory = null) :
|
||||
base(settings, logFactory)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="ConfigServerConfigurationProvider"/>.
|
||||
/// </summary>
|
||||
/// <param name="settings">the configuration settings the provider uses when
|
||||
/// accessing the server.</param>
|
||||
/// <param name="httpClient">a HttpClient the provider uses to make requests of
|
||||
/// the server.</param>
|
||||
/// <param name="logFactory">optional logging factory</param>
|
||||
/// </summary>
|
||||
public ConfigServerConfigurationProvider(ConfigServerClientSettings settings, HttpClient httpClient, ILoggerFactory logFactory = null) :
|
||||
base(settings, httpClient, logFactory)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The configuration settings the provider uses when accessing the server.
|
||||
/// </summary>
|
||||
public virtual ConfigServerClientSettings Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return _settings as ConfigServerClientSettings;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,197 @@
|
|||
//
|
||||
// Copyright 2015 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SteelToe.Extensions.Configuration.CloudFoundry
|
||||
{
|
||||
|
||||
public class CloudFoundryApplicationOptions
|
||||
{
|
||||
public Vcap Vcap { get; set; }
|
||||
|
||||
public string ApplicationId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vcap?.Application?.Application_Id;
|
||||
}
|
||||
}
|
||||
|
||||
public string ApplicationName
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vcap?.Application?.Application_Name;
|
||||
}
|
||||
}
|
||||
public string[] ApplicationUris
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vcap?.Application?.Application_Uris;
|
||||
}
|
||||
}
|
||||
public string ApplicationVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vcap?.Application?.Application_Version;
|
||||
}
|
||||
}
|
||||
public string InstanceId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vcap?.Application?.Instance_Id;
|
||||
}
|
||||
}
|
||||
public int InstanceIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetInt(Vcap?.Application?.Instance_Index, -1);
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vcap?.Application?.Name;
|
||||
}
|
||||
}
|
||||
public int Port
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetInt(Vcap?.Application?.Port, -1);
|
||||
}
|
||||
}
|
||||
public string SpaceId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vcap?.Application?.Space_Id;
|
||||
}
|
||||
}
|
||||
public string SpaceName
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vcap?.Application?.Space_Name;
|
||||
}
|
||||
}
|
||||
public string Start
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vcap?.Application?.Start;
|
||||
}
|
||||
}
|
||||
public string[] Uris
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vcap?.Application?.Uris;
|
||||
}
|
||||
}
|
||||
public string Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vcap?.Application?.Version;
|
||||
}
|
||||
}
|
||||
public int DiskLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
var limits = Vcap?.Application?.Limits;
|
||||
if ( limits == null)
|
||||
return -1;
|
||||
return GetInt(limits.Disk, -1);
|
||||
}
|
||||
}
|
||||
public int MemoryLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
var limits = Vcap?.Application?.Limits;
|
||||
if (limits == null)
|
||||
return -1;
|
||||
return GetInt(limits.Mem, -1);
|
||||
}
|
||||
}
|
||||
public int FileDescriptorLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
var limits = Vcap?.Application?.Limits;
|
||||
if (limits == null)
|
||||
return -1;
|
||||
return GetInt(limits.Fds, -1);
|
||||
}
|
||||
}
|
||||
|
||||
private int GetInt(string strValue, int def)
|
||||
{
|
||||
|
||||
int result = def;
|
||||
if (!string.IsNullOrEmpty(strValue))
|
||||
{
|
||||
int.TryParse(strValue, out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Vcap
|
||||
{
|
||||
public Application Application { get; set; }
|
||||
|
||||
public Dictionary<string, Service[]> Services { get; set; }
|
||||
}
|
||||
public class Application
|
||||
{
|
||||
public string Application_Id { get; set; }
|
||||
public string Application_Name { get; set; }
|
||||
public string[] Application_Uris { get; set; }
|
||||
public string Application_Version { get; set; }
|
||||
public string Instance_Id { get; set; }
|
||||
public string Instance_Index { get; set; }
|
||||
public Limits Limits { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Port { get; set; }
|
||||
public string Space_Id { get; set; }
|
||||
public string Space_Name { get; set; }
|
||||
public string Start { get; set; }
|
||||
public string[] Uris { get; set; }
|
||||
public string Version { get; set; }
|
||||
}
|
||||
public class Limits
|
||||
{
|
||||
public string Disk { get; set; }
|
||||
public string Fds { get; set; }
|
||||
public string Mem { get; set; }
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -14,24 +14,26 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
|
||||
using Xunit;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using SteelToe.Extensions.Configuration.CloudFoundry;
|
||||
using System;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.Test
|
||||
namespace SteelToe.Extensions.Configuration
|
||||
{
|
||||
public class ConfigServerClientSettingsTest
|
||||
public static class CloudFoundryConfigurationBuilderExtensions
|
||||
{
|
||||
[Fact]
|
||||
public void DefaultConstructor_InitializedWithDefaults()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
|
||||
// Act and Assert
|
||||
ConfigServerTestHelpers.VerifyDefaults(settings);
|
||||
public static IConfigurationBuilder AddCloudFoundry(this IConfigurationBuilder configurationBuilder)
|
||||
{
|
||||
if (configurationBuilder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(configurationBuilder));
|
||||
}
|
||||
|
||||
configurationBuilder.Add(new CloudFoundryConfigurationProvider());
|
||||
|
||||
return configurationBuilder;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
//
|
||||
// Copyright 2015 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace SteelToe.Extensions.Configuration.CloudFoundry
|
||||
{
|
||||
public class CloudFoundryConfigurationProvider : ConfigurationProvider
|
||||
{
|
||||
private const string VCAP_PREFIX = "VCAP_";
|
||||
private const string APPLICATION = "APPLICATION";
|
||||
private const string SERVICES = "SERVICES";
|
||||
|
||||
public CloudFoundryConfigurationProvider()
|
||||
{
|
||||
}
|
||||
public override void Load()
|
||||
{
|
||||
var builder = new ConfigurationBuilder();
|
||||
builder.AddEnvironmentVariables(VCAP_PREFIX);
|
||||
var vcap = builder.Build();
|
||||
Process(vcap);
|
||||
}
|
||||
|
||||
private void Process(IConfigurationRoot vcap)
|
||||
{
|
||||
string appJson = vcap[APPLICATION];
|
||||
if (!string.IsNullOrEmpty(appJson))
|
||||
{
|
||||
|
||||
//TODO: Use JsonStreamConfigurationProvider when ASP.NET5 Configuration PR accepted
|
||||
var path = CreateTempFile(appJson);
|
||||
ConfigurationBuilder builder = new ConfigurationBuilder();
|
||||
builder.AddJsonFile(path);
|
||||
var applicationData = builder.Build();
|
||||
|
||||
if (applicationData != null)
|
||||
{
|
||||
LoadData("vcap:application", applicationData.GetChildren());
|
||||
string vcapAppName = Data["vcap:application:name"];
|
||||
if (!string.IsNullOrEmpty(vcapAppName))
|
||||
{
|
||||
Data["spring:application:name"] = vcapAppName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string appServicesJson = vcap[SERVICES];
|
||||
if (!string.IsNullOrEmpty(appServicesJson))
|
||||
{
|
||||
//TODO: Use JsonStreamConfigurationProvider when ASP.NET5 Configuration PR accepted
|
||||
var path = CreateTempFile(appServicesJson);
|
||||
ConfigurationBuilder builder = new ConfigurationBuilder();
|
||||
builder.AddJsonFile(path);
|
||||
var servicesData = builder.Build();
|
||||
|
||||
if (servicesData != null)
|
||||
{
|
||||
LoadData("vcap:services", servicesData.GetChildren());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
internal IDictionary<string, string> Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
return Data;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData(string prefix, IEnumerable<IConfigurationSection> sections)
|
||||
{
|
||||
if (sections == null || sections.Count() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach(IConfigurationSection section in sections)
|
||||
{
|
||||
LoadSection(prefix, section);
|
||||
LoadData(prefix, section.GetChildren());
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadSection(string prefix, IConfigurationSection section)
|
||||
{
|
||||
if (section == null)
|
||||
return;
|
||||
if (string.IsNullOrEmpty(section.Value))
|
||||
return;
|
||||
Data[prefix + Constants.KeyDelimiter + section.Path] = section.Value;
|
||||
}
|
||||
|
||||
// TODO: Remove when moving to JsonStreamConfigurationProvider
|
||||
private static string CreateTempFile(string contents)
|
||||
{
|
||||
var tempFile = Path.GetTempFileName();
|
||||
File.WriteAllText(tempFile, contents);
|
||||
return tempFile;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
//
|
||||
// Copyright 2015 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SteelToe.Extensions.Configuration.CloudFoundry;
|
||||
using System;
|
||||
|
||||
|
||||
namespace SteelToe.Extensions.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for adding services related to CloudFoundry
|
||||
/// </summary>
|
||||
public static class CloudFoundryServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A convenience extension method that can optionally be used to add Spring Cloud Config Server client services to the
|
||||
/// ServiceCollection. It adds the IOptions service to the IServiceCollection and then configures IOption service
|
||||
/// with CloudFoundryApplicationOptions and CloudFoundryServicesOptions.
|
||||
/// It also adds the IConfigurationRoot as a service instance to the collection.
|
||||
/// After a call to this method, you will be able to use the DI mechanism to get access to all of these components.
|
||||
/// </summary>
|
||||
/// <param name="services">the service collection to add the services to (required)</param>
|
||||
/// <param name="config">the Iconfiguration root (required)</param>
|
||||
/// <returns>update IServiceCollection</returns>
|
||||
public static IServiceCollection AddCloudFoundry(this IServiceCollection services, IConfigurationRoot config)
|
||||
{
|
||||
if (services == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(services));
|
||||
}
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(config));
|
||||
}
|
||||
|
||||
services.AddOptions();
|
||||
services.Configure<CloudFoundryApplicationOptions>(config);
|
||||
services.Configure<CloudFoundryServicesOptions>(config);
|
||||
services.AddInstance<IConfigurationRoot>(config);
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
//
|
||||
// Copyright 2015 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SteelToe.Extensions.Configuration.CloudFoundry
|
||||
{
|
||||
public class CloudFoundryServicesOptions
|
||||
{
|
||||
public Vcap Vcap { get; set; }
|
||||
|
||||
public IList<Service> Services
|
||||
{
|
||||
get
|
||||
{
|
||||
List<Service> results = new List<Service>();
|
||||
var services = Vcap?.Services;
|
||||
if (services != null)
|
||||
{
|
||||
foreach(KeyValuePair<string, Service[]> kvp in services)
|
||||
{
|
||||
results.AddRange(kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Service
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Label { get; set; }
|
||||
public string[] Tags { get; set; }
|
||||
public string Plan { get; set; }
|
||||
public Dictionary<string, Credential> Credentials { get; set; }
|
||||
}
|
||||
|
||||
[TypeConverter(typeof(CredentialConverter))]
|
||||
public class Credential : Dictionary<string, Credential> {
|
||||
|
||||
private string _value;
|
||||
public Credential()
|
||||
{
|
||||
|
||||
}
|
||||
public Credential(string value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public string Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CredentialConverter : TypeConverter
|
||||
{
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
if (value is string)
|
||||
return new Credential((string)value);
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
if (sourceType == typeof(string))
|
||||
return true;
|
||||
return base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
|
|||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Spring.Extensions.Configuration.Server")]
|
||||
[assembly: AssemblyTitle("SteelToe.Extensions.Configuration.CloudFoundry")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Spring.Extensions.Configuration.Server")]
|
||||
[assembly: AssemblyProduct("SteelToe.Extensions.Configuration.CloudFoundry")]
|
||||
[assembly: AssemblyCopyright("Copyright © Original Authors 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
@ -20,6 +20,6 @@ using System.Runtime.InteropServices;
|
|||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("d06283b3-995e-4ac2-b45f-df6a6c377644")]
|
||||
[assembly: Guid("cd4399c7-81fb-49a6-8a9b-164c02cf2128")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Spring.Extensions.Configuration.Server.Test")]
|
||||
[assembly: InternalsVisibleTo("SteelToe.Extensions.Configuration.CloudFoundry.Test")]
|
|
@ -6,8 +6,8 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>d06283b3-995e-4ac2-b45f-df6a6c377655</ProjectGuid>
|
||||
<RootNamespace>Spring.Extensions.Configuration.Common</RootNamespace>
|
||||
<ProjectGuid>cd4399c7-81fb-49a6-8a9b-164c02cf2128</ProjectGuid>
|
||||
<RootNamespace>SteelToe.Extensions.Configuration.CloudFoundry</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"version": "1.0.0",
|
||||
"description": "ASP.NET 5 CloudFoundry Environment Variable Configuration Provider",
|
||||
"authors": [ "Pivotal", "dtillman" ],
|
||||
"tags": [ "CloudFoundry", "ASPNET5", "Spring", "Spring Cloud" ],
|
||||
"projectUrl": "http://steeltoe.io",
|
||||
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
|
||||
"copyright": "Copyright 2015 the original authors",
|
||||
"frameworks": {
|
||||
"net451": {
|
||||
"dependencies": {
|
||||
}
|
||||
},
|
||||
"dnxcore50": {
|
||||
"dependencies": {
|
||||
"System.ComponentModel.TypeConverter": "4.0.1-beta-23516"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.Extensions.Configuration": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.OptionsModel": "1.0.0-rc1-final",
|
||||
"Newtonsoft.Json": "7.0.1"
|
||||
}
|
||||
}
|
||||
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer
|
||||
{
|
||||
public class Environment
|
||||
public class ConfigEnvironment
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Label { get; set; }
|
|
@ -16,11 +16,50 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer
|
||||
{
|
||||
|
||||
public class ConfigServerClientSettingsBase
|
||||
/// <summary>
|
||||
/// Holds the settings used to configure the Spring Cloud Config Server provider
|
||||
/// <see cref="ConfigServerConfigurationProvider"/>.
|
||||
/// </summary>
|
||||
public class ConfigServerClientSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Default Config Server address used by provider
|
||||
/// </summary>
|
||||
public const string DEFAULT_URI = "http://localhost:8888";
|
||||
|
||||
/// <summary>
|
||||
/// Default enironment used when accessing configuration data
|
||||
/// </summary>
|
||||
public const string DEFAULT_ENVIRONMENT = "Production";
|
||||
|
||||
/// <summary>
|
||||
/// Default fail fast setting
|
||||
/// </summary>
|
||||
public const bool DEFAULT_FAILFAST = false;
|
||||
|
||||
/// <summary>
|
||||
/// Default Config Server provider enabled setting
|
||||
/// </summary>
|
||||
public const bool DEFAULT_PROVIDER_ENABLED = true;
|
||||
|
||||
/// <summary>
|
||||
/// Default certifcate validation enabled setting
|
||||
/// </summary>
|
||||
public const bool DEFAULT_CERTIFICATE_VALIDATION = true;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize Config Server client settings with defaults
|
||||
/// </summary>
|
||||
public ConfigServerClientSettings() : base()
|
||||
{
|
||||
ValidateCertificates = DEFAULT_CERTIFICATE_VALIDATION;
|
||||
FailFast = DEFAULT_FAILFAST;
|
||||
Environment = DEFAULT_ENVIRONMENT;
|
||||
Enabled = DEFAULT_PROVIDER_ENABLED;
|
||||
Uri = DEFAULT_URI;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Config Server address
|
||||
|
@ -35,7 +74,7 @@ namespace Spring.Extensions.Configuration.Common
|
|||
/// <summary>
|
||||
/// The environment used when accessing configuration data
|
||||
/// </summary>
|
||||
public virtual string Environment { get; set; }
|
||||
public virtual string Environment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The application name used when accessing configuration data
|
||||
|
@ -52,7 +91,8 @@ namespace Spring.Extensions.Configuration.Common
|
|||
/// </summary>
|
||||
public virtual string Username
|
||||
{
|
||||
get { return GetUserName(); } set { this.username = value; }
|
||||
get { return GetUserName(); }
|
||||
set { this.username = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -60,7 +100,8 @@ namespace Spring.Extensions.Configuration.Common
|
|||
/// </summary>
|
||||
public virtual string Password
|
||||
{
|
||||
get { return GetPassword(); } set { this.password = value; }
|
||||
get { return GetPassword(); }
|
||||
set { this.password = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -73,6 +114,9 @@ namespace Spring.Extensions.Configuration.Common
|
|||
/// </summary>
|
||||
public virtual bool ValidateCertificates { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the HttpRequestUrl, unescaped
|
||||
/// </summary>
|
||||
public virtual string RawUri
|
||||
{
|
||||
get
|
||||
|
@ -81,13 +125,6 @@ namespace Spring.Extensions.Configuration.Common
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize Config Server client settings
|
||||
/// </summary>
|
||||
internal protected ConfigServerClientSettingsBase()
|
||||
{
|
||||
}
|
||||
|
||||
internal string GetRawUri()
|
||||
{
|
||||
try
|
||||
|
@ -98,10 +135,10 @@ namespace Spring.Extensions.Configuration.Common
|
|||
return uri.GetComponents(UriComponents.HttpRequestUrl, UriFormat.Unescaped);
|
||||
}
|
||||
}
|
||||
catch (UriFormatException e)
|
||||
catch (UriFormatException)
|
||||
{
|
||||
// Log
|
||||
|
||||
|
||||
|
||||
}
|
||||
return Uri;
|
||||
}
|
||||
|
@ -111,7 +148,8 @@ namespace Spring.Extensions.Configuration.Common
|
|||
return password;
|
||||
return GetUserPassElement(1);
|
||||
}
|
||||
internal string GetUserName() {
|
||||
internal string GetUserName()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(username))
|
||||
return username;
|
||||
return GetUserPassElement(0);
|
||||
|
@ -128,7 +166,7 @@ namespace Spring.Extensions.Configuration.Common
|
|||
return uri.UserInfo;
|
||||
}
|
||||
}
|
||||
catch (UriFormatException e)
|
||||
catch (UriFormatException)
|
||||
{
|
||||
// Log
|
||||
throw;
|
||||
|
@ -155,6 +193,9 @@ namespace Spring.Extensions.Configuration.Common
|
|||
private string password;
|
||||
|
||||
private static readonly char[] COLON_DELIMIT = new char[] { ':' };
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer
|
||||
{
|
||||
public class ConfigServerClientSettingsOptions
|
||||
{
|
|
@ -19,14 +19,14 @@ using System.Collections.Generic;
|
|||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Spring.Extensions.Configuration.Common;
|
||||
using SteelToe.Extensions.Configuration.ConfigServer;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server
|
||||
namespace SteelToe.Extensions.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for adding <see cref="ConfigServerConfigurationProvider"/>.
|
||||
/// </summary>
|
||||
public static class ConfigServerConfigurationExtensions
|
||||
public static class ConfigServerConfigurationBuilderExtensions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
|
@ -81,7 +81,7 @@ namespace Spring.Extensions.Configuration.Server
|
|||
if (providers != null)
|
||||
{
|
||||
ConfigurationRoot existing = new ConfigurationRoot(new List<IConfigurationProvider>(providers));
|
||||
ConfigServerConfigurationSettingsHelper.Initialize(PREFIX, settings, environment, existing);
|
||||
ConfigurationSettingsHelper.Initialize(PREFIX, settings, environment, existing);
|
||||
}
|
||||
|
||||
return settings;
|
|
@ -15,31 +15,41 @@
|
|||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Net.Http;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using System.Net.Http.Headers;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Security;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer
|
||||
{
|
||||
|
||||
public class ConfigServerConfigurationProviderBase : ConfigurationProvider
|
||||
/// <summary>
|
||||
/// A Spring Cloud Config Server based <see cref="ConfigurationProvider"/>.
|
||||
/// </summary>
|
||||
public class ConfigServerConfigurationProvider : ConfigurationProvider
|
||||
{
|
||||
|
||||
private static readonly TimeSpan DEFAULT_TIMEOUT = new TimeSpan(0, 0, 5);
|
||||
protected ConfigServerClientSettingsBase _settings;
|
||||
protected ConfigServerClientSettings _settings;
|
||||
protected HttpClient _client;
|
||||
protected ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="ConfigServerConfigurationProvider"/> with default
|
||||
/// configuration settings. <see cref="ConfigServerClientSettings"/>
|
||||
/// <param name="logFactory">optional logging factory</param>
|
||||
/// </summary>
|
||||
public ConfigServerConfigurationProvider(ILoggerFactory logFactory = null) :
|
||||
this(new ConfigServerClientSettings(), logFactory)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="ConfigServerConfigurationProvider"/>.
|
||||
/// </summary>
|
||||
|
@ -47,7 +57,7 @@ namespace Spring.Extensions.Configuration.Common
|
|||
/// accessing the server.</param>
|
||||
/// <param name="logFactory">optional logging factory</param>
|
||||
/// </summary>
|
||||
internal protected ConfigServerConfigurationProviderBase(ConfigServerClientSettingsBase settings, ILoggerFactory logFactory = null) :
|
||||
public ConfigServerConfigurationProvider(ConfigServerClientSettings settings, ILoggerFactory logFactory = null) :
|
||||
this(settings, GetHttpClient(settings), logFactory)
|
||||
{
|
||||
_client.Timeout = DEFAULT_TIMEOUT;
|
||||
|
@ -62,7 +72,7 @@ namespace Spring.Extensions.Configuration.Common
|
|||
/// the server.</param>
|
||||
/// <param name="logFactory">optional logging factory</param>
|
||||
/// </summary>
|
||||
internal protected ConfigServerConfigurationProviderBase(ConfigServerClientSettingsBase settings, HttpClient httpClient, ILoggerFactory logFactory = null)
|
||||
public ConfigServerConfigurationProvider(ConfigServerClientSettings settings, HttpClient httpClient, ILoggerFactory logFactory = null)
|
||||
{
|
||||
if (settings == null)
|
||||
{
|
||||
|
@ -74,19 +84,30 @@ namespace Spring.Extensions.Configuration.Common
|
|||
throw new ArgumentNullException(nameof(httpClient));
|
||||
}
|
||||
|
||||
_logger = logFactory?.CreateLogger<ConfigServerConfigurationProviderBase>();
|
||||
_logger = logFactory?.CreateLogger<ConfigServerConfigurationProvider>();
|
||||
_settings = settings;
|
||||
_client = httpClient;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The configuration settings the provider uses when accessing the server.
|
||||
/// </summary>
|
||||
public virtual ConfigServerClientSettings Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return _settings as ConfigServerClientSettings;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads configuration data from the Spring Cloud Configuration Server as specified by
|
||||
/// the <see cref="Settings"/>
|
||||
/// </summary>
|
||||
public override void Load()
|
||||
{
|
||||
// Adds client settings (e.g spring:cloud:config:uri) to the Data dictionary
|
||||
// Adds client settings (e.g spring:cloud:config:uri, etc) to the Data dictionary
|
||||
AddConfigServerClientSettings();
|
||||
|
||||
Exception error = null;
|
||||
|
@ -100,9 +121,9 @@ namespace Spring.Extensions.Configuration.Common
|
|||
var path = GetConfigServerUri(label);
|
||||
|
||||
// Invoke config server, and wait for results
|
||||
Task<Environment> task = RemoteLoadAsync(path);
|
||||
Task<ConfigEnvironment> task = RemoteLoadAsync(path);
|
||||
task.Wait();
|
||||
Environment env = task.Result;
|
||||
ConfigEnvironment env = task.Result;
|
||||
|
||||
// Update config Data dictionary with any results
|
||||
if (env != null)
|
||||
|
@ -120,7 +141,8 @@ namespace Spring.Extensions.Configuration.Common
|
|||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
error = e;
|
||||
}
|
||||
|
@ -143,7 +165,7 @@ namespace Spring.Extensions.Configuration.Common
|
|||
var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
|
||||
if (!string.IsNullOrEmpty(_settings.Password))
|
||||
{
|
||||
AuthenticationHeaderValue auth = new AuthenticationHeaderValue("Basic",
|
||||
AuthenticationHeaderValue auth = new AuthenticationHeaderValue("Basic",
|
||||
GetEncoded(_settings.Username, _settings.Password));
|
||||
request.Headers.Authorization = auth;
|
||||
}
|
||||
|
@ -173,7 +195,7 @@ namespace Spring.Extensions.Configuration.Common
|
|||
/// </summary>
|
||||
/// <param name="requestUri">the Uri used in accessing the Spring Cloud Configuration Server</param>
|
||||
/// <returns>The task object representing the asynchronous operation</returns>
|
||||
internal protected virtual async Task<Environment> RemoteLoadAsync(string requestUri)
|
||||
internal protected virtual async Task<ConfigEnvironment> RemoteLoadAsync(string requestUri)
|
||||
{
|
||||
// Get the request message
|
||||
var request = GetRequestMessage(requestUri);
|
||||
|
@ -214,7 +236,8 @@ namespace Spring.Extensions.Configuration.Common
|
|||
Stream stream = await response.Content.ReadAsStreamAsync();
|
||||
return Deserialize(stream);
|
||||
}
|
||||
} catch (Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Log and rethrow
|
||||
_logger?.LogError("Config Server exception: {0}, path: {1}", e, requestUri);
|
||||
|
@ -233,16 +256,18 @@ namespace Spring.Extensions.Configuration.Common
|
|||
/// Deserialize the response from the Configuration Server
|
||||
/// </summary>
|
||||
/// <param name="stream">the stream representing the response from the Configuration Server</param>
|
||||
/// <returns>The Environment object representing the response from the server</returns>
|
||||
internal protected virtual Environment Deserialize(Stream stream)
|
||||
/// <returns>The ConfigEnvironment object representing the response from the server</returns>
|
||||
internal protected virtual ConfigEnvironment Deserialize(Stream stream)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
using (JsonReader reader = new JsonTextReader(new StreamReader(stream)))
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
return (Environment)serializer.Deserialize(reader, typeof(Environment));
|
||||
return (ConfigEnvironment)serializer.Deserialize(reader, typeof(ConfigEnvironment));
|
||||
}
|
||||
} catch (Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger?.LogError("Config Server serialization exception", e);
|
||||
}
|
||||
|
@ -276,11 +301,13 @@ namespace Spring.Extensions.Configuration.Common
|
|||
|
||||
foreach (KeyValuePair<string, object> kvp in source.Source)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
string key = kvp.Key.Replace(".", Constants.KeyDelimiter);
|
||||
string value = kvp.Value.ToString();
|
||||
Data[key] = value;
|
||||
} catch (Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger?.LogError("Config Server exception, property: {0}={1}", kvp.Key, kvp.Value.GetType(), e);
|
||||
}
|
||||
|
@ -302,18 +329,19 @@ namespace Spring.Extensions.Configuration.Common
|
|||
return Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + password));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates an appropriatly configured HttpClient that will be used in communicating with the
|
||||
/// Spring Cloud Configuration Server
|
||||
/// </summary>
|
||||
/// <param name="settings">the settings used in configuring the HttpClient</param>
|
||||
/// <returns>The HttpClient used by the provider</returns>
|
||||
protected static HttpClient GetHttpClient(ConfigServerClientSettingsBase settings)
|
||||
protected static HttpClient GetHttpClient(ConfigServerClientSettings settings)
|
||||
{
|
||||
#if NET451
|
||||
return new HttpClient();
|
||||
#else
|
||||
// TODO: For coreclr, disabling certificate validation only works on windows
|
||||
// TODO: For coreclr, disabling certificate validation only works on windows platform
|
||||
// https://github.com/dotnet/corefx/issues/4476
|
||||
if (settings != null && !settings.ValidateCertificates)
|
||||
{
|
||||
|
@ -326,7 +354,6 @@ namespace Spring.Extensions.Configuration.Common
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
internal string[] GetLabels()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_settings.Label))
|
||||
|
@ -355,6 +382,5 @@ namespace Spring.Extensions.Configuration.Common
|
|||
|
||||
private static readonly char[] COMMA_DELIMIT = new char[] { ',' };
|
||||
private static readonly string[] EMPTY_LABELS = new string[] { "" };
|
||||
|
||||
}
|
||||
}
|
|
@ -16,8 +16,11 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer
|
||||
{
|
||||
/// <summary>
|
||||
/// Exception thrown by Config Server client when problems occur
|
||||
/// </summary>
|
||||
public class ConfigServerException : Exception
|
||||
{
|
||||
public ConfigServerException(string message, Exception error) :
|
|
@ -18,8 +18,9 @@ using System;
|
|||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using SteelToe.Extensions.Configuration.ConfigServer;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server
|
||||
namespace SteelToe.Extensions.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for adding services related to Spring Cloud Config Server.
|
||||
|
@ -29,8 +30,8 @@ namespace Spring.Extensions.Configuration.Server
|
|||
/// <summary>
|
||||
/// A convenience extension method that can optionally be used to add Spring Cloud Config Server client services to the
|
||||
/// ServiceCollection. It adds the IOptions service to the IServiceCollection and then configures IOption service
|
||||
/// with the ConfigServerClientSettingsOptions. It also adds the IConfigurationRoot as a service instance to the
|
||||
/// Collection. After a call to this method, you will be able to use the DI mechanism to get access to these components.
|
||||
/// with the ClientSettingsOptions. It also adds the IConfigurationRoot as a service instance to the Collection.
|
||||
/// After a call to this method, you will be able to use the DI mechanism to get access to these components.
|
||||
/// </summary>
|
||||
/// <param name="services">the service collection to add the services to (required)</param>
|
||||
/// <param name="config">the Iconfiguration root (required)</param>
|
|
@ -3,13 +3,13 @@ using Microsoft.Extensions.Configuration;
|
|||
using System;
|
||||
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer
|
||||
{
|
||||
public static class ConfigServerConfigurationSettingsHelper
|
||||
public static class ConfigurationSettingsHelper
|
||||
{
|
||||
private const string SPRING_APPLICATION_PREFIX = "spring:application";
|
||||
|
||||
public static void Initialize(string configPrefix, ConfigServerClientSettingsBase settings, IHostingEnvironment environment, ConfigurationRoot root)
|
||||
public static void Initialize(string configPrefix, ConfigServerClientSettings settings, IHostingEnvironment environment, ConfigurationRoot root)
|
||||
{
|
||||
if (configPrefix == null)
|
||||
{
|
|
@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
|
|||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Spring.Extensions.Configuration.Common")]
|
||||
[assembly: AssemblyTitle("SteelToe.Extensions.Configuration.ConfigServer")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Spring.Extensions.Configuration.Common")]
|
||||
[assembly: AssemblyProduct("SteelToe.Extensions.Configuration.ConfigServer")]
|
||||
[assembly: AssemblyCopyright("Copyright © Original Authors 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
@ -20,8 +20,7 @@ using System.Runtime.InteropServices;
|
|||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("d06283b3-995e-4ac2-b45f-df6a6c377655")]
|
||||
[assembly: Guid("23413532-9d6d-4777-9560-3ebcdec0ac03")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Spring.Extensions.Configuration.Common.Test")]
|
||||
[assembly: InternalsVisibleTo("Spring.Extensions.Configuration.Server.Test")]
|
||||
[assembly: InternalsVisibleTo("Spring.Extensions.Configuration.CloudFoundry.Server.Test")]
|
||||
[assembly: InternalsVisibleTo("SteelToe.Extensions.Configuration.ConfigServer.Test")]
|
||||
[assembly: InternalsVisibleTo("Pivotal.Extensions.Configuration.ConfigServer.Test")]
|
|
@ -21,11 +21,9 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common
|
||||
namespace SteelToe.Extensions.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// TODO: This class obviously needs to move into a common location
|
||||
///
|
||||
/// Utility class for working with configuration values that have placeholders in them.
|
||||
/// A placeholder takes the form of <code ${some:config:reference?default_if_not_present}></code>
|
||||
///
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer
|
||||
{
|
||||
public class PropertySource
|
||||
{
|
|
@ -6,8 +6,8 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>d06283b3-995e-4ac2-b45f-df6a6c377644</ProjectGuid>
|
||||
<RootNamespace>Spring.Extensions.Configuration.Server</RootNamespace>
|
||||
<ProjectGuid>23413532-9d6d-4777-9560-3ebcdec0ac03</ProjectGuid>
|
||||
<RootNamespace>SteelToe.Extensions.Configuration.ConfigServer</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"version": "1.0.7-*",
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"description": "ASP.NET 5 Spring Cloud Config Server Configuration Provider",
|
||||
"authors": [ "Pivotal", "dtillman" ],
|
||||
"tags": [ "CloudFoundry", "ASPNET5", "Spring", "Spring Cloud Services", "Spring Cloud Config Server" ],
|
||||
"tags": [ "ASPNET5", "Spring", "Spring Cloud", "Spring Cloud Config Server" ],
|
||||
"projectUrl": "http://steeltoe.io",
|
||||
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
|
||||
"copyright": "Copyright 2015 the original authors",
|
||||
|
@ -25,7 +25,6 @@
|
|||
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.OptionsModel": "1.0.0-rc1-final",
|
||||
"Newtonsoft.Json": "7.0.1",
|
||||
"Spring.Extensions.Configuration.Common": "1.0.7-*",
|
||||
"System.Net.Http": "4.0.0"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
//
|
||||
// Copyright 2015 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Xunit;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common.Test
|
||||
{
|
||||
public class ConfigServerTestHelpers
|
||||
{
|
||||
public static string CreateTempFile(string contents)
|
||||
{
|
||||
var tempFile = Path.GetTempFileName();
|
||||
File.WriteAllText(tempFile, contents);
|
||||
return tempFile;
|
||||
|
||||
}
|
||||
public static Stream StringToStream(string str)
|
||||
{
|
||||
var memStream = new MemoryStream();
|
||||
var textWriter = new StreamWriter(memStream);
|
||||
textWriter.Write(str);
|
||||
textWriter.Flush();
|
||||
memStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
return memStream;
|
||||
}
|
||||
|
||||
public static string StreamToString(Stream stream)
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
var reader = new StreamReader(stream);
|
||||
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
||||
public static void VerifyDefaults(ConfigServerClientSettingsBase settings)
|
||||
{
|
||||
Assert.False(settings.Enabled);
|
||||
Assert.False(settings.FailFast);
|
||||
Assert.Null(settings.Uri);
|
||||
Assert.Null(settings.Environment);
|
||||
Assert.False(settings.ValidateCertificates);
|
||||
Assert.Null(settings.Name);
|
||||
Assert.Null(settings.Label);
|
||||
Assert.Null(settings.Username);
|
||||
Assert.Null(settings.Password);
|
||||
}
|
||||
}
|
||||
|
||||
public class TestConfigServerStartup
|
||||
{
|
||||
|
||||
private String _response;
|
||||
private int _returnStatus;
|
||||
|
||||
private HttpRequest _request;
|
||||
|
||||
public HttpRequest LastRequest
|
||||
{
|
||||
get
|
||||
{
|
||||
return _request;
|
||||
}
|
||||
}
|
||||
public TestConfigServerStartup(string response) :
|
||||
this(response, 200)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public TestConfigServerStartup(string response, int returnStatus)
|
||||
{
|
||||
_response = response;
|
||||
_returnStatus = returnStatus;
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
_request = context.Request;
|
||||
context.Response.StatusCode = _returnStatus;
|
||||
await context.Response.WriteAsync(_response);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"description": "Unit test project for Spring.Extensions.Configuration.Common",
|
||||
"authors": [ "dtillman" ],
|
||||
"tags": [ "" ],
|
||||
"projectUrl": "",
|
||||
"licenseUrl": "",
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": {
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Hosting": "1.0.0-rc1-final",
|
||||
"Microsoft.AspNet.Http.Abstractions": "1.0.0-rc1-final",
|
||||
"Microsoft.AspNet.TestHost": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration.Ini": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration.Xml": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.OptionsModel": "1.0.0-rc1-final",
|
||||
"Spring.Extensions.Configuration.Common": "1.0.6-*",
|
||||
"xunit": "2.1.0",
|
||||
"xunit.runner.dnx": "2.1.0-rc1-build204"
|
||||
},
|
||||
|
||||
"commands": {
|
||||
"test": "xunit.runner.dnx"
|
||||
}
|
||||
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
//
|
||||
// Copyright 2015 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using Xunit;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.Test
|
||||
{
|
||||
public class ConfigServerConfigurationProviderTest
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public void SettingsConstructor__ThrowsIfSettingsNull()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettings settings = null;
|
||||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => new ConfigServerConfigurationProvider(settings));
|
||||
Assert.Contains(nameof(settings), ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsConstructor__ThrowsIfHttpClientNull()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
HttpClient httpClient = null;
|
||||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => new ConfigServerConfigurationProvider(settings, httpClient));
|
||||
Assert.Contains(nameof(httpClient), ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsConstructor__WithLoggerFactorySucceeds()
|
||||
{
|
||||
// Arrange
|
||||
LoggerFactory logFactory = new LoggerFactory();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
|
||||
// Act and Assert
|
||||
var provider = new ConfigServerConfigurationProvider(settings, logFactory);
|
||||
Assert.NotNull(provider.Logger);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DefaultConstructor_InitializedWithDefaultSettings()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider();
|
||||
|
||||
// Act and Assert
|
||||
ConfigServerTestHelpers.VerifyDefaults(provider.Settings);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
//
|
||||
// Copyright 2015 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace SteelToe.Extensions.Configuration.CloudFoundry.Test
|
||||
{
|
||||
public class CloudFoundryConfigurationBuilderExtensionsTest
|
||||
{
|
||||
[Fact]
|
||||
public void AddCloudFoundry_ThrowsIfConfigBuilderNull()
|
||||
{
|
||||
// Arrange
|
||||
IConfigurationBuilder configurationBuilder = null;
|
||||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => CloudFoundryConfigurationBuilderExtensions.AddCloudFoundry(configurationBuilder));
|
||||
Assert.Contains(nameof(configurationBuilder), ex.Message);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddCloudFoundry_AddsConfigServerProviderToProvidersList()
|
||||
{
|
||||
// Arrange
|
||||
var configurationBuilder = new ConfigurationBuilder();
|
||||
|
||||
// Act and Assert
|
||||
configurationBuilder.AddCloudFoundry();
|
||||
|
||||
CloudFoundryConfigurationProvider cloudProvider = null;
|
||||
foreach (IConfigurationProvider provider in configurationBuilder.Providers)
|
||||
{
|
||||
cloudProvider = provider as CloudFoundryConfigurationProvider;
|
||||
if (cloudProvider != null)
|
||||
break;
|
||||
}
|
||||
Assert.NotNull(cloudProvider);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,379 @@
|
|||
//
|
||||
// Copyright 2015 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
using Xunit;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
|
||||
namespace SteelToe.Extensions.Configuration.CloudFoundry.Test
|
||||
{
|
||||
public class CloudFoundryOptionsTest
|
||||
{
|
||||
[Fact]
|
||||
public void ConfigureCloudFoundryOptions_With_VCAP_APPLICATION_Environment_NotPresent()
|
||||
{
|
||||
// Arrange
|
||||
Environment.SetEnvironmentVariable("VCAP_APPLICATION", null);
|
||||
var services = new ServiceCollection().AddOptions();
|
||||
// Act and Assert
|
||||
|
||||
var builder = new ConfigurationBuilder().AddCloudFoundry();
|
||||
var config = builder.Build();
|
||||
|
||||
services.Configure<CloudFoundryApplicationOptions>(config);
|
||||
var service = services.BuildServiceProvider().GetService<IOptions<CloudFoundryApplicationOptions>>();
|
||||
Assert.NotNull(service);
|
||||
var options = service.Value;
|
||||
|
||||
Assert.Null(options.ApplicationId);
|
||||
Assert.Null(options.ApplicationName);
|
||||
Assert.Null(options.ApplicationUris);
|
||||
Assert.Null(options.ApplicationVersion);
|
||||
Assert.Null(options.InstanceId);
|
||||
Assert.Null(options.Name);
|
||||
Assert.Null(options.SpaceId);
|
||||
Assert.Null(options.SpaceName);
|
||||
Assert.Null(options.Start);
|
||||
Assert.Null(options.Uris);
|
||||
Assert.Equal(-1, options.DiskLimit);
|
||||
Assert.Equal(-1, options.FileDescriptorLimit);
|
||||
Assert.Equal(-1, options.InstanceIndex);
|
||||
Assert.Equal(-1, options.MemoryLimit);
|
||||
Assert.Equal(-1, options.Port);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfigureCloudFoundryOptions_With_VCAP_SERVICES_Environment_NotPresent()
|
||||
{
|
||||
// Arrange
|
||||
Environment.SetEnvironmentVariable("VCAP_SERVICES", null);
|
||||
var services = new ServiceCollection().AddOptions();
|
||||
// Act and Assert
|
||||
|
||||
var builder = new ConfigurationBuilder().AddCloudFoundry();
|
||||
var config = builder.Build();
|
||||
|
||||
services.Configure<CloudFoundryServicesOptions>(config);
|
||||
var service = services.BuildServiceProvider().GetService<IOptions<CloudFoundryServicesOptions>>();
|
||||
Assert.NotNull(service);
|
||||
var options = service.Value;
|
||||
Assert.NotNull(options);
|
||||
Assert.NotNull(options.Services);
|
||||
Assert.Equal(0, options.Services.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfigureCloudFoundryOptions_With_VCAP_APPLICATION_Environment_ConfiguresCloudFoundryApplicationOptions()
|
||||
{
|
||||
// Arrange
|
||||
var environment = @"
|
||||
{
|
||||
|
||||
'application_id': 'fa05c1a9-0fc1-4fbd-bae1-139850dec7a3',
|
||||
'application_name': 'my-app',
|
||||
'application_uris': [
|
||||
'my-app.10.244.0.34.xip.io'
|
||||
],
|
||||
'application_version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca',
|
||||
'limits': {
|
||||
'disk': 1024,
|
||||
'fds': 16384,
|
||||
'mem': 256
|
||||
},
|
||||
'name': 'my-app',
|
||||
'space_id': '06450c72-4669-4dc6-8096-45f9777db68a',
|
||||
'space_name': 'my-space',
|
||||
'uris': [
|
||||
'my-app.10.244.0.34.xip.io',
|
||||
'my-app2.10.244.0.34.xip.io'
|
||||
],
|
||||
'users': null,
|
||||
'version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca'
|
||||
}";
|
||||
|
||||
// Arrange
|
||||
Environment.SetEnvironmentVariable("VCAP_APPLICATION", environment);
|
||||
var services = new ServiceCollection().AddOptions();
|
||||
// Act and Assert
|
||||
|
||||
var builder = new ConfigurationBuilder().AddCloudFoundry();
|
||||
var config = builder.Build();
|
||||
|
||||
services.Configure<CloudFoundryApplicationOptions>(config);
|
||||
var service = services.BuildServiceProvider().GetService<IOptions<CloudFoundryApplicationOptions>>();
|
||||
Assert.NotNull(service);
|
||||
var options = service.Value;
|
||||
Assert.Equal("fa05c1a9-0fc1-4fbd-bae1-139850dec7a3", options.ApplicationId);
|
||||
Assert.Equal("my-app", options.ApplicationName);
|
||||
|
||||
Assert.NotNull(options.ApplicationUris);
|
||||
Assert.Equal(1, options.ApplicationUris.Length);
|
||||
Assert.Equal("my-app.10.244.0.34.xip.io", options.ApplicationUris[0]);
|
||||
|
||||
Assert.Equal("fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca", options.ApplicationVersion);
|
||||
Assert.Equal("my-app", options.Name);
|
||||
Assert.Equal("06450c72-4669-4dc6-8096-45f9777db68a", options.SpaceId);
|
||||
Assert.Equal("my-space", options.SpaceName);
|
||||
|
||||
Assert.NotNull(options.Uris);
|
||||
Assert.Equal(2, options.Uris.Length);
|
||||
Assert.Equal("my-app.10.244.0.34.xip.io", options.Uris[0]);
|
||||
Assert.Equal("my-app2.10.244.0.34.xip.io", options.Uris[1]);
|
||||
|
||||
Assert.Equal("fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca", options.Version);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfigureCloudFoundryOptions_With_VCAP_SERVICES_Environment_ConfiguresCloudFoundryServicesOptions()
|
||||
{
|
||||
// Arrange
|
||||
var environment = @"
|
||||
{
|
||||
'p-config-server': [
|
||||
{
|
||||
'credentials': {
|
||||
'access_token_uri': 'https://p-spring-cloud-services.uaa.wise.com/oauth/token',
|
||||
'client_id': 'p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef',
|
||||
'client_secret': 'e8KF1hXvAnGd',
|
||||
'uri': 'http://localhost:8888'
|
||||
},
|
||||
'label': 'p-config-server',
|
||||
'name': 'My Config Server',
|
||||
'plan': 'standard',
|
||||
'tags': [
|
||||
'configuration',
|
||||
'spring-cloud'
|
||||
]
|
||||
}
|
||||
]
|
||||
}";
|
||||
// Arrange
|
||||
Environment.SetEnvironmentVariable("VCAP_SERVICES", environment);
|
||||
var services = new ServiceCollection().AddOptions();
|
||||
// Act and Assert
|
||||
|
||||
var builder = new ConfigurationBuilder().AddCloudFoundry();
|
||||
var config = builder.Build();
|
||||
|
||||
services.Configure<CloudFoundryServicesOptions>(config);
|
||||
var service = services.BuildServiceProvider().GetService<IOptions<CloudFoundryServicesOptions>>();
|
||||
Assert.NotNull(service);
|
||||
var options = service.Value;
|
||||
Assert.NotNull(options.Services);
|
||||
Assert.Equal(1, options.Services.Count);
|
||||
Assert.Equal("p-config-server", options.Services[0].Label);
|
||||
Assert.Equal("My Config Server", options.Services[0].Name);
|
||||
Assert.Equal("standard", options.Services[0].Plan);
|
||||
|
||||
Assert.NotNull(options.Services[0].Tags);
|
||||
Assert.Equal(2, options.Services[0].Tags.Length);
|
||||
Assert.Equal("configuration", options.Services[0].Tags[0]);
|
||||
Assert.Equal("spring-cloud", options.Services[0].Tags[1]);
|
||||
|
||||
Assert.NotNull(options.Services[0].Credentials);
|
||||
Assert.Equal(4, options.Services[0].Credentials.Count);
|
||||
Assert.Equal("https://p-spring-cloud-services.uaa.wise.com/oauth/token", options.Services[0].Credentials["access_token_uri"].Value);
|
||||
Assert.Equal("p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef", options.Services[0].Credentials["client_id"].Value);
|
||||
Assert.Equal("e8KF1hXvAnGd", options.Services[0].Credentials["client_secret"].Value);
|
||||
Assert.Equal("http://localhost:8888", options.Services[0].Credentials["uri"].Value);
|
||||
}
|
||||
[Fact]
|
||||
public void ConfigureCloudFoundryOptions_With_Complex_VCAP_SERVICES_Environment_ConfiguresCloudFoundryServicesOptions()
|
||||
{
|
||||
// Arrange
|
||||
var environment = @"
|
||||
{
|
||||
'p-rabbitmq': [
|
||||
{
|
||||
'name': 'rabbitmq',
|
||||
'label': 'p-rabbitmq',
|
||||
'tags': [
|
||||
'rabbitmq',
|
||||
'messaging',
|
||||
'message-queue',
|
||||
'amqp',
|
||||
'stomp',
|
||||
'mqtt',
|
||||
'pivotal'
|
||||
],
|
||||
'plan': 'standard',
|
||||
'credentials': {
|
||||
'http_api_uris': [
|
||||
'https://268371bd-07e5-46f3-aec7-d1633ae20bbb:3fnpvbqm0djq5jl9fp6fc697f4@pivotal-rabbitmq.system.testcloud.com/api/'
|
||||
],
|
||||
'ssl': false,
|
||||
'dashboard_url': 'https://pivotal-rabbitmq.system.testcloud.com/#/login/268371bd-07e5-46f3-aec7-d1633ae20bbb/3fnpvbqm0djq5jl9fp6fc697f4',
|
||||
'password': '3fnpvbqm0djq5jl9fp6fc697f4',
|
||||
'protocols': {
|
||||
'management': {
|
||||
'path': '/api/',
|
||||
'ssl': false,
|
||||
'hosts': [
|
||||
'192.168.0.97'
|
||||
],
|
||||
'password': '3fnpvbqm0djq5jl9fp6fc697f4',
|
||||
'username': '268371bd-07e5-46f3-aec7-d1633ae20bbb',
|
||||
'port': 15672,
|
||||
'host': '192.168.0.97',
|
||||
'uri': 'http://268371bd-07e5-46f3-aec7-d1633ae20bbb:3fnpvbqm0djq5jl9fp6fc697f4@192.168.0.97:15672/api/',
|
||||
'uris': [
|
||||
'http://268371bd-07e5-46f3-aec7-d1633ae20bbb:3fnpvbqm0djq5jl9fp6fc697f4@192.168.0.97:15672/api/'
|
||||
]
|
||||
},
|
||||
'amqp': {
|
||||
'vhost': '2260a117-cf28-4725-86dd-37b3b8971052',
|
||||
'username': '268371bd-07e5-46f3-aec7-d1633ae20bbb',
|
||||
'password': '3fnpvbqm0djq5jl9fp6fc697f4',
|
||||
'port': 5672,
|
||||
'host': '192.168.0.97',
|
||||
'hosts': [
|
||||
'192.168.0.97'
|
||||
],
|
||||
'ssl': false,
|
||||
'uri': 'amqp://268371bd-07e5-46f3-aec7-d1633ae20bbb:3fnpvbqm0djq5jl9fp6fc697f4@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052',
|
||||
'uris': [
|
||||
'amqp://268371bd-07e5-46f3-aec7-d1633ae20bbb:3fnpvbqm0djq5jl9fp6fc697f4@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052'
|
||||
]
|
||||
}
|
||||
},
|
||||
'username': '268371bd-07e5-46f3-aec7-d1633ae20bbb',
|
||||
'hostname': '192.168.0.97',
|
||||
'hostnames': [
|
||||
'192.168.0.97'
|
||||
],
|
||||
'vhost': '2260a117-cf28-4725-86dd-37b3b8971052',
|
||||
'http_api_uri': 'https://268371bd-07e5-46f3-aec7-d1633ae20bbb:3fnpvbqm0djq5jl9fp6fc697f4@pivotal-rabbitmq.system.testcloud.com/api/',
|
||||
'uri': 'amqp://268371bd-07e5-46f3-aec7-d1633ae20bbb:3fnpvbqm0djq5jl9fp6fc697f4@192.168.0.97/2260a117-cf28-4725-86dd-37b3b8971052',
|
||||
'uris': [
|
||||
'amqp://268371bd-07e5-46f3-aec7-d1633ae20bbb:3fnpvbqm0djq5jl9fp6fc697f4@192.168.0.97/2260a117-cf28-4725-86dd-37b3b8971052'
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}";
|
||||
// Arrange
|
||||
Environment.SetEnvironmentVariable("VCAP_SERVICES", environment);
|
||||
var services = new ServiceCollection().AddOptions();
|
||||
// Act and Assert
|
||||
|
||||
var builder = new ConfigurationBuilder().AddCloudFoundry();
|
||||
var config = builder.Build();
|
||||
|
||||
services.Configure<CloudFoundryServicesOptions>(config);
|
||||
var service = services.BuildServiceProvider().GetService<IOptions<CloudFoundryServicesOptions>>();
|
||||
Assert.NotNull(service);
|
||||
var options = service.Value;
|
||||
Assert.NotNull(options.Services);
|
||||
Assert.Equal(1, options.Services.Count);
|
||||
Assert.Equal("p-rabbitmq", options.Services[0].Label);
|
||||
Assert.Equal("rabbitmq", options.Services[0].Name);
|
||||
Assert.Equal("standard", options.Services[0].Plan);
|
||||
|
||||
Assert.NotNull(options.Services[0].Tags);
|
||||
Assert.Equal(7, options.Services[0].Tags.Length);
|
||||
Assert.Equal("rabbitmq", options.Services[0].Tags[0]);
|
||||
Assert.Equal("pivotal", options.Services[0].Tags[6]);
|
||||
|
||||
Assert.NotNull(options.Services[0].Credentials);
|
||||
Assert.Equal(12, options.Services[0].Credentials.Count);
|
||||
Assert.Equal("https://pivotal-rabbitmq.system.testcloud.com/#/login/268371bd-07e5-46f3-aec7-d1633ae20bbb/3fnpvbqm0djq5jl9fp6fc697f4", options.Services[0].Credentials["dashboard_url"].Value);
|
||||
Assert.Equal("268371bd-07e5-46f3-aec7-d1633ae20bbb", options.Services[0].Credentials["username"].Value);
|
||||
Assert.Equal("3fnpvbqm0djq5jl9fp6fc697f4", options.Services[0].Credentials["password"].Value);
|
||||
Assert.Equal("268371bd-07e5-46f3-aec7-d1633ae20bbb", options.Services[0].Credentials["protocols"]["amqp"]["username"].Value);
|
||||
Assert.Equal("3fnpvbqm0djq5jl9fp6fc697f4", options.Services[0].Credentials["protocols"]["amqp"]["password"].Value);
|
||||
Assert.Equal("amqp://268371bd-07e5-46f3-aec7-d1633ae20bbb:3fnpvbqm0djq5jl9fp6fc697f4@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052",
|
||||
options.Services[0].Credentials["protocols"]["amqp"]["uris"]["0"].Value);
|
||||
|
||||
//}
|
||||
}
|
||||
[Fact]
|
||||
public void ConfigureCloudFoundryOptions_With_MultipleOfSame_VCAP_SERVICES_Environment_ConfiguresCloudFoundryServicesOptions()
|
||||
{
|
||||
// Arrange
|
||||
var environment = @"
|
||||
{
|
||||
'p-mysql': [
|
||||
{
|
||||
'name': 'mySql1',
|
||||
'label': 'p-mysql',
|
||||
'tags': [
|
||||
'mysql',
|
||||
'relational'
|
||||
],
|
||||
'plan': '100mb-dev',
|
||||
'credentials': {
|
||||
'hostname': '192.168.0.97',
|
||||
'port': 3306,
|
||||
'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31',
|
||||
'username': '9vD0Mtk3wFFuaaaY',
|
||||
'password': 'Cjn4HsAiKV8sImst',
|
||||
'uri': 'mysql://9vD0Mtk3wFFuaaaY:Cjn4HsAiKV8sImst@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true',
|
||||
'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'mySql2',
|
||||
'label': 'p-mysql',
|
||||
'tags': [
|
||||
'mysql',
|
||||
'relational'
|
||||
],
|
||||
'plan': '100mb-dev',
|
||||
'credentials': {
|
||||
'hostname': '192.168.0.97',
|
||||
'port': 3306,
|
||||
'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31',
|
||||
'username': '9vD0Mtk3wFFuaaaY',
|
||||
'password': 'Cjn4HsAiKV8sImst',
|
||||
'uri': 'mysql://9vD0Mtk3wFFuaaaY:Cjn4HsAiKV8sImst@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true',
|
||||
'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst'
|
||||
}
|
||||
}
|
||||
]
|
||||
}";
|
||||
// Arrange
|
||||
Environment.SetEnvironmentVariable("VCAP_SERVICES", environment);
|
||||
var services = new ServiceCollection().AddOptions();
|
||||
// Act and Assert
|
||||
|
||||
var builder = new ConfigurationBuilder().AddCloudFoundry();
|
||||
var config = builder.Build();
|
||||
|
||||
services.Configure<CloudFoundryServicesOptions>(config);
|
||||
var service = services.BuildServiceProvider().GetService<IOptions<CloudFoundryServicesOptions>>();
|
||||
Assert.NotNull(service);
|
||||
var options = service.Value;
|
||||
Assert.NotNull(options.Services);
|
||||
Assert.Equal(2, options.Services.Count);
|
||||
|
||||
Assert.Equal("p-mysql", options.Services[0].Label);
|
||||
Assert.Equal("p-mysql", options.Services[1].Label);
|
||||
|
||||
Assert.True(options.Services[0].Name.Equals("mySql1") || options.Services[0].Name.Equals("mySql2"));
|
||||
Assert.True(options.Services[1].Name.Equals("mySql1") || options.Services[1].Name.Equals("mySql2"));
|
||||
|
||||
Assert.Equal("192.168.0.97", options.Services[0].Credentials["hostname"].Value);
|
||||
Assert.Equal("192.168.0.97", options.Services[1].Credentials["hostname"].Value);
|
||||
Assert.Equal("3306", options.Services[0].Credentials["port"].Value);
|
||||
Assert.Equal("cf_0f5dda44_e678_4727_993f_30e6d455cc31", options.Services[0].Credentials["name"].Value);
|
||||
Assert.Equal("cf_0f5dda44_e678_4727_993f_30e6d455cc31", options.Services[1].Credentials["name"].Value);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using System;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace SteelToe.Extensions.Configuration.CloudFoundry.Test
|
||||
{
|
||||
public class CloudFoundryServiceCollectionExtensionsTest
|
||||
{
|
||||
[Fact]
|
||||
public void AddCloudFoundry_ThrowsIfServiceCollectionNull()
|
||||
{
|
||||
// Arrange
|
||||
IServiceCollection services = null;
|
||||
IConfigurationRoot config = null;
|
||||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => CloudFoundryServiceCollectionExtensions.AddCloudFoundry(services, config));
|
||||
Assert.Contains(nameof(services), ex.Message);
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void AddCloudFoundry_ThrowsIfConfigurtionNull()
|
||||
{
|
||||
// Arrange
|
||||
IServiceCollection services = new ServiceCollection();
|
||||
IConfigurationRoot config = null;
|
||||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => CloudFoundryServiceCollectionExtensions.AddCloudFoundry(services, config));
|
||||
Assert.Contains(nameof(config), ex.Message);
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void AddCloudFoundry_ConfiguresCloudFoundryOptions()
|
||||
{
|
||||
// Arrange
|
||||
var services = new ServiceCollection();
|
||||
|
||||
// Act and Assert
|
||||
var builder = new ConfigurationBuilder().AddCloudFoundry();
|
||||
var config = builder.Build();
|
||||
CloudFoundryServiceCollectionExtensions.AddCloudFoundry(services, config);
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var app = serviceProvider.GetService<IOptions<CloudFoundryApplicationOptions>>();
|
||||
Assert.NotNull(app);
|
||||
var service = serviceProvider.GetService<IOptions<CloudFoundryServicesOptions>>();
|
||||
Assert.NotNull(service);
|
||||
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void AddCloudFoundry_AddsConfigurationAsService()
|
||||
{
|
||||
// Arrange
|
||||
var services = new ServiceCollection();
|
||||
|
||||
// Act and Assert
|
||||
var builder = new ConfigurationBuilder().AddCloudFoundry();
|
||||
var config = builder.Build();
|
||||
CloudFoundryServiceCollectionExtensions.AddCloudFoundry(services, config);
|
||||
|
||||
var service = services.BuildServiceProvider().GetService<IConfigurationRoot>();
|
||||
Assert.NotNull(service);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,218 @@
|
|||
//
|
||||
// Copyright 2015 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace SteelToe.Extensions.Configuration.CloudFoundry.Test
|
||||
{
|
||||
public class CloudFoundryConfigurationProviderTest
|
||||
{
|
||||
public CloudFoundryConfigurationProviderTest()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Load_VCAP_APPLICATION_ChangesDataDictionary()
|
||||
{
|
||||
// Arrange
|
||||
var environment = @"
|
||||
{
|
||||
|
||||
'application_id': 'fa05c1a9-0fc1-4fbd-bae1-139850dec7a3',
|
||||
'application_name': 'my-app',
|
||||
'application_uris': [
|
||||
'my-app.10.244.0.34.xip.io'
|
||||
],
|
||||
'application_version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca',
|
||||
'limits': {
|
||||
'disk': 1024,
|
||||
'fds': 16384,
|
||||
'mem': 256
|
||||
},
|
||||
'name': 'my-app',
|
||||
'space_id': '06450c72-4669-4dc6-8096-45f9777db68a',
|
||||
'space_name': 'my-space',
|
||||
'uris': [
|
||||
'my-app.10.244.0.34.xip.io',
|
||||
'my-app2.10.244.0.34.xip.io'
|
||||
],
|
||||
'users': null,
|
||||
'version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca'
|
||||
}";
|
||||
|
||||
Environment.SetEnvironmentVariable("VCAP_APPLICATION", environment);
|
||||
var provider = new CloudFoundryConfigurationProvider();
|
||||
|
||||
// Act and Assert
|
||||
provider.Load();
|
||||
IDictionary<string, string> dict = provider.Properties;
|
||||
Assert.Equal("fa05c1a9-0fc1-4fbd-bae1-139850dec7a3", dict["vcap:application:application_id"]);
|
||||
Assert.Equal("1024", dict["vcap:application:limits:disk"]);
|
||||
Assert.Equal("my-app.10.244.0.34.xip.io", dict["vcap:application:uris:0"]);
|
||||
Assert.Equal("my-app2.10.244.0.34.xip.io", dict["vcap:application:uris:1"]);
|
||||
|
||||
Assert.Equal("my-app", dict["spring:application:name"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Load_VCAP_SERVICES_ChangesDataDictionary()
|
||||
{
|
||||
var environment = @"
|
||||
{
|
||||
'elephantsql': [
|
||||
{
|
||||
'name': 'elephantsql-c6c60',
|
||||
'label': 'elephantsql',
|
||||
'tags': [
|
||||
'postgres',
|
||||
'postgresql',
|
||||
'relational'
|
||||
],
|
||||
'plan': 'turtle',
|
||||
'credentials': {
|
||||
'uri': 'postgres://seilbmbd:ABcdEF@babar.elephantsql.com:5432/seilbmbd'
|
||||
}
|
||||
}
|
||||
],
|
||||
'sendgrid': [
|
||||
{
|
||||
'name': 'mysendgrid',
|
||||
'label': 'sendgrid',
|
||||
'tags': [
|
||||
'smtp'
|
||||
],
|
||||
'plan': 'free',
|
||||
'credentials': {
|
||||
'hostname': 'smtp.sendgrid.net',
|
||||
'username': 'QvsXMbJ3rK',
|
||||
'password': 'HCHMOYluTv'
|
||||
}
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
|
||||
Environment.SetEnvironmentVariable("VCAP_SERVICES", environment);
|
||||
var provider = new CloudFoundryConfigurationProvider();
|
||||
|
||||
// Act and Assert
|
||||
provider.Load();
|
||||
IDictionary<string, string> dict = provider.Properties;
|
||||
Assert.Equal("elephantsql-c6c60", dict["vcap:services:elephantsql:0:name"]);
|
||||
Assert.Equal("mysendgrid", dict["vcap:services:sendgrid:0:name"]);
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void Load_VCAP_SERVICES_MultiServices_ChangesDataDictionary()
|
||||
{
|
||||
var environment = @"
|
||||
{
|
||||
'p-config-server': [
|
||||
{
|
||||
'name': 'myConfigServer',
|
||||
'label': 'p-config-server',
|
||||
'tags': [
|
||||
'configuration',
|
||||
'spring-cloud'
|
||||
],
|
||||
'plan': 'standard',
|
||||
'credentials': {
|
||||
'uri': 'https://config-eafc353b-77e2-4dcc-b52a-25777e996ed9.apps.testcloud.com',
|
||||
'client_id': 'p-config-server-9bff4c87-7ffd-4536-9e76-e67ea3ec81d0',
|
||||
'client_secret': 'AJUAjyxP3nO9',
|
||||
'access_token_uri': 'https://p-spring-cloud-services.uaa.system.testcloud.com/oauth/token'
|
||||
}
|
||||
}
|
||||
],
|
||||
'p-service-registry': [
|
||||
{
|
||||
'name': 'myServiceRegistry',
|
||||
'label': 'p-service-registry',
|
||||
'tags': [
|
||||
'eureka',
|
||||
'discovery',
|
||||
'registry',
|
||||
'spring-cloud'
|
||||
],
|
||||
'plan': 'standard',
|
||||
'credentials': {
|
||||
'uri': 'https://eureka-f4b98d1c-3166-4741-b691-79abba5b2d51.apps.testcloud.com',
|
||||
'client_id': 'p-service-registry-9121b185-cd3b-497c-99f7-8e8064d4a6f0',
|
||||
'client_secret': '3Rv1U79siLDa',
|
||||
'access_token_uri': 'https://p-spring-cloud-services.uaa.system.testcloud.com/oauth/token'
|
||||
}
|
||||
}
|
||||
],
|
||||
'p-mysql': [
|
||||
{
|
||||
'name': 'mySql1',
|
||||
'label': 'p-mysql',
|
||||
'tags': [
|
||||
'mysql',
|
||||
'relational'
|
||||
],
|
||||
'plan': '100mb-dev',
|
||||
'credentials': {
|
||||
'hostname': '192.168.0.97',
|
||||
'port': 3306,
|
||||
'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31',
|
||||
'username': '9vD0Mtk3wFFuaaaY',
|
||||
'password': 'Cjn4HsAiKV8sImst',
|
||||
'uri': 'mysql://9vD0Mtk3wFFuaaaY:Cjn4HsAiKV8sImst@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true',
|
||||
'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'mySql2',
|
||||
'label': 'p-mysql',
|
||||
'tags': [
|
||||
'mysql',
|
||||
'relational'
|
||||
],
|
||||
'plan': '100mb-dev',
|
||||
'credentials': {
|
||||
'hostname': '192.168.0.97',
|
||||
'port': 3306,
|
||||
'name': 'cf_b2d83697_5fa1_4a51_991b_975c9d7e5515',
|
||||
'username': 'gxXQb2pMbzFsZQW8',
|
||||
'password': 'lvMkGf6oJQvKSOwn',
|
||||
'uri': 'mysql://gxXQb2pMbzFsZQW8:lvMkGf6oJQvKSOwn@192.168.0.97:3306/cf_b2d83697_5fa1_4a51_991b_975c9d7e5515?reconnect=true',
|
||||
'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_b2d83697_5fa1_4a51_991b_975c9d7e5515?user=gxXQb2pMbzFsZQW8&password=lvMkGf6oJQvKSOwn'
|
||||
}
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
Environment.SetEnvironmentVariable("VCAP_SERVICES", environment);
|
||||
var provider = new CloudFoundryConfigurationProvider();
|
||||
|
||||
// Act and Assert
|
||||
provider.Load();
|
||||
IDictionary<string, string> dict = provider.Properties;
|
||||
Assert.Equal("myConfigServer", dict["vcap:services:p-config-server:0:name"]);
|
||||
Assert.Equal("https://config-eafc353b-77e2-4dcc-b52a-25777e996ed9.apps.testcloud.com", dict["vcap:services:p-config-server:0:credentials:uri"]);
|
||||
Assert.Equal("myServiceRegistry", dict["vcap:services:p-service-registry:0:name"]);
|
||||
Assert.Equal("https://eureka-f4b98d1c-3166-4741-b691-79abba5b2d51.apps.testcloud.com", dict["vcap:services:p-service-registry:0:credentials:uri"]);
|
||||
Assert.Equal("mySql1", dict["vcap:services:p-mysql:0:name"]);
|
||||
Assert.Equal("mysql://9vD0Mtk3wFFuaaaY:Cjn4HsAiKV8sImst@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true", dict["vcap:services:p-mysql:0:credentials:uri"]);
|
||||
Assert.Equal("mySql2", dict["vcap:services:p-mysql:1:name"]);
|
||||
Assert.Equal("mysql://gxXQb2pMbzFsZQW8:lvMkGf6oJQvKSOwn@192.168.0.97:3306/cf_b2d83697_5fa1_4a51_991b_975c9d7e5515?reconnect=true", dict["vcap:services:p-mysql:1:credentials:uri"]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
|
|||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Spring.Extensions.Configuration.Server.Test")]
|
||||
[assembly: AssemblyTitle("SteelToe.Extensions.Configuration.CloudFoundry.Test")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Spring.Extensions.Configuration.Server.Test")]
|
||||
[assembly: AssemblyProduct("SteelToe.Extensions.Configuration.CloudFoundry.Test")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
@ -20,4 +20,4 @@ using System.Runtime.InteropServices;
|
|||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("eccb52be-a124-4213-95a3-0c4842aa55a1")]
|
||||
[assembly: Guid("6c872c62-7b97-43c7-827c-5ab8b3d7ba41")]
|
|
@ -6,8 +6,8 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>eccb52be-a124-4213-95a3-0c4842aa55a1</ProjectGuid>
|
||||
<RootNamespace>Spring.Extensions.Configuration.Server.Test</RootNamespace>
|
||||
<ProjectGuid>6c872c62-7b97-43c7-827c-5ab8b3d7ba41</ProjectGuid>
|
||||
<RootNamespace>SteelToe.Extensions.Configuration.CloudFoundry.Test</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"description": "Unit test project for SteelToe.Extensions.Configuration.CloudFoundry",
|
||||
"authors": [ "Pivotal", "dtillman" ],
|
||||
"tags": [ "ASPNET5", "Spring", "Spring Cloud", "Spring Cloud Config Server" ],
|
||||
"projectUrl": "http://steeltoe.io",
|
||||
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
|
||||
"copyright": "Copyright 2015 the original authors",
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": {
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Hosting": "1.0.0-rc1-final",
|
||||
"Microsoft.AspNet.Http.Abstractions": "1.0.0-rc1-final",
|
||||
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
|
||||
"Microsoft.AspNet.TestHost": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Configuration": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.OptionsModel": "1.0.0-rc1-final",
|
||||
"SteelToe.Extensions.Configuration.CloudFoundry": "1.0.0-*",
|
||||
"xunit": "2.1.0",
|
||||
"xunit.runner.dnx": "2.1.0-rc1-build204"
|
||||
},
|
||||
|
||||
"commands": {
|
||||
"test": "xunit.runner.dnx"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -14,14 +14,15 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
|
||||
using Spring.Extensions.Configuration.Server.Test;
|
||||
|
||||
using Xunit;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using SteelToe.Extensions.Configuration.ConfigServer.Test;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.ITest
|
||||
{
|
||||
//
|
||||
// NOTE: Some of the tests assume a running Spring Cloud Config Server is started
|
||||
|
@ -60,7 +61,7 @@ namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
|||
}
|
||||
}";
|
||||
|
||||
var path = ConfigServerTestHelpers.CreateTempFile(appsettings);
|
||||
var path = TestHelpers.CreateTempFile(appsettings);
|
||||
var configurationBuilder = new ConfigurationBuilder();
|
||||
var hostingEnv = new HostingEnvironment();
|
||||
configurationBuilder.AddJsonFile(path);
|
|
@ -14,12 +14,7 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.ITest
|
||||
{
|
||||
public class ConfigServerDataAsOptions
|
||||
{
|
|
@ -21,7 +21,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.ITest
|
||||
{
|
||||
|
||||
public class HomeController : Controller
|
|
@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
|
|||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Spring.Extensions.Configuration.Server.IntegrationTest")]
|
||||
[assembly: AssemblyTitle("SteelToe.Extensions.Configuration.ConfigServer.ITest")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Spring.Extensions.Configuration.Server.IntegrationTest")]
|
||||
[assembly: AssemblyProduct("SteelToe.Extensions.Configuration.ConfigServer.ITest")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
@ -20,4 +20,4 @@ using System.Runtime.InteropServices;
|
|||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("8d43b1b0-0c20-4aa5-b510-332e1190d0c3")]
|
||||
[assembly: Guid("3d9b0677-d184-4e30-8503-c9f291fa1335")]
|
|
@ -6,8 +6,8 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>8d43b1b0-0c20-4aa5-b510-332e1190d0c3</ProjectGuid>
|
||||
<RootNamespace>Spring.Extensions.Configuration.Server.IntegrationTest</RootNamespace>
|
||||
<ProjectGuid>3d9b0677-d184-4e30-8503-c9f291fa1335</ProjectGuid>
|
||||
<RootNamespace>SteelToe.Extensions.Configuration.ConfigServer.ITest</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
|
@ -16,16 +16,11 @@
|
|||
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spring.Extensions.Configuration.Server.Test;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using SteelToe.Extensions.Configuration.ConfigServer.Test;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.ITest
|
||||
{
|
||||
class TestServerStartup
|
||||
{
|
||||
|
@ -49,7 +44,7 @@ namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
|||
}
|
||||
}
|
||||
}";
|
||||
var path = ConfigServerTestHelpers.CreateTempFile(appsettings);
|
||||
var path = TestHelpers.CreateTempFile(appsettings);
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile(path)
|
||||
.AddConfigServer(environment);
|
|
@ -1,10 +1,11 @@
|
|||
{
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"description": "Integration test project for Spring.Extensions.Configuration.Server",
|
||||
"authors": [ "dtillman" ],
|
||||
"tags": [ "" ],
|
||||
"projectUrl": "",
|
||||
"licenseUrl": "",
|
||||
"description": "Integration test project for SteelToe.Extensions.Configuration.ConfigServer",
|
||||
"authors": [ "Pivotal", "dtillman" ],
|
||||
"tags": [ "ASPNET5", "Spring", "Spring Cloud", "Spring Cloud Config Server" ],
|
||||
"projectUrl": "http://steeltoe.io",
|
||||
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
|
||||
"copyright": "Copyright 2015 the original authors",
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": {
|
||||
|
@ -20,8 +21,8 @@
|
|||
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
|
||||
"Spring.Extensions.Configuration.Server": "1.0.7-*",
|
||||
"Spring.Extensions.Configuration.Server.Test": "1.0.0-*",
|
||||
"SteelToe.Extensions.Configuration.ConfigServer": "1.0.0-*",
|
||||
"SteelToe.Extensions.Configuration.ConfigServer.Test": "1.0.0-*",
|
||||
"xunit": "2.1.0",
|
||||
"xunit.runner.dnx": "2.1.0-rc1-build204"
|
||||
},
|
||||
|
@ -29,3 +30,6 @@
|
|||
"test": "xunit.runner.dnx"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Microsoft.Extensions.OptionsModel;
|
||||
using Xunit;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.Test
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.Test
|
||||
{
|
||||
public class ConfigServerClientSettingsOptionsTest
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ namespace Spring.Extensions.Configuration.Server.Test
|
|||
Assert.NotNull(service);
|
||||
var options = service.Value;
|
||||
Assert.NotNull(options);
|
||||
ConfigServerTestHelpers.VerifyDefaults(options.Settings);
|
||||
TestHelpers.VerifyDefaults(options.Settings);
|
||||
|
||||
Assert.Equal(ConfigServerClientSettings.DEFAULT_PROVIDER_ENABLED, options.Enabled);
|
||||
Assert.Equal(ConfigServerClientSettings.DEFAULT_FAILFAST, options.FailFast);
|
|
@ -16,19 +16,18 @@
|
|||
|
||||
using Xunit;
|
||||
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common.Test
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.Test
|
||||
{
|
||||
public class ConfigServerClientSettingsBaseTest
|
||||
public class ConfigServerClientSettingsTest
|
||||
{
|
||||
[Fact]
|
||||
public void DefaultConstructor_InitializedWithDefaults()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
|
||||
// Act and Assert
|
||||
ConfigServerTestHelpers.VerifyDefaults(settings);
|
||||
TestHelpers.VerifyDefaults(settings);
|
||||
|
||||
}
|
||||
|
||||
|
@ -36,17 +35,17 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public void GetRawUri_GoodWithUserPass()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase() { Uri = "https://user:pass@localhost:8888/" };
|
||||
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings() { Uri = "https://user:pass@localhost:8888/" };
|
||||
|
||||
// Act and Assert
|
||||
Assert.Equal("https://localhost:8888/", settings.RawUri);
|
||||
Assert.Equal("https://localhost:8888/", settings.RawUri);
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void GetRawUri_Bad()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase() { Uri = "blahblah" };
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings() { Uri = "blahblah" };
|
||||
|
||||
// Act and Assert
|
||||
Assert.Equal("blahblah", settings.RawUri);
|
||||
|
@ -56,7 +55,7 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public void GetUserName_GoodWithUserPassOnUri()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase() { Uri = "https://user:pass@localhost:8888/" };
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings() { Uri = "https://user:pass@localhost:8888/" };
|
||||
|
||||
// Act and Assert
|
||||
Assert.Equal("user", settings.Username);
|
||||
|
@ -66,7 +65,7 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public void GetPassword_GoodWithUserPassOnUri()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase() { Uri = "https://user:pass@localhost:8888/" };
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings() { Uri = "https://user:pass@localhost:8888/" };
|
||||
|
||||
// Act and Assert
|
||||
Assert.Equal("pass", settings.Password);
|
||||
|
@ -76,7 +75,7 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public void GetUserName_GoodWithUserPassOnUri_SettingsOverrides()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase() { Uri = "https://user:pass@localhost:8888/", Username = "explicitOverrides" };
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings() { Uri = "https://user:pass@localhost:8888/", Username = "explicitOverrides" };
|
||||
|
||||
// Act and Assert
|
||||
Assert.Equal("explicitOverrides", settings.Username);
|
||||
|
@ -87,7 +86,7 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public void GetPassword_GoodWithUserPassOnUri_SettingsOverrides()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase() { Uri = "https://user:pass@localhost:8888/" , Password = "explicitOverrides" };
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings() { Uri = "https://user:pass@localhost:8888/", Password = "explicitOverrides" };
|
||||
|
||||
// Act and Assert
|
||||
Assert.Equal("explicitOverrides", settings.Password);
|
||||
|
@ -95,6 +94,7 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -19,11 +19,10 @@ using Xunit;
|
|||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.Extensions.Configuration.Xml;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.Test
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.Test
|
||||
{
|
||||
public class ConfigServerConfigurationExtensionsTest
|
||||
public class ConfigServerConfigurationBuilderExtensionsTest
|
||||
{
|
||||
[Fact]
|
||||
public void AddConfigServer_ThrowsIfConfigBuilderNull()
|
||||
|
@ -33,7 +32,7 @@ namespace Spring.Extensions.Configuration.Server.Test
|
|||
var environment = new HostingEnvironment();
|
||||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => ConfigServerConfigurationExtensions.AddConfigServer(configurationBuilder, environment));
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => ConfigServerConfigurationBuilderExtensions.AddConfigServer(configurationBuilder, environment));
|
||||
Assert.Contains(nameof(configurationBuilder), ex.Message);
|
||||
|
||||
}
|
||||
|
@ -45,7 +44,7 @@ namespace Spring.Extensions.Configuration.Server.Test
|
|||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
|
||||
IHostingEnvironment environment = null;
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => ConfigServerConfigurationExtensions.AddConfigServer(configurationBuilder, environment));
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => ConfigServerConfigurationBuilderExtensions.AddConfigServer(configurationBuilder, environment));
|
||||
Assert.Contains(nameof(environment), ex.Message);
|
||||
|
||||
}
|
||||
|
@ -118,7 +117,7 @@ namespace Spring.Extensions.Configuration.Server.Test
|
|||
}
|
||||
}";
|
||||
|
||||
var path = ConfigServerTestHelpers.CreateTempFile(appsettings);
|
||||
var path = TestHelpers.CreateTempFile(appsettings);
|
||||
var configurationBuilder = new ConfigurationBuilder();
|
||||
var environment = new HostingEnvironment();
|
||||
configurationBuilder.AddJsonFile(path);
|
||||
|
@ -167,7 +166,7 @@ namespace Spring.Extensions.Configuration.Server.Test
|
|||
</cloud>
|
||||
</spring>
|
||||
</settings>";
|
||||
var path = ConfigServerTestHelpers.CreateTempFile(appsettings);
|
||||
var path = TestHelpers.CreateTempFile(appsettings);
|
||||
var configurationBuilder = new ConfigurationBuilder();
|
||||
var environment = new HostingEnvironment();
|
||||
configurationBuilder.AddXmlFile(path);
|
||||
|
@ -210,7 +209,7 @@ namespace Spring.Extensions.Configuration.Server.Test
|
|||
username=myUsername
|
||||
password=myPassword
|
||||
";
|
||||
var path = ConfigServerTestHelpers.CreateTempFile(appsettings);
|
||||
var path = TestHelpers.CreateTempFile(appsettings);
|
||||
var configurationBuilder = new ConfigurationBuilder();
|
||||
var environment = new HostingEnvironment();
|
||||
configurationBuilder.AddIniFile(path);
|
||||
|
@ -314,7 +313,7 @@ namespace Spring.Extensions.Configuration.Server.Test
|
|||
}
|
||||
}";
|
||||
|
||||
var path = ConfigServerTestHelpers.CreateTempFile(appsettings);
|
||||
var path = TestHelpers.CreateTempFile(appsettings);
|
||||
var configurationBuilder = new ConfigurationBuilder();
|
||||
var environment = new HostingEnvironment();
|
||||
configurationBuilder.AddJsonFile(path);
|
|
@ -23,19 +23,19 @@ using Xunit;
|
|||
using System.IO;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common.Test
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.Test
|
||||
{
|
||||
public class ConfigServerConfigurationProviderBaseTest
|
||||
public class ConfigServerConfigurationProviderTest
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public void SettingsConstructor__ThrowsIfSettingsNull()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = null;
|
||||
ConfigServerClientSettings settings = null;
|
||||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => new ConfigServerConfigurationProviderBase(settings));
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => new ConfigServerConfigurationProvider(settings));
|
||||
Assert.Contains(nameof(settings), ex.Message);
|
||||
}
|
||||
|
||||
|
@ -43,11 +43,11 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public void SettingsConstructor__ThrowsIfHttpClientNull()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
HttpClient httpClient = null;
|
||||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => new ConfigServerConfigurationProviderBase(settings, httpClient));
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => new ConfigServerConfigurationProvider(settings, httpClient));
|
||||
Assert.Contains(nameof(httpClient), ex.Message);
|
||||
}
|
||||
|
||||
|
@ -56,20 +56,30 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
{
|
||||
// Arrange
|
||||
LoggerFactory logFactory = new LoggerFactory();
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
|
||||
// Act and Assert
|
||||
var provider = new ConfigServerConfigurationProviderBase(settings, logFactory);
|
||||
var provider = new ConfigServerConfigurationProvider(settings, logFactory);
|
||||
Assert.NotNull(provider.Logger);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DefaultConstructor_InitializedWithDefaultSettings()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider();
|
||||
|
||||
// Act and Assert
|
||||
TestHelpers.VerifyDefaults(provider.Settings);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetConfigServerUri_NoLabel()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase() { Name = "myName", Environment = "Production" };
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings);
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings() { Name = "myName", Environment = "Production" };
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);
|
||||
|
||||
// Act and Assert
|
||||
string path = provider.GetConfigServerUri(null);
|
||||
|
@ -80,8 +90,8 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public void GetConfigServerUri_WithLabel()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase() { Name = "myName", Environment = "Production", Label = "myLabel" };
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings);
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings() { Name = "myName", Environment = "Production", Label = "myLabel" };
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);
|
||||
|
||||
// Act and Assert
|
||||
string path = provider.GetConfigServerUri(settings.Label);
|
||||
|
@ -92,7 +102,7 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public void Deserialize_EmptyStream()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(new ConfigServerClientSettingsBase());
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(new ConfigServerClientSettings());
|
||||
MemoryStream stream = new MemoryStream();
|
||||
|
||||
// Act and Assert
|
||||
|
@ -119,11 +129,11 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
}
|
||||
|
||||
}";
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(new ConfigServerClientSettingsBase());
|
||||
Stream stream = ConfigServerTestHelpers.StringToStream(environment);
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(new ConfigServerClientSettings());
|
||||
Stream stream = TestHelpers.StringToStream(environment);
|
||||
|
||||
// Act and Assert
|
||||
Environment env = provider.Deserialize(stream);
|
||||
ConfigEnvironment env = provider.Deserialize(stream);
|
||||
Assert.Null(env);
|
||||
}
|
||||
|
||||
|
@ -147,11 +157,11 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
}
|
||||
]
|
||||
}";
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(new ConfigServerClientSettingsBase());
|
||||
Stream stream = ConfigServerTestHelpers.StringToStream(environment);
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(new ConfigServerClientSettings());
|
||||
Stream stream = TestHelpers.StringToStream(environment);
|
||||
|
||||
// Act and Assert
|
||||
Environment env = provider.Deserialize(stream);
|
||||
ConfigEnvironment env = provider.Deserialize(stream);
|
||||
Assert.NotNull(env);
|
||||
Assert.Equal("testname", env.Name);
|
||||
Assert.NotNull(env.Profiles);
|
||||
|
@ -172,13 +182,13 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public void AddPropertySource_ChangesDataDictionary()
|
||||
{
|
||||
// Arrange
|
||||
IDictionary<string,object> properties = new Dictionary<string, object>();
|
||||
IDictionary<string, object> properties = new Dictionary<string, object>();
|
||||
properties["a.b.c.d"] = "value1";
|
||||
properties["a"] = "value2";
|
||||
properties["b"] = 10;
|
||||
PropertySource source = new PropertySource("test", properties );
|
||||
PropertySource source = new PropertySource("test", properties);
|
||||
source.Name = "test";
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(new ConfigServerClientSettingsBase());
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(new ConfigServerClientSettings());
|
||||
|
||||
// Act and Assert
|
||||
provider.AddPropertySource(source);
|
||||
|
@ -197,7 +207,7 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public async void RemoteLoadAsync_InvalidPath()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(new ConfigServerClientSettingsBase());
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(new ConfigServerClientSettings());
|
||||
|
||||
// Act and Assert
|
||||
InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => provider.RemoteLoadAsync("foobar\\foobar\\"));
|
||||
|
@ -207,7 +217,7 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public async void RemoteLoadAsync_HostTimesout()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(new ConfigServerClientSettingsBase());
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(new ConfigServerClientSettings());
|
||||
|
||||
// Act and Assert
|
||||
HttpRequestException ex = await Assert.ThrowsAsync<HttpRequestException>(() => provider.RemoteLoadAsync("http://foo.bar:9999/app/profile"));
|
||||
|
@ -217,13 +227,13 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public async void RemoteLoadAsync_ConfigServerReturnsGreaterThanEqualBadRequest()
|
||||
{
|
||||
// Arrange
|
||||
var startup = new TestConfigServerStartup("",500);
|
||||
var startup = new TestConfigServerStartup("", 500);
|
||||
var server = TestServer.Create(startup.Configure);
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Uri = "http://localhost:8888";
|
||||
settings.Name = "myName";
|
||||
server.BaseAddress = new Uri(settings.Uri);
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());
|
||||
string path = provider.GetConfigServerUri(null);
|
||||
|
||||
// Act and Assert
|
||||
|
@ -239,15 +249,15 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
// Arrange
|
||||
var startup = new TestConfigServerStartup("", 204);
|
||||
var server = TestServer.Create(startup.Configure);
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Uri = "http://localhost:8888";
|
||||
settings.Name = "myName";
|
||||
server.BaseAddress = new Uri(settings.Uri);
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());
|
||||
string path = provider.GetConfigServerUri(null);
|
||||
|
||||
// Act and Assert
|
||||
Environment result = await provider.RemoteLoadAsync(path);
|
||||
ConfigEnvironment result = await provider.RemoteLoadAsync(path);
|
||||
|
||||
Assert.NotNull(startup.LastRequest);
|
||||
Assert.Equal("/" + settings.Name + "/" + settings.Environment, startup.LastRequest.Path.Value);
|
||||
|
@ -277,15 +287,15 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
}";
|
||||
var startup = new TestConfigServerStartup(environment, 200);
|
||||
var server = TestServer.Create(startup.Configure);
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
settings.Uri ="http://localhost:8888";
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Uri = "http://localhost:8888";
|
||||
settings.Name = "myName";
|
||||
server.BaseAddress = new Uri(settings.Uri);
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());
|
||||
string path = provider.GetConfigServerUri(null);
|
||||
|
||||
// Act and Assert
|
||||
Environment env = await provider.RemoteLoadAsync(path);
|
||||
ConfigEnvironment env = await provider.RemoteLoadAsync(path);
|
||||
Assert.NotNull(startup.LastRequest);
|
||||
Assert.Equal("/" + settings.Name + "/" + settings.Environment, startup.LastRequest.Path.Value);
|
||||
Assert.NotNull(env);
|
||||
|
@ -309,11 +319,11 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
// Arrange
|
||||
var startup = new TestConfigServerStartup("", 404);
|
||||
var server = TestServer.Create(startup.Configure);
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Uri = "http://localhost:8888";
|
||||
settings.Name = "myName";
|
||||
server.BaseAddress = new Uri(settings.Uri);
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());
|
||||
|
||||
// Act and Assert
|
||||
provider.Load();
|
||||
|
@ -328,12 +338,12 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
// Arrange
|
||||
var startup = new TestConfigServerStartup("", 404);
|
||||
var server = TestServer.Create(startup.Configure);
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Uri = "http://localhost:8888";
|
||||
settings.Name = "myName";
|
||||
settings.FailFast = true;
|
||||
server.BaseAddress = new Uri(settings.Uri);
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());
|
||||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ConfigServerException>(() => provider.Load());
|
||||
|
@ -347,12 +357,12 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
// Arrange
|
||||
var startup = new TestConfigServerStartup("", 500);
|
||||
var server = TestServer.Create(startup.Configure);
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Uri = "http://localhost:8888";
|
||||
settings.Name = "myName";
|
||||
settings.FailFast = true;
|
||||
server.BaseAddress = new Uri(settings.Uri);
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());
|
||||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ConfigServerException>(() => provider.Load());
|
||||
|
@ -381,11 +391,11 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
}";
|
||||
var startup = new TestConfigServerStartup(environment, 200);
|
||||
var server = TestServer.Create(startup.Configure);
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Uri = "http://localhost:8888";
|
||||
settings.Name = "myName";
|
||||
server.BaseAddress = new Uri(settings.Uri);
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());
|
||||
|
||||
// Act and Assert
|
||||
provider.Load();
|
||||
|
@ -402,7 +412,7 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
public void AddConfigServerClientSettings_ChangesDataDictionary()
|
||||
{
|
||||
// Arrange
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
|
||||
settings.Enabled = true;
|
||||
settings.Environment = "environment";
|
||||
|
@ -413,7 +423,7 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
settings.Uri = "http://foo.bar/";
|
||||
settings.Username = "username";
|
||||
settings.ValidateCertificates = false;
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings);
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);
|
||||
|
||||
|
||||
// Act and Assert
|
||||
|
@ -445,8 +455,8 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
[Fact]
|
||||
public void GetLabels_Null()
|
||||
{
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings);
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);
|
||||
|
||||
string[] result = provider.GetLabels();
|
||||
Assert.NotNull(result);
|
||||
|
@ -457,9 +467,9 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
[Fact]
|
||||
public void GetLabels_Empty()
|
||||
{
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Label = string.Empty;
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings);
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);
|
||||
|
||||
string[] result = provider.GetLabels();
|
||||
Assert.NotNull(result);
|
||||
|
@ -469,9 +479,9 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
[Fact]
|
||||
public void GetLabels_SingleString()
|
||||
{
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Label = "foobar";
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings);
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);
|
||||
|
||||
string[] result = provider.GetLabels();
|
||||
Assert.NotNull(result);
|
||||
|
@ -481,9 +491,9 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
[Fact]
|
||||
public void GetLabels_MultiString()
|
||||
{
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Label = "1,2,3,";
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings);
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);
|
||||
|
||||
string[] result = provider.GetLabels();
|
||||
Assert.NotNull(result);
|
||||
|
@ -496,9 +506,9 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
[Fact]
|
||||
public void GetLabels_MultiStringHoles()
|
||||
{
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Label = "1,,2,3,";
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings);
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);
|
||||
|
||||
string[] result = provider.GetLabels();
|
||||
Assert.NotNull(result);
|
||||
|
@ -511,11 +521,11 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
[Fact]
|
||||
public void GetRequestMessage_AddsBasicAuthIfPassword()
|
||||
{
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
settings.Uri = "http://user:password@localhost:8888/";
|
||||
settings.Name = "foo";
|
||||
settings.Environment = "development";
|
||||
ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings);
|
||||
ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);
|
||||
|
||||
string requestURI = provider.GetConfigServerUri(null);
|
||||
var request = provider.GetRequestMessage(requestURI);
|
|
@ -22,9 +22,9 @@ using System;
|
|||
|
||||
using Xunit;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.Test
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.Test
|
||||
{
|
||||
public class ConfigServerServiceCollectionExtensionsTest
|
||||
public class ConfigServerConfigServerServiceCollectionExtensionsTest
|
||||
{
|
||||
[Fact]
|
||||
public void AddConfigServer_ThrowsIfServiceCollectionNull()
|
||||
|
@ -67,7 +67,7 @@ namespace Spring.Extensions.Configuration.Server.Test
|
|||
Assert.NotNull(service);
|
||||
var options = service.Value;
|
||||
Assert.NotNull(options);
|
||||
ConfigServerTestHelpers.VerifyDefaults(options.Settings);
|
||||
TestHelpers.VerifyDefaults(options.Settings);
|
||||
|
||||
Assert.Equal(ConfigServerClientSettings.DEFAULT_PROVIDER_ENABLED, options.Enabled);
|
||||
Assert.Equal(ConfigServerClientSettings.DEFAULT_FAILFAST, options.FailFast);
|
|
@ -16,30 +16,30 @@
|
|||
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common.Test
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.Test
|
||||
{
|
||||
public class ConfigServerConfigurationSettingsHelperTest
|
||||
public class ConfigurationSettingsHelperTest
|
||||
{
|
||||
[Fact]
|
||||
public void Initalize_ThrowsOnNulls()
|
||||
{
|
||||
//Initialize(string configPrefix, ConfigServerClientSettingsBase settings, IHostingEnvironment environment, ConfigurationRoot root)
|
||||
// Arrange
|
||||
string configPrefix = null;
|
||||
ConfigServerClientSettingsBase settings = null;
|
||||
ConfigServerClientSettings settings = null;
|
||||
IHostingEnvironment environment = null;
|
||||
ConfigurationRoot root = null;
|
||||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => ConfigServerConfigurationSettingsHelper.Initialize(configPrefix, settings, environment, root));
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => ConfigurationSettingsHelper.Initialize(configPrefix, settings, environment, root));
|
||||
Assert.Contains(nameof(configPrefix), ex.Message);
|
||||
ex = Assert.Throws<ArgumentNullException>(() => ConfigServerConfigurationSettingsHelper.Initialize("foobar", settings, environment, root));
|
||||
ex = Assert.Throws<ArgumentNullException>(() => ConfigurationSettingsHelper.Initialize("foobar", settings, environment, root));
|
||||
Assert.Contains(nameof(settings), ex.Message);
|
||||
ex = Assert.Throws<ArgumentNullException>(() => ConfigServerConfigurationSettingsHelper.Initialize("foobar", new ConfigServerClientSettingsBase(), environment, root));
|
||||
ex = Assert.Throws<ArgumentNullException>(() => ConfigurationSettingsHelper.Initialize("foobar", new ConfigServerClientSettings(), environment, root));
|
||||
Assert.Contains(nameof(environment), ex.Message);
|
||||
}
|
||||
|
||||
|
@ -48,14 +48,13 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
{
|
||||
// Arrange
|
||||
string prefix = "spring:cloud:config";
|
||||
ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
|
||||
ConfigServerClientSettings settings = new ConfigServerClientSettings();
|
||||
HostingEnvironment env = new HostingEnvironment();
|
||||
env.EnvironmentName = null;
|
||||
ConfigurationRoot root = new ConfigurationRoot(new List<IConfigurationProvider>());
|
||||
|
||||
// Act and Assert
|
||||
ConfigServerConfigurationSettingsHelper.Initialize(prefix, settings, env, root);
|
||||
ConfigServerTestHelpers.VerifyDefaults(settings);
|
||||
ConfigurationSettingsHelper.Initialize(prefix, settings, env, root);
|
||||
TestHelpers.VerifyDefaults(settings);
|
||||
|
||||
|
||||
|
|
@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
|
|||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Spring.Extensions.Configuration.Common.Test")]
|
||||
[assembly: AssemblyTitle("SteelToe.Extensions.Configuration.ConfigServer.Test")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Spring.Extensions.Configuration.Common.Test")]
|
||||
[assembly: AssemblyProduct("SteelToe.Extensions.Configuration.ConfigServer.Test")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
@ -20,4 +20,4 @@ using System.Runtime.InteropServices;
|
|||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("eccb52be-a124-4213-95a3-0c4842aa55a2")]
|
||||
[assembly: Guid("85b94f1c-0f93-44b2-af3e-1f3e05346c7d")]
|
|
@ -18,7 +18,7 @@ using Microsoft.Extensions.Configuration;
|
|||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Common.Test
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.Test
|
||||
{
|
||||
public class PropertyPlaceholderHelperTest
|
||||
{
|
||||
|
@ -170,7 +170,7 @@ namespace Spring.Extensions.Configuration.Common.Test
|
|||
}
|
||||
}
|
||||
}";
|
||||
var path = ConfigServerTestHelpers.CreateTempFile(json1);
|
||||
var path = TestHelpers.CreateTempFile(json1);
|
||||
var builder = new ConfigurationBuilder();
|
||||
builder.AddJsonFile(path);
|
||||
var config = builder.Build();
|
|
@ -6,8 +6,8 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>eccb52be-a124-4213-95a3-0c4842aa55a2</ProjectGuid>
|
||||
<RootNamespace>Spring.Extensions.Configuration.Common.Test</RootNamespace>
|
||||
<ProjectGuid>85b94f1c-0f93-44b2-af3e-1f3e05346c7d</ProjectGuid>
|
||||
<RootNamespace>SteelToe.Extensions.Configuration.ConfigServer.Test</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
@ -16,7 +16,6 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c359}" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -21,9 +21,9 @@ using Xunit;
|
|||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.Test
|
||||
namespace SteelToe.Extensions.Configuration.ConfigServer.Test
|
||||
{
|
||||
public class ConfigServerTestHelpers
|
||||
public class TestHelpers
|
||||
{
|
||||
public static string CreateTempFile(string contents)
|
||||
{
|
|
@ -1,10 +1,11 @@
|
|||
{
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"description": "Unit test project for Spring.Extensions.Configuration.Server",
|
||||
"authors": [ "dtillman" ],
|
||||
"tags": [ "" ],
|
||||
"projectUrl": "",
|
||||
"licenseUrl": "",
|
||||
"description": "Unit test project for SteelToe.Extensions.Configuration.ConfigServer",
|
||||
"authors": [ "Pivotal", "dtillman" ],
|
||||
"tags": [ "ASPNET5", "Spring", "Spring Cloud", "Spring Cloud Config Server" ],
|
||||
"projectUrl": "http://steeltoe.io",
|
||||
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
|
||||
"copyright": "Copyright 2015 the original authors",
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": {
|
||||
|
@ -25,7 +26,7 @@
|
|||
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.OptionsModel": "1.0.0-rc1-final",
|
||||
"Spring.Extensions.Configuration.Server": "1.0.7-*",
|
||||
"SteelToe.Extensions.Configuration.ConfigServer": "1.0.0-*",
|
||||
"xunit": "2.1.0",
|
||||
"xunit.runner.dnx": "2.1.0-rc1-build204"
|
||||
},
|
||||
|
@ -35,3 +36,4 @@
|
|||
}
|
||||
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче