├── .appveyor.yml ├── .gitattributes ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── Configuration.sln ├── License.txt ├── README.md ├── config ├── versions-dev.props ├── versions-master.props └── versions.props ├── nuget.config ├── open_source_licenses.txt ├── src ├── Steeltoe.Extensions.Configuration.CloudFoundryAutofac │ ├── CloudFoundryContainerBuilderExtensions.cs │ └── Steeltoe.Extensions.Configuration.CloudFoundryAutofac.csproj ├── Steeltoe.Extensions.Configuration.CloudFoundryBase │ ├── AbstractServiceOptions.cs │ ├── CloudFoundryApplicationOptions.cs │ ├── CloudFoundryConfigurationBuilderExtensions.cs │ ├── CloudFoundryConfigurationProvider.cs │ ├── CloudFoundryConfigurationSource.cs │ ├── CloudFoundryEnvironmentSettingsReader.cs │ ├── CloudFoundryMemorySettingsReader.cs │ ├── CloudFoundryServicesOptions.cs │ ├── Credential.cs │ ├── CredentialConverter.cs │ ├── ICloudFoundrySettingsReader.cs │ ├── JsonStreamConfigurationProvider.cs │ ├── JsonStreamConfigurationSource.cs │ ├── Limits.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Service.cs │ └── Steeltoe.Extensions.Configuration.CloudFoundryBase.csproj ├── Steeltoe.Extensions.Configuration.CloudFoundryCore │ ├── CloudFoundryHostBuilderExtensions.cs │ ├── CloudFoundryServiceCollectionExtensions.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── README.md │ └── Steeltoe.Extensions.Configuration.CloudFoundryCore.csproj ├── Steeltoe.Extensions.Configuration.ConfigServerAutofac │ ├── ConfigServerContainerBuilderExtensions.cs │ └── Steeltoe.Extensions.Configuration.ConfigServerAutofac.csproj ├── Steeltoe.Extensions.Configuration.ConfigServerBase │ ├── ConfigEnvironment.cs │ ├── ConfigServerClientSettings.cs │ ├── ConfigServerClientSettingsOptions.cs │ ├── ConfigServerConfigurationBuilderExtensions.cs │ ├── ConfigServerConfigurationProvider.cs │ ├── ConfigServerConfigurationSource.cs │ ├── ConfigServerDiscoveryService.cs │ ├── ConfigServerException.cs │ ├── ConfigServerHealthContributor.cs │ ├── ConfigurationSettingsHelper.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── PropertySource.cs │ ├── README.md │ ├── SpringCloudConfigDiscovery.cs │ ├── SpringCloudConfigHealth.cs │ ├── SpringCloudConfigRetry.cs │ └── Steeltoe.Extensions.Configuration.ConfigServerBase.csproj ├── Steeltoe.Extensions.Configuration.ConfigServerCore │ ├── ConfigServerConfigurationBuilderExtensionsCore.cs │ ├── ConfigServerHostBuilderExtensions.cs │ ├── ConfigServerServiceCollectionExtensions.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Steeltoe.Extensions.Configuration.ConfigServerCore.csproj ├── Steeltoe.Extensions.Configuration.PlaceholderBase │ ├── PlaceholderResolverExtensions.cs │ ├── PlaceholderResolverProvider.cs │ ├── PlaceholderResolverSource.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── README.md │ └── Steeltoe.Extensions.Configuration.PlaceholderBase.csproj ├── Steeltoe.Extensions.Configuration.PlaceholderCore │ ├── PlaceholderResolverExtensions.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── README.md │ └── Steeltoe.Extensions.Configuration.PlaceholderCore.csproj └── Steeltoe.Extensions.Configuration.RandomValueBase │ ├── Properties │ └── AssemblyInfo.cs │ ├── README.md │ ├── RandomValueExtensions.cs │ ├── RandomValueProvider.cs │ ├── RandomValueSource.cs │ └── Steeltoe.Extensions.Configuration.RandomValueBase.csproj ├── stylecop.json ├── targetframework.props ├── test ├── Steeltoe.Extensions.Configuration.CloudFoundryAutofac.Test │ ├── CloudFoundryContainerBuilderExtensionsTest.cs │ ├── Steeltoe.Extensions.Configuration.CloudFoundryAutofac.Test.csproj │ └── xunit.runner.json ├── Steeltoe.Extensions.Configuration.CloudFoundryBase.Test │ ├── AbstractServiceOptionsTest.cs │ ├── CloudFoundryApplicationOptionsTest.cs │ ├── CloudFoundryConfigurationBuilderExtensionsTest.cs │ ├── CloudFoundryServiceOptionsTest.cs │ ├── CloudfoundryConfigurationProviderTest.cs │ ├── JsonStreamConfigurationProviderTest.cs │ ├── JsonStreamConfigurationSourceTest.cs │ ├── MySqlCredentials.cs │ ├── MySqlServiceOption.cs │ ├── Steeltoe.Extensions.Configuration.CloudFoundryBase.Test.csproj │ └── xunit.runner.json ├── Steeltoe.Extensions.Configuration.CloudFoundryCore.Test │ ├── CloudFoundryHostBuilderExtensionsTest.cs │ ├── CloudFoundryServiceCollectionExtensionsTest.cs │ ├── MySqlCredentials.cs │ ├── MySqlServiceOption.cs │ ├── Steeltoe.Extensions.Configuration.CloudFoundryCore.Test.csproj │ ├── TestServerStartup.cs │ ├── TestServerStartup42.cs │ └── xunit.runner.json ├── Steeltoe.Extensions.Configuration.ConfigServer.ITest │ ├── ConfigServerConfigurationExtensionsIntegrationTest.cs │ ├── ConfigServerDataAsOptions.cs │ ├── HomeController.cs │ ├── Info.cs │ ├── Steeltoe.Extensions.Configuration.ConfigServer.ITest.csproj │ ├── TestServerStartup.cs │ └── xunit.runner.json ├── Steeltoe.Extensions.Configuration.ConfigServerAutofac.Test │ ├── ConfigServerConfigurationBuilderExtensionsAutofacTest.cs │ ├── ConfigServerContainerBuilderExtensionsTest.cs │ ├── Steeltoe.Extensions.Configuration.ConfigServerAutofac.Test.csproj │ └── xunit.runner.json ├── Steeltoe.Extensions.Configuration.ConfigServerBase.Test │ ├── ConfigServerClientSettingsTest.cs │ ├── ConfigServerConfigurationBuilderExtensionsTest.cs │ ├── ConfigServerConfigurationProviderTest.cs │ ├── ConfigServerConfigurationSourceTest.cs │ ├── ConfigServerDiscoveryServiceTest.cs │ ├── ConfigServerHealthContributorTest.cs │ ├── ConfigurationSettingsHelperTest.cs │ ├── CustomCloudFoundrySettingsReader.cs │ ├── Steeltoe.Extensions.Configuration.ConfigServerBase.Test.csproj │ ├── TestConfigServerStartup.cs │ ├── TestHelpers.cs │ └── xunit.runner.json ├── Steeltoe.Extensions.Configuration.ConfigServerCore.Test │ ├── ConfigServerClientSettingsOptionsTest.cs │ ├── ConfigServerConfigurationBuilderExtensionsCoreTest.cs │ ├── ConfigServerServiceCollectionExtensionsTest.cs │ ├── Steeltoe.Extensions.Configuration.ConfigServerCore.Test.csproj │ ├── TestConfigServerStartup.cs │ ├── TestHelpers.cs │ └── xunit.runner.json ├── Steeltoe.Extensions.Configuration.PlaceholderBase.Test │ ├── PlaceholderResolverExtensionsTest.cs │ ├── PlaceholderResolverProviderTest.cs │ ├── PlaceholderResolverSourceTest.cs │ ├── Steeltoe.Extensions.Configuration.PlaceholderBase.Test.csproj │ ├── TestHelpers.cs │ └── xunit.runner.json ├── Steeltoe.Extensions.Configuration.PlaceholderCore.Test │ ├── PlaceholderServiceCollectionExtensionsTest.cs │ ├── Steeltoe.Extensions.Configuration.PlaceholderCore.Test.csproj │ ├── TestHelpers.cs │ ├── TestServerStartup.cs │ ├── TestServerStartup1.cs │ └── xunit.runner.json └── Steeltoe.Extensions.Configuration.RandomValuesBase.Test │ ├── RandomValueExtensionsTest.cs │ ├── RandomValueProviderTest.cs │ ├── RandomValueSourceTest.cs │ ├── Steeltoe.Extensions.Configuration.RandomValueBase.Test.csproj │ └── xunit.runner.json └── versions.props /.appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '2.2.0-{branch}-{build}' 2 | init: 3 | - git config --global core.autocrlf true 4 | image: Visual Studio 2017 5 | skip_tags: true 6 | branches: 7 | only: 8 | - master 9 | - dev 10 | - /^update[0-9]{2}x/ 11 | install: 12 | - git clone https://github.com/SteeltoeOSS/steeltoe-ci.git -v 13 | - ps: steeltoe-ci\scripts\appveyor_install.ps1 14 | test_script: 15 | - ps: steeltoe-ci\scripts\appveyor_tests.ps1 16 | build_script: 17 | - ps: steeltoe-ci\scripts\appveyor_build.ps1 18 | - ps: steeltoe-ci\scripts\sign-packages.ps1 19 | artifacts: 20 | - path: 'localfeed\*.nupkg' 21 | environment: 22 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true 23 | DOTNET_CLI_TELEMETRY_OPTOUT: 1 24 | ProjectList: Steeltoe.Extensions.Configuration.RandomValueBase Steeltoe.Extensions.Configuration.CloudFoundryBase Steeltoe.Extensions.Configuration.PlaceholderBase Steeltoe.Extensions.Configuration.ConfigServerBase Steeltoe.Extensions.Configuration.CloudFoundryCore Steeltoe.Extensions.Configuration.CloudFoundryAutofac Steeltoe.Extensions.Configuration.PlaceholderCore Steeltoe.Extensions.Configuration.ConfigServerCore Steeltoe.Extensions.Configuration.ConfigServerAutofac 25 | PackageReferencesToUpdate: SteeltoeConfigVersion 26 | github_access_token: 27 | secure: ko4J3M/czguVI9AbVdkv5qZuj3Wuzts5nkz/6cypneFkQGWJXDs8Akg7xOEMu8qU 28 | SignClientUser: 29 | secure: Tt9mySuspn9dHJOLKMoGxrNJvJbpBrWK44UI9Qc9+eNilYdoukHZ3jUF06pl2r60 30 | SignClientSecret: 31 | secure: ZmCTr+SyfQtewSNsiB8OMISmQJp8RfjRSK0Dvg60iTQ= 32 | deploy: 33 | - provider: NuGet 34 | skip_symbols: false 35 | artifact: /.*\.nupkg/ 36 | server: https://www.myget.org/F/steeltoedev/api/v2/package 37 | symbol_server: https://www.myget.org/F/steeltoedev/symbols/api/v2/package 38 | api_key: 39 | secure: 246ApObnMYYvzDo9Ki72CxxuKfuoqYbrbUK2HLevGIGHXYY6f0OkAdE3EWCwNJ7g 40 | on: 41 | branch: dev 42 | appveyor_repo_tag: false 43 | - provider: NuGet 44 | skip_symbols: false 45 | artifact: /.*\.nupkg/ 46 | server: https://www.myget.org/F/steeltoemaster/api/v2/package 47 | symbol_server: https://www.myget.org/F/steeltoemaster/symbols/api/v2/package 48 | api_key: 49 | secure: 246ApObnMYYvzDo9Ki72CxxuKfuoqYbrbUK2HLevGIGHXYY6f0OkAdE3EWCwNJ7g 50 | on: 51 | branch: master 52 | appveyor_repo_tag: false 53 | - provider: NuGet 54 | skip_symbols: true 55 | artifact: /.*\.nupkg/ 56 | server: https://www.myget.org/F/steeltoestaging/api/v2/package 57 | symbol_server: https://www.myget.org/F/steeltoestaging/symbols/api/v2/package 58 | api_key: 59 | secure: 246ApObnMYYvzDo9Ki72CxxuKfuoqYbrbUK2HLevGIGHXYY6f0OkAdE3EWCwNJ7g 60 | on: 61 | branch: /^update[0-9]{2}x/ 62 | appveyor_repo_tag: false 63 | after_deploy: 64 | - git config --global credential.helper store 65 | - ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:github_access_token):x-oauth-basic@github.com`n" 66 | - git config --global user.email "steeltoe@pivotal.io" 67 | - git config --global user.name "SteeltoeCI" 68 | - ps: steeltoe-ci\scripts\update_downstream_props.ps1 -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.doc diff=astextplain 2 | *.DOC diff=astextplain 3 | *.docx diff=astextplain 4 | *.DOCX diff=astextplain 5 | *.dot diff=astextplain 6 | *.DOT diff=astextplain 7 | *.pdf diff=astextplain 8 | *.PDF diff=astextplain 9 | *.rtf diff=astextplain 10 | *.RTF diff=astextplain 11 | 12 | *.jpg binary 13 | *.png binary 14 | *.gif binary 15 | 16 | *.cs text=auto diff=csharp 17 | *.vb text=auto 18 | *.resx text=auto 19 | *.c text=auto 20 | *.cpp text=auto 21 | *.cxx text=auto 22 | *.h text=auto 23 | *.hxx text=auto 24 | *.py text=auto 25 | *.rb text=auto 26 | *.java text=auto 27 | *.html text=auto 28 | *.htm text=auto 29 | *.css text=auto 30 | *.scss text=auto 31 | *.sass text=auto 32 | *.less text=auto 33 | *.js text=auto 34 | *.lisp text=auto 35 | *.clj text=auto 36 | *.sql text=auto 37 | *.php text=auto 38 | *.lua text=auto 39 | *.m text=auto 40 | *.asm text=auto 41 | *.erl text=auto 42 | *.fs text=auto 43 | *.fsx text=auto 44 | *.hs text=auto 45 | 46 | *.csproj text=auto 47 | *.vbproj text=auto 48 | *.fsproj text=auto 49 | *.dbproj text=auto 50 | *.sln text=auto eol=crlf 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | ~$* 157 | *~ 158 | *.dbmdl 159 | *.dbproj.schemaview 160 | *.pfx 161 | *.publishsettings 162 | node_modules/ 163 | bower_components/ 164 | 165 | # RIA/Silverlight projects 166 | Generated_Code/ 167 | 168 | # Backup & report files from converting an old project file 169 | # to a newer Visual Studio version. Backup files are not needed, 170 | # because we have git ;-) 171 | _UpgradeReport_Files/ 172 | Backup*/ 173 | UpgradeLog*.XML 174 | UpgradeLog*.htm 175 | 176 | # SQL Server files 177 | *.mdf 178 | *.ldf 179 | 180 | # Business Intelligence projects 181 | *.rdl.data 182 | *.bim.layout 183 | *.bim_*.settings 184 | 185 | # Microsoft Fakes 186 | FakesAssemblies/ 187 | 188 | # Node.js Tools for Visual Studio 189 | .ntvs_analysis.dat 190 | 191 | # Visual Studio 6 build log 192 | *.plg 193 | 194 | # Visual Studio 6 workspace options file 195 | *.opt 196 | 197 | # DNX-based projects have a project.lock.json file. This should not be checked-in during development 198 | project.lock.json 199 | 200 | .vscode/ 201 | .idea/ 202 | 203 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | dist: trusty 3 | env: 4 | TestFrameworkVersion: netcoreapp2.1 5 | STEELTOE_VERSION: 2.2.0 6 | global: 7 | - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true 8 | - DOTNET_CLI_TELEMETRY_OPTOUT: 1 9 | mono: none 10 | dotnet: 2.1.403 11 | os: 12 | - linux 13 | - osx 14 | osx_image: xcode8.3 15 | branches: 16 | only: 17 | - master 18 | - dev 19 | - /^update[0-9]{2}x/ 20 | script: 21 | - ./steeltoe-ci/scripts/travis_install.sh 22 | - ./steeltoe-ci/scripts/travis_build.sh 23 | - ./steeltoe-ci/scripts/travis_test.sh 24 | before_install: 25 | - git clone https://github.com/SteeltoeOSS/steeltoe-ci.git -v 26 | - if [ "$TRAVIS_OS_NAME" = "osx" ]; then ulimit -n 1024; fi 27 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | If you have not previously done so, please fill out and 2 | submit the [Contributor License Agreement](https://cla.pivotal.io/sign/pivotal). 3 | -------------------------------------------------------------------------------- /config/versions-dev.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(STEELTOE_VERSION) 4 | $(STEELTOE_DASH_VERSION_SUFFIX) 5 | 2.2.0-dev-00117 6 | 2.2.0-dev-00326 7 | 2.0.0 8 | 2.0.0 9 | 2.1.0 10 | 2.1.0 11 | 4.6.1 12 | 4.3.3 13 | 4.4.0 14 | 1.0.2 15 | 11.0.2 16 | 15.7.2 17 | 2.3.1 18 | 2.3.1 19 | 1.0.0-beta2-18618-05 20 | 21 | -------------------------------------------------------------------------------- /config/versions-master.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(STEELTOE_VERSION) 4 | $(STEELTOE_DASH_VERSION_SUFFIX) 5 | 2.2.0-master-00094 6 | 2.2.0-master-00313 7 | 2.0.0 8 | 2.0.0 9 | 2.1.0 10 | 2.1.0 11 | 4.6.1 12 | 4.3.3 13 | 4.4.0 14 | 1.0.2 15 | 11.0.2 16 | 15.7.2 17 | 2.3.1 18 | 2.3.1 19 | 1.0.0-beta2-18618-05 20 | 21 | -------------------------------------------------------------------------------- /config/versions.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(STEELTOE_VERSION) 4 | $(STEELTOE_DASH_VERSION_SUFFIX) 5 | 2.1.0 6 | 2.2.0 7 | 2.0.0 8 | 2.0.0 9 | 2.1.0 10 | 2.1.0 11 | 4.6.1 12 | 4.3.3 13 | 4.4.0 14 | 1.0.2 15 | 11.0.2 16 | 15.7.2 17 | 2.3.1 18 | 2.3.1 19 | 1.0.0-beta2-18618-05 20 | 21 | -------------------------------------------------------------------------------- /nuget.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryAutofac/CloudFoundryContainerBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Autofac; 16 | using Microsoft.Extensions.Configuration; 17 | using Steeltoe.Common.Options.Autofac; 18 | using System; 19 | 20 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 21 | { 22 | /// 23 | /// Extension methods for adding services related to CloudFoundry 24 | /// 25 | public static class CloudFoundryContainerBuilderExtensions 26 | { 27 | public static void RegisterCloudFoundryOptions(this ContainerBuilder container, IConfiguration config) 28 | { 29 | if (container == null) 30 | { 31 | throw new ArgumentNullException(nameof(container)); 32 | } 33 | 34 | if (config == null) 35 | { 36 | throw new ArgumentNullException(nameof(config)); 37 | } 38 | 39 | var appSection = config.GetSection(CloudFoundryApplicationOptions.CONFIGURATION_PREFIX); 40 | container.RegisterOption(appSection); 41 | 42 | var serviceSection = config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX); 43 | container.RegisterOption(serviceSection); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryAutofac/Steeltoe.Extensions.Configuration.CloudFoundryAutofac.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CloudFoundry Environment Variable Configuration Provider Autofac 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.Extensions.Configuration.CloudFoundryAutofac 10 | Steeltoe.Extensions.Configuration.CloudFoundryAutofac 11 | CloudFoundry;ASPNET;Autofac 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.Extensions.Configuration.CloudFoundryAutofac.xml 21 | 22 | 23 | 24 | 25 | 26 | 27 | All 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 40 | 41 | 42 | 43 | stylecop.json 44 | Always 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/AbstractServiceOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using System; 17 | using System.Collections.Generic; 18 | 19 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 20 | { 21 | public abstract class AbstractServiceOptions 22 | { 23 | public const string CONFIGURATION_PREFIX = "vcap:services"; 24 | 25 | public string Name { get; set; } 26 | 27 | public string Label { get; set; } 28 | 29 | public List Tags { get; set; } 30 | 31 | public string Plan { get; set; } 32 | 33 | public void Bind(IConfiguration configuration, string serviceName) 34 | { 35 | if (configuration == null) 36 | { 37 | throw new ArgumentNullException(nameof(configuration)); 38 | } 39 | 40 | if (string.IsNullOrEmpty(serviceName)) 41 | { 42 | throw new ArgumentException(nameof(serviceName)); 43 | } 44 | 45 | var services = configuration.GetSection(CONFIGURATION_PREFIX); 46 | var section = FindServiceSection(services, serviceName); 47 | 48 | if (section != null) 49 | { 50 | section.Bind(this); 51 | } 52 | } 53 | 54 | internal IConfigurationSection FindServiceSection(IConfigurationSection section, string serviceName) 55 | { 56 | var children = section.GetChildren(); 57 | foreach (var child in children) 58 | { 59 | string name = child.GetValue("name"); 60 | if (serviceName == name) 61 | { 62 | return child; 63 | } 64 | } 65 | 66 | foreach (var child in children) 67 | { 68 | var result = FindServiceSection(child, serviceName); 69 | if (result != null) 70 | { 71 | return result; 72 | } 73 | } 74 | 75 | return null; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/CloudFoundryApplicationOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Steeltoe.Common.Options; 17 | 18 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 19 | { 20 | public class CloudFoundryApplicationOptions : AbstractOptions 21 | { 22 | public const string CONFIGURATION_PREFIX = "vcap:application"; 23 | 24 | public CloudFoundryApplicationOptions() 25 | { 26 | } 27 | 28 | public CloudFoundryApplicationOptions(IConfigurationRoot root) 29 | : base(root, CONFIGURATION_PREFIX) 30 | { 31 | } 32 | 33 | public CloudFoundryApplicationOptions(IConfiguration config) 34 | : base(config) 35 | { 36 | } 37 | 38 | public string CF_Api { get; set; } 39 | 40 | public string Application_Id { get; set; } 41 | 42 | public string Application_Name { get; set; } 43 | 44 | public string[] Application_Uris { get; set; } 45 | 46 | public string Application_Version { get; set; } 47 | 48 | public string Instance_Id { get; set; } 49 | 50 | public int Instance_Index { get; set; } = -1; 51 | 52 | public Limits Limits { get; set; } 53 | 54 | public string Name { get; set; } 55 | 56 | public int Port { get; set; } = -1; 57 | 58 | public string Space_Id { get; set; } 59 | 60 | public string Space_Name { get; set; } 61 | 62 | public string Start { get; set; } 63 | 64 | public string[] Uris { get; set; } 65 | 66 | public string Version { get; set; } 67 | 68 | public string Instance_IP { get; set; } 69 | 70 | public string Internal_IP { get; set; } 71 | 72 | public string ApplicationId => Application_Id; 73 | 74 | public string ApplicationName => Application_Name; 75 | 76 | public string[] ApplicationUris => Application_Uris; 77 | 78 | public string ApplicationVersion => Application_Version; 79 | 80 | public string InstanceId => Instance_Id; 81 | 82 | public int InstanceIndex => Instance_Index; 83 | 84 | public string SpaceId => Space_Id; 85 | 86 | public string SpaceName => Space_Name; 87 | 88 | public string InstanceIP => Instance_IP; 89 | 90 | public string InternalIP => Internal_IP; 91 | 92 | public int DiskLimit => Limits == null ? -1 : Limits.Disk; 93 | 94 | public int MemoryLimit => Limits == null ? -1 : Limits.Mem; 95 | 96 | public int FileDescriptorLimit => Limits == null ? -1 : Limits.Fds; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/CloudFoundryConfigurationBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using System; 17 | 18 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 19 | { 20 | public static class CloudFoundryConfigurationBuilderExtensions 21 | { 22 | public static IConfigurationBuilder AddCloudFoundry(this IConfigurationBuilder configurationBuilder) 23 | { 24 | return configurationBuilder.AddCloudFoundry(null); 25 | } 26 | 27 | public static IConfigurationBuilder AddCloudFoundry(this IConfigurationBuilder configurationBuilder, ICloudFoundrySettingsReader settingsReader) 28 | { 29 | if (configurationBuilder == null) 30 | { 31 | throw new ArgumentNullException(nameof(configurationBuilder)); 32 | } 33 | 34 | return configurationBuilder.Add(new CloudFoundryConfigurationSource { SettingsReader = settingsReader }); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/CloudFoundryConfigurationSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | 17 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 18 | { 19 | public class CloudFoundryConfigurationSource : IConfigurationSource 20 | { 21 | public ICloudFoundrySettingsReader SettingsReader { get; set; } 22 | 23 | public IConfigurationProvider Build(IConfigurationBuilder builder) 24 | { 25 | return new CloudFoundryConfigurationProvider(this.SettingsReader ?? new CloudFoundryEnvironmentSettingsReader()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/CloudFoundryEnvironmentSettingsReader.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | 17 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 18 | { 19 | public class CloudFoundryEnvironmentSettingsReader : ICloudFoundrySettingsReader 20 | { 21 | private const string CF_INSTANCE_GUID = "CF_INSTANCE_GUID"; 22 | 23 | private const string CF_INSTANCE_INDEX = "CF_INSTANCE_INDEX"; 24 | 25 | private const string CF_INSTANCE_INTERNAL_IP = "CF_INSTANCE_INTERNAL_IP"; 26 | 27 | private const string CF_INSTANCE_IP = "CF_INSTANCE_IP"; 28 | 29 | private const string CF_INSTANCE_PORT = "CF_INSTANCE_PORT"; 30 | 31 | private const string VCAP_APPLICATION = "VCAP_APPLICATION"; 32 | 33 | private const string VCAP_SERVICES = "VCAP_SERVICES"; 34 | 35 | public string ApplicationJson => Environment.GetEnvironmentVariable(VCAP_APPLICATION); 36 | 37 | public string InstanceId => Environment.GetEnvironmentVariable(CF_INSTANCE_GUID); 38 | 39 | public string InstanceIndex => Environment.GetEnvironmentVariable(CF_INSTANCE_INDEX); 40 | 41 | public string InstanceInternalIp => Environment.GetEnvironmentVariable(CF_INSTANCE_INTERNAL_IP); 42 | 43 | public string InstanceIp => Environment.GetEnvironmentVariable(CF_INSTANCE_IP); 44 | 45 | public string InstancePort => Environment.GetEnvironmentVariable(CF_INSTANCE_PORT); 46 | 47 | public string ServicesJson => Environment.GetEnvironmentVariable(VCAP_SERVICES); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/CloudFoundryMemorySettingsReader.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 16 | { 17 | public class CloudFoundryMemorySettingsReader : ICloudFoundrySettingsReader 18 | { 19 | public string ApplicationJson { get; set; } 20 | 21 | public string InstanceId { get; set; } 22 | 23 | public string InstanceIndex { get; set; } 24 | 25 | public string InstanceInternalIp { get; set; } 26 | 27 | public string InstanceIp { get; set; } 28 | 29 | public string InstancePort { get; set; } 30 | 31 | public string ServicesJson { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/CloudFoundryServicesOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Steeltoe.Common.Options; 17 | using System.Collections.Generic; 18 | 19 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 20 | { 21 | public class CloudFoundryServicesOptions : AbstractOptions 22 | { 23 | public const string CONFIGURATION_PREFIX = "vcap"; 24 | 25 | public CloudFoundryServicesOptions() 26 | { 27 | } 28 | 29 | public CloudFoundryServicesOptions(IConfigurationRoot root) 30 | : base(root, CONFIGURATION_PREFIX) 31 | { 32 | } 33 | 34 | public CloudFoundryServicesOptions(IConfiguration config) 35 | : base(config) 36 | { 37 | } 38 | 39 | public Dictionary Services { get; set; } = new Dictionary(); 40 | 41 | public IList ServicesList 42 | { 43 | get 44 | { 45 | List results = new List(); 46 | if (Services != null) 47 | { 48 | foreach (KeyValuePair kvp in Services) 49 | { 50 | results.AddRange(kvp.Value); 51 | } 52 | } 53 | 54 | return results; 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/Credential.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Collections.Generic; 16 | using System.ComponentModel; 17 | 18 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 19 | { 20 | [TypeConverter(typeof(CredentialConverter))] 21 | public class Credential : Dictionary 22 | { 23 | private string _value; 24 | 25 | public Credential() 26 | { 27 | } 28 | 29 | public Credential(string value) 30 | { 31 | _value = value; 32 | } 33 | 34 | public string Value 35 | { 36 | get 37 | { 38 | return _value; 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/CredentialConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using System.ComponentModel; 17 | using System.Globalization; 18 | 19 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 20 | { 21 | public class CredentialConverter : TypeConverter 22 | { 23 | public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) 24 | { 25 | if (value is string) 26 | { 27 | return new Credential((string)value); 28 | } 29 | 30 | return base.ConvertFrom(context, culture, value); 31 | } 32 | 33 | public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) 34 | { 35 | if (sourceType == typeof(string)) 36 | { 37 | return true; 38 | } 39 | 40 | return base.CanConvertFrom(context, sourceType); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/ICloudFoundrySettingsReader.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 16 | { 17 | public interface ICloudFoundrySettingsReader 18 | { 19 | string ApplicationJson { get; } 20 | 21 | string InstanceId { get; } 22 | 23 | string InstanceIndex { get; } 24 | 25 | string InstanceInternalIp { get; } 26 | 27 | string InstanceIp { get; } 28 | 29 | string InstancePort { get; } 30 | 31 | string ServicesJson { get; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/JsonStreamConfigurationProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration.Json; 16 | using System; 17 | 18 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 19 | { 20 | internal class JsonStreamConfigurationProvider : JsonConfigurationProvider 21 | { 22 | private JsonStreamConfigurationSource _source; 23 | 24 | internal JsonStreamConfigurationProvider(JsonStreamConfigurationSource source) 25 | : base(source) 26 | { 27 | if (source == null) 28 | { 29 | throw new ArgumentNullException(nameof(source)); 30 | } 31 | 32 | _source = source; 33 | } 34 | 35 | public override void Load() 36 | { 37 | Load(_source.Stream); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/JsonStreamConfigurationSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.Configuration.Json; 17 | using System; 18 | using System.IO; 19 | 20 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 21 | { 22 | internal class JsonStreamConfigurationSource : JsonConfigurationSource 23 | { 24 | internal JsonStreamConfigurationSource(MemoryStream stream) 25 | { 26 | if (stream == null) 27 | { 28 | throw new ArgumentNullException(nameof(stream)); 29 | } 30 | 31 | Stream = stream; 32 | } 33 | 34 | internal MemoryStream Stream { get; } 35 | 36 | public override IConfigurationProvider Build(IConfigurationBuilder builder) 37 | { 38 | return new JsonStreamConfigurationProvider(this); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/Limits.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 16 | { 17 | public class Limits 18 | { 19 | public int Disk { get; set; } = -1; 20 | 21 | public int Fds { get; set; } = -1; 22 | 23 | public int Mem { get; set; } = -1; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Runtime.CompilerServices; 16 | 17 | [assembly: InternalsVisibleTo("Steeltoe.Extensions.Configuration.CloudFoundryBase.Test")] 18 | [assembly: InternalsVisibleTo("Steeltoe.Extensions.Configuration.CloudFoundryCore.Test")] 19 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/Service.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Collections.Generic; 16 | 17 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 18 | { 19 | public class Service 20 | { 21 | public string Name { get; set; } 22 | 23 | public string Label { get; set; } 24 | 25 | public string[] Tags { get; set; } 26 | 27 | public string Plan { get; set; } 28 | 29 | public Dictionary Credentials { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryBase/Steeltoe.Extensions.Configuration.CloudFoundryBase.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | CloudFoundry Environment Variable Configuration Provider - Base Package 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.Extensions.Configuration.CloudFoundryBase 10 | Steeltoe.Extensions.Configuration.CloudFoundryBase 11 | CloudFoundry;NET Core;NET Framework 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | 21 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.Extensions.Configuration.CloudFoundryBase.xml 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | All 32 | 33 | 34 | 35 | 36 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 37 | 38 | 39 | 40 | stylecop.json 41 | Always 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryCore/CloudFoundryHostBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Hosting; 16 | using System; 17 | using System.Collections.Generic; 18 | 19 | namespace Steeltoe.Extensions.Configuration.CloudFoundry 20 | { 21 | public static class CloudFoundryHostBuilderExtensions 22 | { 23 | /// 24 | /// Enable the application to listen on port(s) provided by the environment at runtime 25 | /// 26 | /// Your WebHostBuilder 27 | /// Set the port number with code so you don't need to set environment variables locally 28 | /// Your WebHostBuilder, now listening on port(s) found in the environment or passed in 29 | /// runLocalPort parameter will not be used if an environment variable PORT is found 30 | public static IWebHostBuilder UseCloudFoundryHosting(this IWebHostBuilder webHostBuilder, int? runLocalPort = null) 31 | { 32 | if (webHostBuilder == null) 33 | { 34 | throw new ArgumentNullException(nameof(webHostBuilder)); 35 | } 36 | 37 | List urls = new List(); 38 | 39 | string portStr = Environment.GetEnvironmentVariable("PORT"); 40 | if (!string.IsNullOrWhiteSpace(portStr)) 41 | { 42 | if (int.TryParse(portStr, out int port)) 43 | { 44 | urls.Add($"http://*:{port}"); 45 | } 46 | } 47 | else if (runLocalPort != null) 48 | { 49 | urls.Add($"http://*:{runLocalPort}"); 50 | } 51 | 52 | if (urls.Count > 0) 53 | { 54 | webHostBuilder.UseUrls(urls.ToArray()); 55 | } 56 | 57 | return webHostBuilder; 58 | } 59 | 60 | public static IWebHostBuilder AddCloudFoundry(this IWebHostBuilder hostBuilder) 61 | { 62 | hostBuilder.ConfigureAppConfiguration((context, config) => 63 | { 64 | config.AddCloudFoundry(); 65 | }); 66 | 67 | return hostBuilder; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryCore/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Runtime.CompilerServices; 16 | 17 | [assembly: InternalsVisibleTo("Steeltoe.Extensions.Configuration.CloudFoundryCore.Test")] 18 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryCore/README.md: -------------------------------------------------------------------------------- 1 | # CloudFoundry .NET Configuration Provider 2 | 3 | This project contains the CloudFoundry configuration provider. This provider enables the CloudFoundry environment variables, `VCAP_APPLICATION` and `VCAP_SERVICES` to be parsed and accessed as configuration data within a .NET application. 4 | 5 | For more information on how to use this component see the online [Steeltoe documentation](https://steeltoe.io/). 6 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.CloudFoundryCore/Steeltoe.Extensions.Configuration.CloudFoundryCore.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | NET Core CloudFoundry Environment Variable Configuration Provider 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.Extensions.Configuration.CloudFoundryCore 10 | Steeltoe.Extensions.Configuration.CloudFoundryCore 11 | CloudFoundry;ASPNET Core;Spring;Spring Cloud 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.Extensions.Configuration.CloudFoundryCore.xml 21 | 22 | 23 | 24 | 25 | 26 | 27 | All 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 40 | 41 | 42 | 43 | stylecop.json 44 | Always 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerAutofac/ConfigServerContainerBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Autofac; 16 | using Microsoft.Extensions.Configuration; 17 | using Steeltoe.Common.HealthChecks; 18 | using Steeltoe.Common.Options.Autofac; 19 | using System; 20 | using System.Linq; 21 | 22 | namespace Steeltoe.Extensions.Configuration.ConfigServer 23 | { 24 | /// 25 | /// Extension methods for adding services related to Spring Cloud Config Server. 26 | /// 27 | public static class ConfigServerContainerBuilderExtensions 28 | { 29 | public static void RegisterConfigServerClientOptions(this ContainerBuilder container, IConfiguration config) 30 | { 31 | if (container == null) 32 | { 33 | throw new ArgumentNullException(nameof(container)); 34 | } 35 | 36 | if (config == null) 37 | { 38 | throw new ArgumentNullException(nameof(config)); 39 | } 40 | 41 | var section = config.GetSection(ConfigServerClientSettingsOptions.CONFIGURATION_PREFIX); 42 | container.RegisterOption(section); 43 | } 44 | 45 | /// 46 | /// Add the ConfigServerHealthContributor as a IHealthContributor to the container. 47 | /// Note: You also need to add the applications IConfiguration to the container as well. 48 | /// 49 | /// the autofac container builder 50 | public static void RegisterConfigServerHealthContributor(this ContainerBuilder container) 51 | { 52 | if (container == null) 53 | { 54 | throw new ArgumentNullException(nameof(container)); 55 | } 56 | 57 | container.RegisterType().As().SingleInstance(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerAutofac/Steeltoe.Extensions.Configuration.ConfigServerAutofac.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Spring Cloud Config Server Configuration Provider Autofac 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.Extensions.Configuration.ConfigServerAutofac 10 | Steeltoe.Extensions.Configuration.ConfigServerAutofac 11 | ASPNET;Autofac;Spring Cloud;Spring Cloud Config Server 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.Extensions.Configuration.ConfigServerAutofac.xml 21 | 22 | 23 | 24 | 25 | 26 | 27 | All 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 40 | 41 | 42 | 43 | stylecop.json 44 | Always 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerBase/ConfigEnvironment.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Collections.Generic; 16 | 17 | namespace Steeltoe.Extensions.Configuration.ConfigServer 18 | { 19 | public class ConfigEnvironment 20 | { 21 | public string Name { get; set; } 22 | 23 | public string Label { get; set; } 24 | 25 | public IList Profiles { get; set; } 26 | 27 | public IList PropertySources { get; set; } 28 | 29 | public string Version { get; set; } 30 | 31 | public string State { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerBase/ConfigServerConfigurationBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.Logging; 17 | using Steeltoe.Common; 18 | using Steeltoe.Extensions.Configuration.CloudFoundry; 19 | using System; 20 | using System.Linq; 21 | using System.Reflection; 22 | 23 | namespace Steeltoe.Extensions.Configuration.ConfigServer 24 | { 25 | public static class ConfigServerConfigurationBuilderExtensions 26 | { 27 | public static IConfigurationBuilder AddConfigServer(this IConfigurationBuilder configurationBuilder, ILoggerFactory logFactory = null) 28 | { 29 | return configurationBuilder.AddConfigServer(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, Assembly.GetEntryAssembly()?.GetName().Name, logFactory); 30 | } 31 | 32 | public static IConfigurationBuilder AddConfigServer(this IConfigurationBuilder configurationBuilder, string environment, ILoggerFactory logFactory = null) 33 | { 34 | return configurationBuilder.AddConfigServer(environment, Assembly.GetEntryAssembly()?.GetName().Name, logFactory); 35 | } 36 | 37 | public static IConfigurationBuilder AddConfigServer(this IConfigurationBuilder configurationBuilder, string environment, string applicationName, ILoggerFactory logFactory = null) 38 | { 39 | if (configurationBuilder == null) 40 | { 41 | throw new ArgumentNullException(nameof(configurationBuilder)); 42 | } 43 | 44 | var settings = new ConfigServerClientSettings() 45 | { 46 | Name = applicationName ?? Assembly.GetEntryAssembly()?.GetName().Name, 47 | 48 | Environment = environment ?? ConfigServerClientSettings.DEFAULT_ENVIRONMENT 49 | }; 50 | 51 | return configurationBuilder.AddConfigServer(settings, logFactory); 52 | } 53 | 54 | public static IConfigurationBuilder AddConfigServer(this IConfigurationBuilder configurationBuilder, ConfigServerClientSettings defaultSettings, ILoggerFactory logFactory = null) 55 | { 56 | if (configurationBuilder == null) 57 | { 58 | throw new ArgumentNullException(nameof(configurationBuilder)); 59 | } 60 | 61 | if (defaultSettings == null) 62 | { 63 | throw new ArgumentNullException(nameof(defaultSettings)); 64 | } 65 | 66 | if (!configurationBuilder.Sources.Any(c => c.GetType() == typeof(CloudFoundryConfigurationSource))) 67 | { 68 | configurationBuilder.Add(new CloudFoundryConfigurationSource()); 69 | } 70 | 71 | configurationBuilder.Add(new ConfigServerConfigurationSource(defaultSettings, configurationBuilder.Sources, configurationBuilder.Properties, logFactory)); 72 | return configurationBuilder; 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerBase/ConfigServerDiscoveryService.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.Logging; 17 | using Steeltoe.Common.Discovery; 18 | using Steeltoe.Common.Reflection; 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Reflection; 22 | using System.Threading; 23 | 24 | namespace Steeltoe.Extensions.Configuration.ConfigServer 25 | { 26 | internal class ConfigServerDiscoveryService 27 | { 28 | protected internal IConfiguration _configuration; 29 | protected internal ConfigServerClientSettings _settings; 30 | protected internal ILoggerFactory _logFactory; 31 | protected internal ILogger _logger; 32 | 33 | private static readonly string[] _discoveryServiceAssemblies = new string[] { "Steeltoe.Discovery.EurekaBase" }; 34 | private static readonly string[] _discoveryServiceTypeNames = new string[] { "Steeltoe.Discovery.Eureka.EurekaClientService" }; 35 | 36 | internal ConfigServerDiscoveryService(IConfiguration configuration, ConfigServerClientSettings settings, ILoggerFactory logFactory = null) 37 | { 38 | _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); 39 | _settings = settings ?? throw new ArgumentNullException(nameof(settings)); 40 | _logFactory = logFactory; 41 | _logger = _logFactory?.CreateLogger(typeof(ConfigServerDiscoveryService)); 42 | } 43 | 44 | internal IList GetConfigServerInstances() 45 | { 46 | MethodInfo method = FindGetInstancesMethod(); 47 | if (method == null) 48 | { 49 | _logger?.LogWarning("Could not locate discovery assembly or GetInstances() method!"); 50 | return null; 51 | } 52 | 53 | return InvokeGetInstances(method); 54 | } 55 | 56 | internal MethodInfo FindGetInstancesMethod() 57 | { 58 | Type discoveryService = ReflectionHelpers.FindType(_discoveryServiceAssemblies, _discoveryServiceTypeNames); 59 | MethodInfo method = null; 60 | 61 | if (discoveryService != null) 62 | { 63 | method = ReflectionHelpers.FindMethod(discoveryService, "GetInstances"); 64 | } 65 | 66 | return method; 67 | } 68 | 69 | internal IList InvokeGetInstances(MethodInfo method) 70 | { 71 | var attempts = 0; 72 | var backOff = _settings.RetryInitialInterval; 73 | IList instances = null; 74 | 75 | do 76 | { 77 | instances = null; 78 | try 79 | { 80 | _logger?.LogDebug("Locating configserver {serviceId} via discovery", _settings.DiscoveryServiceId); 81 | instances = method.Invoke(null, new object[] { _configuration, _settings.DiscoveryServiceId, _logFactory }) as IList; 82 | } 83 | catch (Exception e) 84 | { 85 | _logger?.LogError(e, "Exception invoking GetInstances() during config server lookup"); 86 | } 87 | 88 | if (!_settings.RetryEnabled || (instances != null && instances.Count > 0)) 89 | { 90 | break; 91 | } 92 | 93 | attempts++; 94 | if (attempts < _settings.RetryAttempts) 95 | { 96 | Thread.CurrentThread.Join(backOff); 97 | var nextBackoff = (int)(backOff * _settings.RetryMultiplier); 98 | backOff = Math.Min(nextBackoff, _settings.RetryMaxInterval); 99 | } 100 | else 101 | { 102 | break; 103 | } 104 | } 105 | while (true); 106 | 107 | return instances; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerBase/ConfigServerException.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | 17 | namespace Steeltoe.Extensions.Configuration.ConfigServer 18 | { 19 | /// 20 | /// Exception thrown by Config Server client when problems occur 21 | /// 22 | public class ConfigServerException : Exception 23 | { 24 | public ConfigServerException(string message, Exception error) 25 | : base(message, error) 26 | { 27 | } 28 | 29 | public ConfigServerException(string message) 30 | : base(message) 31 | { 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerBase/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Runtime.CompilerServices; 16 | 17 | [assembly: InternalsVisibleTo("Steeltoe.Extensions.Configuration.ConfigServerBase.Test")] 18 | [assembly: InternalsVisibleTo("Steeltoe.Extensions.Configuration.ConfigServerCore.Test")] 19 | [assembly: InternalsVisibleTo("Pivotal.Extensions.Configuration.ConfigServerBase.Test")] 20 | [assembly: InternalsVisibleTo("Pivotal.Extensions.Configuration.ConfigServerCore.Test")] 21 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerBase/PropertySource.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Collections.Generic; 16 | 17 | namespace Steeltoe.Extensions.Configuration.ConfigServer 18 | { 19 | public class PropertySource 20 | { 21 | public PropertySource() 22 | { 23 | } 24 | 25 | public PropertySource(string name, IDictionary properties) 26 | { 27 | Name = name; 28 | Source = properties; 29 | } 30 | 31 | public string Name { get; set; } 32 | 33 | public IDictionary Source { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerBase/README.md: -------------------------------------------------------------------------------- 1 | # Spring Cloud Config .NET Configuration Provider 2 | 3 | This project contains the [Spring Cloud Config Server](https://projects.spring.io/spring-cloud/docs/1.0.3/spring-cloud.html#_spring_cloud_config) client configuration provider. By acting as a client to the Spring Cloud Config Server, this provider enables the Config Server to become a source of configuration data for a .NET application. You can learn more about Cloud Native Applications and the Spring Cloud Config Server at [Spring Cloud](https://projects.spring.io/spring-cloud/docs/1.0.3/spring-cloud.html). 4 | 5 | For more information on how to use this component see the online [Steeltoe documentation](https://steeltoe.io/). -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerBase/SpringCloudConfigDiscovery.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.ConfigServer 16 | { 17 | public class SpringCloudConfigDiscovery 18 | { 19 | public bool Enabled { get; set; } = ConfigServerClientSettings.DEFAULT_DISCOVERY_ENABLED; 20 | 21 | public string ServiceId { get; set; } = ConfigServerClientSettings.DEFAULT_CONFIGSERVER_SERVICEID; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerBase/SpringCloudConfigHealth.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.ConfigServer 16 | { 17 | public class SpringCloudConfigHealth 18 | { 19 | public bool Enabled { get; set; } = ConfigServerClientSettings.DEFAULT_HEALTH_ENABLED; 20 | 21 | public long TimeToLive { get; set; } = ConfigServerClientSettings.DEFAULT_HEALTH_TIMETOLIVE; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerBase/SpringCloudConfigRetry.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.ConfigServer 16 | { 17 | public class SpringCloudConfigRetry 18 | { 19 | public bool Enabled { get; set; } = ConfigServerClientSettings.DEFAULT_RETRY_ENABLED; 20 | 21 | public int InitialInterval { get; set; } = ConfigServerClientSettings.DEFAULT_INITIAL_RETRY_INTERVAL; 22 | 23 | public int MaxInterval { get; set; } = ConfigServerClientSettings.DEFAULT_MAX_RETRY_INTERVAL; 24 | 25 | public double Multiplier { get; set; } = ConfigServerClientSettings.DEFAULT_RETRY_MULTIPLIER; 26 | 27 | public int MaxAttempts { get; set; } = ConfigServerClientSettings.DEFAULT_MAX_RETRY_ATTEMPTS; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerBase/Steeltoe.Extensions.Configuration.ConfigServerBase.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Spring Cloud Config Server Configuration Provider - Base Package 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.Extensions.Configuration.ConfigServerBase 10 | Steeltoe.Extensions.Configuration.ConfigServerBase 11 | Spring Cloud;Spring Cloud Config Server 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.Extensions.Configuration.ConfigServerBase.xml 21 | 22 | 23 | 24 | 25 | 26 | All 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591;618 42 | 43 | 44 | 45 | stylecop.json 46 | Always 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerCore/ConfigServerConfigurationBuilderExtensionsCore.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.Configuration; 17 | using Microsoft.Extensions.Logging; 18 | using System; 19 | 20 | namespace Steeltoe.Extensions.Configuration.ConfigServer 21 | { 22 | /// 23 | /// Extension methods for adding . 24 | /// 25 | public static class ConfigServerConfigurationBuilderExtensionsCore 26 | { 27 | public static IConfigurationBuilder AddConfigServer(this IConfigurationBuilder configurationBuilder, IHostingEnvironment environment, ILoggerFactory logFactory = null) 28 | { 29 | if (configurationBuilder == null) 30 | { 31 | throw new ArgumentNullException(nameof(configurationBuilder)); 32 | } 33 | 34 | if (environment == null) 35 | { 36 | throw new ArgumentNullException(nameof(environment)); 37 | } 38 | 39 | var settings = new ConfigServerClientSettings() 40 | { 41 | Name = environment.ApplicationName, 42 | Environment = environment.EnvironmentName 43 | }; 44 | 45 | return configurationBuilder.AddConfigServer(settings, logFactory); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerCore/ConfigServerHostBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.Logging; 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | namespace Steeltoe.Extensions.Configuration.ConfigServer 21 | { 22 | public static class ConfigServerHostBuilderExtensions 23 | { 24 | /// 25 | /// Add Config Server and Cloud Foundry as application configuration sources. Add Config Server health check 26 | /// contributor to the service container. 27 | /// 28 | /// 29 | /// 30 | /// with config server and Cloud Foundry Config Provider attached 31 | public static IWebHostBuilder AddConfigServer(this IWebHostBuilder hostBuilder, ILoggerFactory loggerFactory = null) 32 | { 33 | hostBuilder.ConfigureAppConfiguration((context, config) => 34 | { 35 | config.AddConfigServer(context.HostingEnvironment, loggerFactory); 36 | }); 37 | 38 | hostBuilder.ConfigureServices((services) => 39 | { 40 | services.AddConfigServerHealthContributor(); 41 | }); 42 | 43 | return hostBuilder; 44 | } 45 | 46 | /// 47 | /// Enable the application to listen on port(s) provided by the environment at runtime 48 | /// 49 | /// Your WebHostBuilder 50 | /// Set the port number with code so you don't need to set environment variables locally 51 | /// Your WebHostBuilder, now listening on port(s) found in the environment or passed in 52 | /// runLocalPort parameter will not be used if an environment variable PORT is found 53 | public static IWebHostBuilder UseCloudFoundryHosting(this IWebHostBuilder webHostBuilder, int? runLocalPort = null) 54 | { 55 | if (webHostBuilder == null) 56 | { 57 | throw new ArgumentNullException(nameof(webHostBuilder)); 58 | } 59 | 60 | List urls = new List(); 61 | 62 | string portStr = Environment.GetEnvironmentVariable("PORT"); 63 | if (!string.IsNullOrWhiteSpace(portStr)) 64 | { 65 | if (int.TryParse(portStr, out int port)) 66 | { 67 | urls.Add($"http://*:{port}"); 68 | } 69 | } 70 | else if (runLocalPort != null) 71 | { 72 | urls.Add($"http://*:{runLocalPort}"); 73 | } 74 | 75 | if (urls.Count > 0) 76 | { 77 | webHostBuilder.UseUrls(urls.ToArray()); 78 | } 79 | 80 | return webHostBuilder; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerCore/ConfigServerServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.DependencyInjection; 17 | using Microsoft.Extensions.DependencyInjection.Extensions; 18 | using Steeltoe.Common.HealthChecks; 19 | using System; 20 | 21 | namespace Steeltoe.Extensions.Configuration.ConfigServer 22 | { 23 | /// 24 | /// Extension methods for adding services related to Spring Cloud Config Server. 25 | /// 26 | public static class ConfigServerServiceCollectionExtensions 27 | { 28 | public static IServiceCollection ConfigureConfigServerClientOptions(this IServiceCollection services, IConfiguration config) 29 | { 30 | if (services == null) 31 | { 32 | throw new ArgumentNullException(nameof(services)); 33 | } 34 | 35 | if (config == null) 36 | { 37 | throw new ArgumentNullException(nameof(config)); 38 | } 39 | 40 | services.AddOptions(); 41 | 42 | var section = config.GetSection(ConfigServerClientSettingsOptions.CONFIGURATION_PREFIX); 43 | services.Configure(section); 44 | 45 | return services; 46 | } 47 | 48 | /// 49 | /// Add the ConfigServerHealthContributor as a IHealthContributor to the service container. 50 | /// 51 | /// the service container 52 | /// the service collection 53 | public static IServiceCollection AddConfigServerHealthContributor(this IServiceCollection services) 54 | { 55 | if (services == null) 56 | { 57 | throw new ArgumentNullException(nameof(services)); 58 | } 59 | 60 | services.AddSingleton(); 61 | 62 | return services; 63 | } 64 | 65 | [Obsolete("No longer necessary; IConfiguration added by default")] 66 | public static IServiceCollection AddConfiguration(this IServiceCollection services, IConfiguration config) 67 | { 68 | if (services == null) 69 | { 70 | throw new ArgumentNullException(nameof(services)); 71 | } 72 | 73 | if (config == null) 74 | { 75 | throw new ArgumentNullException(nameof(config)); 76 | } 77 | 78 | services.AddOptions(); 79 | 80 | services.TryAddSingleton(config); 81 | 82 | var root = config as IConfigurationRoot; 83 | if (root != null) 84 | { 85 | services.TryAddSingleton(root); 86 | } 87 | 88 | return services; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerCore/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Reflection; 16 | using System.Runtime.CompilerServices; 17 | using System.Runtime.InteropServices; 18 | 19 | [assembly: InternalsVisibleTo("Steeltoe.Extensions.Configuration.ConfigServerCore.Test")] 20 | [assembly: InternalsVisibleTo("Pivotal.Extensions.Configuration.ConfigServerCore.Test")] 21 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.ConfigServerCore/Steeltoe.Extensions.Configuration.ConfigServerCore.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | NET Core Spring Cloud Config Server Configuration Provider 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.Extensions.Configuration.ConfigServerCore 10 | Steeltoe.Extensions.Configuration.ConfigServerCore 11 | ASPNET Core;Spring;Spring Cloud;Config Server 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.Extensions.Configuration.ConfigServerCore.xml 21 | 22 | 23 | 24 | 25 | 26 | 27 | All 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 40 | 41 | 42 | 43 | stylecop.json 44 | Always 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.PlaceholderBase/PlaceholderResolverExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.Logging; 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | namespace Steeltoe.Extensions.Configuration.Placeholder 21 | { 22 | public static class PlaceholderResolverExtensions 23 | { 24 | /// 25 | /// Add a placeholder resolver configuration source to the . The placeholder resolver source will capture and wrap all 26 | /// the existing sources contained in the builder. The newly created source will then replace the existing sources 27 | /// and provide placeholder resolution for the configuration. Typically you will want to add this configuration source as the last one so that you wrap all 28 | /// of the applications configuration sources with place holder resolution. 29 | /// 30 | /// the configuration builder 31 | /// the logger factory to use 32 | /// builder 33 | public static IConfigurationBuilder AddPlaceholderResolver(this IConfigurationBuilder builder, ILoggerFactory loggerFactory = null) 34 | { 35 | if (builder == null) 36 | { 37 | throw new ArgumentNullException(nameof(builder)); 38 | } 39 | 40 | var resolver = new PlaceholderResolverSource(builder.Sources, loggerFactory); 41 | builder.Sources.Clear(); 42 | builder.Add(resolver); 43 | 44 | return builder; 45 | } 46 | 47 | /// 48 | /// Creates a new from a . The place holder resolver will be created using the existing 49 | /// configuration providers contained in the incoming configuration. This results in providing placeholder resolution for those configuration sources. 50 | /// 51 | /// incoming configuration to wrap 52 | /// the logger factory to use 53 | /// a new configuration 54 | public static IConfiguration AddPlaceholderResolver(this IConfiguration configuration, ILoggerFactory loggerFactory = null) 55 | { 56 | if (configuration == null) 57 | { 58 | throw new ArgumentNullException(nameof(configuration)); 59 | } 60 | 61 | var root = configuration as IConfigurationRoot; 62 | return new ConfigurationRoot(new List() { new PlaceholderResolverProvider(new List(root.Providers), loggerFactory) }); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.PlaceholderBase/PlaceholderResolverSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.Logging; 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | namespace Steeltoe.Extensions.Configuration 21 | { 22 | /// 23 | /// Configuration source used in creating a that resolves placeholders 24 | /// A placeholder takes the form of ${some:config:reference?default_if_not_present}> 25 | /// 26 | public class PlaceholderResolverSource : IConfigurationSource 27 | { 28 | internal ILoggerFactory _loggerFactory; 29 | 30 | internal IList _sources; 31 | 32 | /// 33 | /// Initializes a new instance of the class. 34 | /// 35 | /// the configuration sources to use 36 | /// the logger factory to use 37 | public PlaceholderResolverSource(IList sources, ILoggerFactory logFactory = null) 38 | { 39 | if (sources == null) 40 | { 41 | throw new ArgumentNullException(nameof(sources)); 42 | } 43 | 44 | _sources = new List(sources); 45 | _loggerFactory = logFactory; 46 | } 47 | 48 | /// 49 | /// Builds a from the sources. 50 | /// 51 | /// the provided builder 52 | /// the placeholder resolver provider 53 | public IConfigurationProvider Build(IConfigurationBuilder builder) 54 | { 55 | var providers = new List(); 56 | foreach (var source in _sources) 57 | { 58 | var provider = source.Build(builder); 59 | providers.Add(provider); 60 | } 61 | 62 | return new PlaceholderResolverProvider(providers, _loggerFactory); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.PlaceholderBase/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Runtime.CompilerServices; 16 | 17 | [assembly: InternalsVisibleTo("Steeltoe.Extensions.Configuration.PlaceholderBase.Test")] 18 | [assembly: InternalsVisibleTo("Steeltoe.Extensions.Configuration.PlaceholderCore.Test")] -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.PlaceholderBase/README.md: -------------------------------------------------------------------------------- 1 | # Configuration Placeholder Resolver .NET Configuration Provider 2 | 3 | This project contains a Placeholder resolver configuration provider. 4 | For more information on how to use this component see the online [Steeltoe documentation](https://steeltoe.io/). -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.PlaceholderBase/Steeltoe.Extensions.Configuration.PlaceholderBase.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Configuration Placeholder Resolver - Base Package 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.Extensions.Configuration.PlaceholderBase 10 | Steeltoe.Extensions.Configuration.PlaceholderBase 11 | Configuration;Placeholders 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.Extensions.Configuration.PlaceholderBase.xml 21 | 22 | 23 | 24 | 25 | 26 | All 27 | 28 | 29 | 30 | 31 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 32 | 33 | 34 | 35 | stylecop.json 36 | Always 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.PlaceholderCore/PlaceholderResolverExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.Configuration; 17 | using Microsoft.Extensions.DependencyInjection; 18 | using Microsoft.Extensions.DependencyInjection.Extensions; 19 | using Microsoft.Extensions.Logging; 20 | using Steeltoe.Extensions.Configuration.Placeholder; 21 | using System; 22 | 23 | namespace Steeltoe.Extensions.Configuration.PlaceholderCore 24 | { 25 | public static class PlaceholderResolverExtensions 26 | { 27 | /// 28 | /// Create a new using a which wraps the provided . 29 | /// The new configuration will then be used to replace the current in the service container. All subsequent requests for a 30 | /// will return the newly created one providing placeholder resolution. 31 | /// 32 | /// the current service container 33 | /// the configuration the placeholder resolver will wrap 34 | /// the log factory to use 35 | /// the new configuration 36 | public static IConfiguration ConfigurePlaceholderResolver(this IServiceCollection services, IConfiguration configuration, ILoggerFactory loggerFactory = null) 37 | { 38 | if (configuration == null) 39 | { 40 | throw new ArgumentNullException(nameof(configuration)); 41 | } 42 | 43 | var newConfig = configuration.AddPlaceholderResolver(loggerFactory); 44 | 45 | services.Replace(ServiceDescriptor.Singleton(typeof(IConfiguration), newConfig)); 46 | 47 | return newConfig; 48 | } 49 | 50 | /// 51 | /// Add a placeholder resolver configuration source to the . The placeholder resolver source will capture and wrap all 52 | /// the existing sources contained in the builder. The newly created source will then replace the existing sources 53 | /// and provide placeholder resolution for the configuration. Typically you will want to add this configuration source as the last one so that you wrap all 54 | /// of the applications configuration sources with place holder resolution. 55 | /// 56 | /// the host builder 57 | /// the log factory to use 58 | /// provided host builder 59 | public static IWebHostBuilder AddPlaceholderResolver(this IWebHostBuilder hostBuilder, ILoggerFactory loggerFactory = null) 60 | { 61 | hostBuilder.ConfigureAppConfiguration((context, builder) => 62 | { 63 | builder.AddPlaceholderResolver(loggerFactory); 64 | }); 65 | return hostBuilder; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.PlaceholderCore/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Runtime.CompilerServices; 16 | 17 | [assembly: InternalsVisibleTo("Steeltoe.Extensions.Configuration.PlaceholderBase.Test")] 18 | [assembly: InternalsVisibleTo("Steeltoe.Extensions.Configuration.PlaceholderCore.Test")] -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.PlaceholderCore/README.md: -------------------------------------------------------------------------------- 1 | # Configuration Placeholder Resolver .NET Configuration Provider 2 | 3 | This project contains a Placeholder resolver configuration provider. 4 | For more information on how to use this component see the online [Steeltoe documentation](https://steeltoe.io/). -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.PlaceholderCore/Steeltoe.Extensions.Configuration.PlaceholderCore.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Configuration Placeholder Resolver - Core Package 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.Extensions.Configuration.PlaceholderCore 10 | Steeltoe.Extensions.Configuration.PlaceholderCore 11 | Configuration;Placeholders 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.Extensions.Configuration.PlaceholderCore.xml 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | All 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 42 | 43 | 44 | 45 | stylecop.json 46 | Always 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.RandomValueBase/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Runtime.CompilerServices; 16 | 17 | [assembly: InternalsVisibleTo("Steeltoe.Extensions.Configuration.RandomValueBase.Test")] -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.RandomValueBase/README.md: -------------------------------------------------------------------------------- 1 | # Configuration Random Value Generator .NET Configuration Provider 2 | 3 | This project contains a Random Value configuration provider. 4 | For more information on how to use this component see the online [Steeltoe documentation](https://steeltoe.io/). -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.RandomValueBase/RandomValueExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.Logging; 17 | using System; 18 | 19 | namespace Steeltoe.Extensions.Configuration.RandomValue 20 | { 21 | public static class RandomValueExtensions 22 | { 23 | /// 24 | /// Add a random value configuration source to the . 25 | /// 26 | /// the configuration builder 27 | /// the logger factory to use 28 | /// builder 29 | public static IConfigurationBuilder AddRandomValueSource(this IConfigurationBuilder builder, ILoggerFactory loggerFactory = null) 30 | { 31 | if (builder == null) 32 | { 33 | throw new ArgumentNullException(nameof(builder)); 34 | } 35 | 36 | var resolver = new RandomValueSource(loggerFactory); 37 | builder.Add(resolver); 38 | 39 | return builder; 40 | } 41 | 42 | /// 43 | /// Add a random value configuration source to the . 44 | /// 45 | /// the configuration builder 46 | /// the prefix used for random key values, default 'random:' 47 | /// the logger factory to use 48 | /// builder 49 | public static IConfigurationBuilder AddRandomValueSource(this IConfigurationBuilder builder, string prefix, ILoggerFactory loggerFactory = null) 50 | { 51 | if (builder == null) 52 | { 53 | throw new ArgumentNullException(nameof(builder)); 54 | } 55 | 56 | if (string.IsNullOrEmpty(prefix)) 57 | { 58 | throw new ArgumentException(nameof(prefix)); 59 | } 60 | 61 | if (!prefix.EndsWith(":")) 62 | { 63 | prefix = prefix + ":"; 64 | } 65 | 66 | var resolver = new RandomValueSource(prefix, loggerFactory); 67 | builder.Add(resolver); 68 | 69 | return builder; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.RandomValueBase/RandomValueSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.Logging; 17 | 18 | namespace Steeltoe.Extensions.Configuration 19 | { 20 | /// 21 | /// Configuration source used in creating a that generates random numbers 22 | /// 23 | public class RandomValueSource : IConfigurationSource 24 | { 25 | public const string PREFIX = "random:"; 26 | internal ILoggerFactory _loggerFactory; 27 | internal string _prefix; 28 | 29 | /// 30 | /// Initializes a new instance of the class. 31 | /// 32 | /// the logger factory to use 33 | public RandomValueSource(ILoggerFactory logFactory = null) 34 | : this(PREFIX, logFactory) 35 | { 36 | } 37 | 38 | /// 39 | /// Initializes a new instance of the class. 40 | /// 41 | /// key prefix to use to match random number keys. Should end with the configuration seperator 42 | /// the logger factory to use 43 | public RandomValueSource(string prefix, ILoggerFactory logFactory = null) 44 | { 45 | _loggerFactory = logFactory; 46 | _prefix = prefix; 47 | } 48 | 49 | /// 50 | /// Builds a from the sources. 51 | /// 52 | /// the provided builder 53 | /// the random number provider 54 | public IConfigurationProvider Build(IConfigurationBuilder builder) 55 | { 56 | return new RandomValueProvider(_prefix, _loggerFactory); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Steeltoe.Extensions.Configuration.RandomValueBase/Steeltoe.Extensions.Configuration.RandomValueBase.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Random Value Provider - Base Package 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.Extensions.Configuration.RandomValueBase 10 | Steeltoe.Extensions.Configuration.RandomValueBase 11 | Configuration;Random Values 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.Extensions.Configuration.RandomValueBase.xml 21 | 22 | 23 | 24 | 25 | 26 | 27 | All 28 | 29 | 30 | 31 | 32 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 33 | 34 | 35 | 36 | stylecop.json 37 | Always 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /stylecop.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", 3 | "settings": { 4 | "documentationRules": { 5 | "copyrightText": "Copyright {copyrightYear} the original author or authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttps://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.", 6 | "xmlHeader": false, 7 | "variables": { 8 | "copyrightYear": "2017" 9 | }, 10 | "documentExposedElements": false, 11 | "documentInternalElements": false, 12 | "documentPrivateElements": false 13 | }, 14 | "indentation": { 15 | "useTabs": false, 16 | "indentationSize": 4 17 | }, 18 | "namingRules": { 19 | }, 20 | "orderingRules": { 21 | "usingDirectivesPlacement": "outsideNamespace", 22 | "systemUsingDirectivesFirst": false 23 | }, 24 | "readabilityRules": { 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /targetframework.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(NuGetPackageRoot)microsoft.targetingpack.netframework.v4.6.1/1.0.1/lib/net461/ 4 | https://dotnet.myget.org/F/dotnet-core/api/v3/index.json 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryAutofac.Test/CloudFoundryContainerBuilderExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Autofac; 16 | using Microsoft.Extensions.Configuration; 17 | using Microsoft.Extensions.Options; 18 | using Steeltoe.Common.Options.Autofac; 19 | using Steeltoe.Extensions.Configuration.CloudFoundry; 20 | using System; 21 | using System.Collections.Generic; 22 | using Xunit; 23 | 24 | namespace Steeltoe.Extensions.Configuration.CloudFoundryAutofac.Test 25 | { 26 | public class CloudFoundryContainerBuilderExtensionsTest 27 | { 28 | [Fact] 29 | public void RegisterCloudFoundryOptions_ThrowsNulls() 30 | { 31 | ContainerBuilder container = null; 32 | Assert.Throws(() => container.RegisterCloudFoundryOptions(null)); 33 | ContainerBuilder container2 = new ContainerBuilder(); 34 | Assert.Throws(() => container2.RegisterCloudFoundryOptions(null)); 35 | } 36 | 37 | [Fact] 38 | public void RegisterCloudFoundryOptions_Registers_AndBindsConfiguration() 39 | { 40 | ContainerBuilder container = new ContainerBuilder(); 41 | var dict = new Dictionary() 42 | { 43 | { "vcap:application:cf_api", "https://foo.bar/foo" }, 44 | { "vcap:application:application_id", "application_id" }, 45 | { "vcap:application:application_name", "application_name" }, 46 | { "vcap:services:p-config-server:0:name", "myConfigServer" }, 47 | { "vcap:services:p-config-server:0:plan", "myPlan" }, 48 | { "vcap:services:p-config-server:0:label", "myLabel" } 49 | }; 50 | 51 | IConfiguration config = new ConfigurationBuilder().AddInMemoryCollection(dict).Build(); 52 | container.RegisterOptions(); 53 | 54 | container.RegisterCloudFoundryOptions(config); 55 | var built = container.Build(); 56 | 57 | var service = built.Resolve>(); 58 | Assert.NotNull(service); 59 | Assert.NotNull(service.Value); 60 | Assert.Equal("https://foo.bar/foo", service.Value.CF_Api); 61 | Assert.Equal("application_name", service.Value.ApplicationName); 62 | Assert.Equal("application_id", service.Value.ApplicationId); 63 | 64 | var services = built.Resolve>(); 65 | Assert.NotNull(services); 66 | Assert.NotNull(services.Value); 67 | var s = services.Value.Services["p-config-server"]; 68 | Assert.NotNull(s); 69 | Assert.NotEmpty(s); 70 | var svc = s[0]; 71 | Assert.Equal("myLabel", svc.Label); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryAutofac.Test/Steeltoe.Extensions.Configuration.CloudFoundryAutofac.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | PreserveNewest 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | All 22 | 23 | 24 | 25 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 26 | 27 | 28 | 29 | stylecop.json 30 | Always 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryAutofac.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryBase.Test/AbstractServiceOptionsTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Text; 19 | using Xunit; 20 | 21 | namespace Steeltoe.Extensions.Configuration.CloudFoundry.Test 22 | { 23 | public class AbstractServiceOptionsTest 24 | { 25 | [Fact] 26 | public void Bind_ThrowsWithBadArguments() 27 | { 28 | var opt = new MySqlServiceOption(); 29 | Assert.Throws(() => opt.Bind(null, "foobar")); 30 | Assert.Throws(() => opt.Bind(new ConfigurationBuilder().Build(), null)); 31 | Assert.Throws(() => opt.Bind(new ConfigurationBuilder().Build(), string.Empty)); 32 | } 33 | 34 | [Fact] 35 | public void Bind_BindsConfiguration() 36 | { 37 | // Arrange 38 | var configJson = @" 39 | { 'vcap': { 40 | 'services' : { 41 | 'p-mysql': [ 42 | { 43 | 'name': 'mySql1', 44 | 'label': 'p-mysql', 45 | 'tags': [ 46 | 'mysql', 47 | 'relational' 48 | ], 49 | 'plan': '100mb-dev', 50 | 'credentials': { 51 | 'hostname': '192.168.0.97', 52 | 'port': 3306, 53 | 'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31', 54 | 'username': '9vD0Mtk3wFFuaaaY', 55 | 'password': 'Cjn4HsAiKV8sImst', 56 | 'uri': 'mysql://9vD0Mtk3wFFuaaaY:Cjn4HsAiKV8sImst@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true', 57 | 'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst' 58 | } 59 | }, 60 | { 61 | 'name': 'mySql2', 62 | 'label': 'p-mysql', 63 | 'tags': [ 64 | 'mysql', 65 | 'relational' 66 | ], 67 | 'plan': '100mb-dev', 68 | 'credentials': { 69 | 'hostname': '192.168.0.97', 70 | 'port': 3306, 71 | 'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31', 72 | 'username': '9vD0Mtk3wFFuaaaY', 73 | 'password': 'Cjn4HsAiKV8sImst', 74 | 'uri': 'mysql://9vD0Mtk3wFFuaaaY:Cjn4HsAiKV8sImst@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true', 75 | 'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst' 76 | } 77 | } 78 | ] 79 | } 80 | } 81 | }"; 82 | var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); 83 | var jsonSource = new JsonStreamConfigurationSource(memStream); 84 | var builder = new ConfigurationBuilder().Add(jsonSource); 85 | var config = builder.Build(); 86 | 87 | var opt = new MySqlServiceOption(); 88 | opt.Bind(config, "mySql2"); 89 | Assert.Equal("mySql2", opt.Name); 90 | Assert.Equal("p-mysql", opt.Label); 91 | 92 | var opt2 = new MySqlServiceOption(); 93 | opt2.Bind(config, "mySql1"); 94 | Assert.Equal("mySql1", opt2.Name); 95 | Assert.Equal("p-mysql", opt2.Label); 96 | } 97 | 98 | [Fact] 99 | public void Bind_DoesNotBindsConfiguration() 100 | { 101 | // Arrange 102 | var configJson = @" 103 | { 'foo': { 104 | 'bar' : { 105 | } 106 | } 107 | }"; 108 | var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); 109 | var jsonSource = new JsonStreamConfigurationSource(memStream); 110 | var builder = new ConfigurationBuilder().Add(jsonSource); 111 | var config = builder.Build(); 112 | 113 | var opt = new MySqlServiceOption(); 114 | opt.Bind(config, "mySql2"); 115 | Assert.NotEqual("mySql2", opt.Name); 116 | Assert.NotEqual("p-mysql", opt.Label); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryBase.Test/JsonStreamConfigurationSourceTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using System; 17 | using System.IO; 18 | using Xunit; 19 | 20 | namespace Steeltoe.Extensions.Configuration.CloudFoundry.Test 21 | { 22 | public class JsonStreamConfigurationSourceTest 23 | { 24 | [Fact] 25 | public void Constructor_Throws_StreamNull() 26 | { 27 | // Arrange 28 | MemoryStream stream = null; 29 | 30 | // Act and Assert 31 | var ex = Assert.Throws(() => new JsonStreamConfigurationSource(stream)); 32 | Assert.Contains(nameof(stream), ex.Message); 33 | } 34 | 35 | [Fact] 36 | public void Build_WithStreamSource_ReturnsExpected() 37 | { 38 | // Arrange 39 | var environment = @" 40 | { 41 | 42 | 'application_id': 'fa05c1a9-0fc1-4fbd-bae1-139850dec7a3', 43 | 'application_name': 'my-app', 44 | 'application_uris': [ 45 | 'my-app.10.244.0.34.xip.io' 46 | ], 47 | 'application_version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca', 48 | 'limits': { 49 | 'disk': 1024, 50 | 'fds': 16384, 51 | 'mem': 256 52 | }, 53 | 'name': 'my-app', 54 | 'space_id': '06450c72-4669-4dc6-8096-45f9777db68a', 55 | 'space_name': 'my-space', 56 | 'uris': [ 57 | 'my-app.10.244.0.34.xip.io', 58 | 'my-app2.10.244.0.34.xip.io' 59 | ], 60 | 'users': null, 61 | 'version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca' 62 | }"; 63 | var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(environment); 64 | var source = new JsonStreamConfigurationSource(memStream); 65 | var provider = new JsonStreamConfigurationProvider(source); 66 | ConfigurationBuilder builder = new ConfigurationBuilder(); 67 | builder.Add(source); 68 | var root = builder.Build(); 69 | 70 | Assert.Equal("fa05c1a9-0fc1-4fbd-bae1-139850dec7a3", root["application_id"]); 71 | Assert.Equal("1024", root["limits:disk"]); 72 | Assert.Equal("my-app.10.244.0.34.xip.io", root["uris:0"]); 73 | Assert.Equal("my-app2.10.244.0.34.xip.io", root["uris:1"]); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryBase.Test/MySqlCredentials.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.CloudFoundry.Test 16 | { 17 | public class MySqlCredentials 18 | { 19 | public string Hostname { get; set; } 20 | 21 | public int Port { get; set; } 22 | 23 | public string Name { get; set; } 24 | 25 | public string Username { get; set; } 26 | 27 | public string Password { get; set; } 28 | 29 | public string Uri { get; set; } 30 | 31 | public string JdbcUrl { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryBase.Test/MySqlServiceOption.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.CloudFoundry.Test 16 | { 17 | public class MySqlServiceOption : AbstractServiceOptions 18 | { 19 | public MySqlServiceOption() 20 | { 21 | } 22 | 23 | public MySqlCredentials Credentials { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryBase.Test/Steeltoe.Extensions.Configuration.CloudFoundryBase.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | PreserveNewest 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | All 23 | 24 | 25 | 26 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 27 | 28 | 29 | 30 | stylecop.json 31 | Always 32 | 33 | 34 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryBase.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryCore.Test/CloudFoundryHostBuilderExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Hosting; 16 | using System; 17 | using Xunit; 18 | 19 | namespace Steeltoe.Extensions.Configuration.CloudFoundry.Test 20 | { 21 | public class CloudFoundryHostBuilderExtensionsTest 22 | { 23 | [Fact] 24 | public void UseCloudFoundryHosting_ThrowsIfHostBuilderNull() 25 | { 26 | // Arrange 27 | IWebHostBuilder webHostBuilder = null; 28 | 29 | // Act and Assert 30 | var ex = Assert.Throws(() => CloudFoundryHostBuilderExtensions.UseCloudFoundryHosting(webHostBuilder)); 31 | Assert.Contains(nameof(webHostBuilder), ex.Message); 32 | } 33 | 34 | [Fact] 35 | public void UseCloudFoundryHosting_DoNotSetUrlsIfNull() 36 | { 37 | // Arrange 38 | Environment.SetEnvironmentVariable("PORT", null); 39 | var hostBuilder = new WebHostBuilder() 40 | .UseStartup() 41 | .UseKestrel(); 42 | 43 | // Act and Assert 44 | hostBuilder.UseCloudFoundryHosting(); 45 | using (hostBuilder.Build()) 46 | { 47 | // No-Op 48 | } 49 | } 50 | 51 | [Fact] 52 | public void UseCloudFoundryHosting_MakeSureThePortIsSet() 53 | { 54 | // Arrange 55 | Environment.SetEnvironmentVariable("PORT", "42"); 56 | var hostBuilder = new WebHostBuilder() 57 | .UseStartup() 58 | .UseKestrel(); 59 | 60 | // Act and Assert 61 | hostBuilder.UseCloudFoundryHosting(); 62 | using (hostBuilder.Build()) 63 | { 64 | // No-Op 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryCore.Test/MySqlCredentials.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.CloudFoundry.Test 16 | { 17 | public class MySqlCredentials 18 | { 19 | public string Hostname { get; set; } 20 | 21 | public int Port { get; set; } 22 | 23 | public string Name { get; set; } 24 | 25 | public string Username { get; set; } 26 | 27 | public string Password { get; set; } 28 | 29 | public string Uri { get; set; } 30 | 31 | public string JdbcUrl { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryCore.Test/MySqlServiceOption.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | namespace Steeltoe.Extensions.Configuration.CloudFoundry.Test 15 | { 16 | public class MySqlServiceOption : AbstractServiceOptions 17 | { 18 | public MySqlServiceOption() 19 | { 20 | } 21 | 22 | public MySqlCredentials Credentials { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryCore.Test/Steeltoe.Extensions.Configuration.CloudFoundryCore.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | PreserveNewest 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | All 25 | 26 | 27 | 28 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 29 | 30 | 31 | 32 | stylecop.json 33 | Always 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryCore.Test/TestServerStartup.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Builder; 16 | using Microsoft.AspNetCore.Hosting.Server.Features; 17 | using Microsoft.Extensions.DependencyInjection; 18 | using System.Collections.Generic; 19 | using Xunit; 20 | 21 | namespace Steeltoe.Extensions.Configuration.CloudFoundry.Test 22 | { 23 | public class TestServerStartup 24 | { 25 | public List ExpectedAddresses { get; set; } = new List(); 26 | 27 | public void ConfigureServices(IServiceCollection services) 28 | { 29 | services.AddMvc(); 30 | } 31 | 32 | public void Configure(IApplicationBuilder app) 33 | { 34 | var addresses = ExpectedAddresses; 35 | Assert.Equal(addresses, app.ServerFeatures.Get()?.Addresses); 36 | app.UseMvc(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryCore.Test/TestServerStartup42.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.CloudFoundry.Test 16 | { 17 | public class TestServerStartup42 : TestServerStartup 18 | { 19 | public TestServerStartup42() 20 | { 21 | this.ExpectedAddresses.Add("http://*:42"); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.CloudFoundryCore.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServer.ITest/ConfigServerDataAsOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.ConfigServer.ITest 16 | { 17 | public class ConfigServerDataAsOptions 18 | { 19 | public string Bar { get; set; } 20 | 21 | public string Foo { get; set; } 22 | 23 | public Info Info { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServer.ITest/HomeController.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Mvc; 16 | using Microsoft.Extensions.Options; 17 | using Steeltoe.Common.HealthChecks; 18 | using System; 19 | using System.Collections.Generic; 20 | 21 | namespace Steeltoe.Extensions.Configuration.ConfigServer.ITest 22 | { 23 | public class HomeController : Controller 24 | { 25 | private ConfigServerDataAsOptions _options; 26 | private IHealthContributor _health; 27 | 28 | public HomeController(IOptions options, IHealthContributor health) 29 | { 30 | _options = options.Value; 31 | _health = health; 32 | } 33 | 34 | [HttpGet] 35 | public string VerifyAsInjectedOptions() 36 | { 37 | if (_options != null) 38 | { 39 | return _options.Bar + _options.Foo + _options.Info?.Description + _options.Info?.Url; 40 | } 41 | else 42 | { 43 | return string.Empty; 44 | } 45 | } 46 | 47 | [HttpGet] 48 | public string Health() 49 | { 50 | if (_health != null) 51 | { 52 | var health = _health.Health(); 53 | health.Details.TryGetValue("propertySources", out object sourcelist); 54 | 55 | var nameList = ToCSV(sourcelist as IList); 56 | return health.Status.ToString() + "," + nameList; 57 | } 58 | else 59 | { 60 | return string.Empty; 61 | } 62 | } 63 | 64 | private object ToCSV(IList list) 65 | { 66 | string result = string.Empty; 67 | foreach (var name in list) 68 | { 69 | result += name + ","; 70 | } 71 | 72 | return result; 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServer.ITest/Info.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.Extensions.Configuration.ConfigServer.ITest 16 | { 17 | public class Info 18 | { 19 | public string Description { get; set; } 20 | 21 | public string Url { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServer.ITest/Steeltoe.Extensions.Configuration.ConfigServer.ITest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | All 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 41 | 42 | 43 | 44 | stylecop.json 45 | Always 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServer.ITest/TestServerStartup.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Builder; 16 | using Microsoft.AspNetCore.Hosting; 17 | using Microsoft.Extensions.Configuration; 18 | using Microsoft.Extensions.DependencyInjection; 19 | using Microsoft.Extensions.DependencyInjection.Extensions; 20 | using Steeltoe.Extensions.Configuration.ConfigServer.Test; 21 | using System.IO; 22 | 23 | namespace Steeltoe.Extensions.Configuration.ConfigServer.ITest 24 | { 25 | internal class TestServerStartup 26 | { 27 | public TestServerStartup(IConfiguration configuration) 28 | { 29 | Configuration = configuration; 30 | } 31 | 32 | public IConfiguration Configuration { get; set; } 33 | 34 | public void ConfigureServices(IServiceCollection services) 35 | { 36 | services.AddOptions(); 37 | services.Configure(Configuration); 38 | services.AddConfigServerHealthContributor(); 39 | services.AddMvc(); 40 | } 41 | 42 | public void Configure(IApplicationBuilder app) 43 | { 44 | var config = app.ApplicationServices.GetServices(); 45 | app.UseMvc(routes => 46 | { 47 | routes.MapRoute( 48 | name: "VerifyAsInjectedOptions", 49 | template: "{controller=Home}/{action=VerifyAsInjectedOptions}"); 50 | routes.MapRoute( 51 | name: "Health", 52 | template: "{controller=Home}/{action=Health}"); 53 | }); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServer.ITest/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerAutofac.Test/ConfigServerConfigurationBuilderExtensionsAutofacTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Steeltoe.Extensions.Configuration.ConfigServer; 17 | using System; 18 | using Xunit; 19 | 20 | namespace Steeltoe.Extensions.Configuration.ConfigServerAutofac.Test 21 | { 22 | public class ConfigServerConfigurationBuilderExtensionsAutofacTest 23 | { 24 | [Fact] 25 | public void AddConfigServer_ThrowsNulls() 26 | { 27 | ConfigurationBuilder builder = null; 28 | Assert.Throws(() => builder.AddConfigServer(null)); 29 | } 30 | 31 | [Fact] 32 | public void AddConfigServer_WithEnvAndName() 33 | { 34 | ConfigurationBuilder builder = new ConfigurationBuilder(); 35 | builder.AddConfigServer("foo", "bar"); 36 | 37 | ConfigServerConfigurationSource provider = null; 38 | foreach (IConfigurationSource source in builder.Sources) 39 | { 40 | provider = source as ConfigServerConfigurationSource; 41 | if (provider != null) 42 | { 43 | break; 44 | } 45 | } 46 | 47 | Assert.NotNull(provider); 48 | var settings = provider.DefaultSettings; 49 | Assert.NotNull(settings); 50 | Assert.Equal("foo", settings.Environment); 51 | Assert.Equal("bar", settings.Name); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerAutofac.Test/ConfigServerContainerBuilderExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Autofac; 16 | using Microsoft.Extensions.Configuration; 17 | using Microsoft.Extensions.Options; 18 | using Steeltoe.Common.Options.Autofac; 19 | using Steeltoe.Extensions.Configuration.ConfigServer; 20 | using System; 21 | using System.Collections.Generic; 22 | using Xunit; 23 | 24 | namespace Steeltoe.Extensions.Configuration.ConfigServerAutofac.Test 25 | { 26 | public class ConfigServerContainerBuilderExtensionsTest 27 | { 28 | [Fact] 29 | public void RegisterConfigServerClientOptions_ThrowsNulls() 30 | { 31 | ContainerBuilder container = null; 32 | Assert.Throws(() => container.RegisterConfigServerClientOptions(null)); 33 | ContainerBuilder container2 = new ContainerBuilder(); 34 | Assert.Throws(() => container2.RegisterConfigServerClientOptions(null)); 35 | } 36 | 37 | [Fact] 38 | public void RegisterConfigServerClientOptions_Registers_AndBindsConfiguration() 39 | { 40 | ContainerBuilder container = new ContainerBuilder(); 41 | var dict = new Dictionary() 42 | { 43 | { "spring:cloud:config:uri", "https://foo.bar/foo" }, 44 | { "spring:cloud:config:env", "env" }, 45 | { "spring:cloud:config:label", "label" }, 46 | { "spring:cloud:config:name", "name" }, 47 | { "spring:cloud:config:username", "username" }, 48 | { "spring:cloud:config:password", "password" } 49 | }; 50 | 51 | IConfiguration config = new ConfigurationBuilder().AddInMemoryCollection(dict).Build(); 52 | container.RegisterOptions(); 53 | 54 | container.RegisterConfigServerClientOptions(config); 55 | var built = container.Build(); 56 | 57 | var service = built.Resolve>(); 58 | Assert.NotNull(service); 59 | Assert.NotNull(service.Value); 60 | Assert.Equal("https://foo.bar/foo", service.Value.Uri); 61 | Assert.Equal("env", service.Value.Env); 62 | Assert.Equal("label", service.Value.Label); 63 | Assert.Equal("name", service.Value.Name); 64 | Assert.Equal("username", service.Value.Username); 65 | Assert.Equal("password", service.Value.Password); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerAutofac.Test/Steeltoe.Extensions.Configuration.ConfigServerAutofac.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | All 25 | 26 | 27 | 28 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 29 | 30 | 31 | 32 | stylecop.json 33 | Always 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerAutofac.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerBase.Test/ConfigServerConfigurationSourceTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.Configuration.Memory; 17 | using Microsoft.Extensions.Logging; 18 | using System; 19 | using System.Collections.Generic; 20 | using System.Linq; 21 | using System.Text; 22 | using Xunit; 23 | 24 | namespace Steeltoe.Extensions.Configuration.ConfigServer.Test 25 | { 26 | public class ConfigServerConfigurationSourceTest 27 | { 28 | [Fact] 29 | public void Constructors__ThrowsIfNulls() 30 | { 31 | // Arrange 32 | ConfigServerClientSettings settings = null; 33 | 34 | // Act and Assert 35 | var ex = Assert.Throws(() => new ConfigServerConfigurationSource((IConfiguration)null)); 36 | ex = Assert.Throws(() => new ConfigServerConfigurationSource(settings, (IConfiguration)null, null)); 37 | ex = Assert.Throws(() => new ConfigServerConfigurationSource((IList)null, null)); 38 | ex = Assert.Throws(() => new ConfigServerConfigurationSource(settings, new List(), null)); 39 | } 40 | 41 | [Fact] 42 | public void Constructors__InitializesProperties() 43 | { 44 | ConfigServerClientSettings settings = new ConfigServerClientSettings(); 45 | var memSource = new MemoryConfigurationSource(); 46 | IList sources = new List() { memSource }; 47 | ILoggerFactory factory = new LoggerFactory(); 48 | 49 | var source = new ConfigServerConfigurationSource(settings, sources, new Dictionary() { { "foo", "bar" } }, factory); 50 | Assert.Equal(settings, source.DefaultSettings); 51 | Assert.Equal(factory, source.LogFactory); 52 | Assert.Null(source.Configuration); 53 | Assert.NotSame(sources, source._sources); 54 | Assert.Single(source._sources); 55 | Assert.Equal(memSource, source._sources[0]); 56 | Assert.Single(source._properties); 57 | Assert.Equal("bar", source._properties["foo"]); 58 | 59 | var config = new ConfigurationBuilder().AddInMemoryCollection().Build(); 60 | source = new ConfigServerConfigurationSource(settings, config, factory); 61 | Assert.Equal(settings, source.DefaultSettings); 62 | Assert.Equal(factory, source.LogFactory); 63 | Assert.NotNull(source.Configuration); 64 | var root = source.Configuration as IConfigurationRoot; 65 | Assert.NotNull(root); 66 | Assert.Same(config, root); 67 | } 68 | 69 | [Fact] 70 | public void Build__ReturnsProvider() 71 | { 72 | // Arrange 73 | ConfigServerClientSettings settings = new ConfigServerClientSettings(); 74 | var memSource = new MemoryConfigurationSource(); 75 | IList sources = new List() { memSource }; 76 | ILoggerFactory factory = new LoggerFactory(); 77 | 78 | // Act and Assert 79 | var source = new ConfigServerConfigurationSource(settings, sources, null); 80 | var provider = source.Build(new ConfigurationBuilder()); 81 | Assert.IsType(provider); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerBase.Test/ConfigServerDiscoveryServiceTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using System.Collections.Generic; 17 | using Xunit; 18 | 19 | namespace Steeltoe.Extensions.Configuration.ConfigServer.Test 20 | { 21 | public class ConfigServerDiscoveryServiceTest 22 | { 23 | [Fact] 24 | public void FindGetInstancesMethod_FindsMethod() 25 | { 26 | var values = new Dictionary() 27 | { 28 | { "eureka:client:serviceUrl", "http://localhost:8761/eureka/" } 29 | }; 30 | var builder = new ConfigurationBuilder(); 31 | builder.AddInMemoryCollection(values); 32 | var config = builder.Build(); 33 | var settings = new ConfigServerClientSettings(); 34 | 35 | var service = new ConfigServerDiscoveryService(config, settings); 36 | Assert.NotNull(service.FindGetInstancesMethod()); 37 | } 38 | 39 | [Fact] 40 | public void InvokeGetInstances_ReturnsExpected() 41 | { 42 | var values = new Dictionary() 43 | { 44 | { "eureka:client:serviceUrl", "http://localhost:8761/eureka/" } 45 | }; 46 | var builder = new ConfigurationBuilder(); 47 | builder.AddInMemoryCollection(values); 48 | var config = builder.Build(); 49 | var settings = new ConfigServerClientSettings(); 50 | 51 | var service = new ConfigServerDiscoveryService(config, settings); 52 | var method = service.FindGetInstancesMethod(); 53 | 54 | var result = service.InvokeGetInstances(method); 55 | Assert.Empty(result); 56 | } 57 | 58 | [Fact] 59 | public void InvokeGetInstances_RetryEnabled_ReturnsExpected() 60 | { 61 | var values = new Dictionary() 62 | { 63 | { "eureka:client:serviceUrl", "https://foo.bar:8761/eureka/" } 64 | }; 65 | var builder = new ConfigurationBuilder(); 66 | builder.AddInMemoryCollection(values); 67 | var config = builder.Build(); 68 | var settings = new ConfigServerClientSettings() 69 | { 70 | RetryEnabled = true 71 | }; 72 | var service = new ConfigServerDiscoveryService(config, settings); 73 | var method = service.FindGetInstancesMethod(); 74 | 75 | var result = service.InvokeGetInstances(method); 76 | Assert.Empty(result); 77 | } 78 | 79 | [Fact] 80 | public void GetConfigServerInstances_ReturnsExpected() 81 | { 82 | var values = new Dictionary() 83 | { 84 | { "eureka:client:serviceUrl", "http://localhost:8761/eureka/" } 85 | }; 86 | var builder = new ConfigurationBuilder(); 87 | builder.AddInMemoryCollection(values); 88 | var config = builder.Build(); 89 | var settings = new ConfigServerClientSettings(); 90 | 91 | var service = new ConfigServerDiscoveryService(config, settings); 92 | var result = service.GetConfigServerInstances(); 93 | Assert.Empty(result); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerBase.Test/ConfigurationSettingsHelperTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Hosting.Internal; 16 | using Microsoft.Extensions.Configuration; 17 | 18 | using System; 19 | using System.Collections.Generic; 20 | using Xunit; 21 | 22 | namespace Steeltoe.Extensions.Configuration.ConfigServer.Test 23 | { 24 | public class ConfigurationSettingsHelperTest 25 | { 26 | [Fact] 27 | public void Initalize_ThrowsOnNulls() 28 | { 29 | // Arrange 30 | string configPrefix = null; 31 | ConfigServerClientSettings settings = null; 32 | IConfiguration config = null; 33 | 34 | // Act and Assert 35 | var ex = Assert.Throws(() => ConfigurationSettingsHelper.Initialize(configPrefix, settings, config)); 36 | Assert.Contains(nameof(configPrefix), ex.Message); 37 | ex = Assert.Throws(() => ConfigurationSettingsHelper.Initialize("foobar", settings, config)); 38 | Assert.Contains(nameof(settings), ex.Message); 39 | ex = Assert.Throws(() => ConfigurationSettingsHelper.Initialize("foobar", new ConfigServerClientSettings(), config)); 40 | Assert.Contains(nameof(config), ex.Message); 41 | } 42 | 43 | [Fact] 44 | public void Initialize_WithDefaultSettings() 45 | { 46 | // Arrange 47 | string prefix = "spring:cloud:config"; 48 | ConfigServerClientSettings settings = new ConfigServerClientSettings(); 49 | HostingEnvironment env = new HostingEnvironment(); 50 | IConfiguration config = new ConfigurationRoot(new List()); 51 | 52 | // Act and Assert 53 | ConfigurationSettingsHelper.Initialize(prefix, settings, config); 54 | TestHelpers.VerifyDefaults(settings); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerBase.Test/CustomCloudFoundrySettingsReader.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.Extensions.Configuration.CloudFoundry; 16 | using System; 17 | 18 | namespace Steeltoe.Extensions.Configuration.ConfigServer.Test 19 | { 20 | internal class CustomCloudFoundrySettingsReader : ICloudFoundrySettingsReader 21 | { 22 | public string ApplicationJson => throw new NotImplementedException(); 23 | 24 | public string InstanceId => throw new NotImplementedException(); 25 | 26 | public string InstanceIndex => throw new NotImplementedException(); 27 | 28 | public string InstanceInternalIp => throw new NotImplementedException(); 29 | 30 | public string InstanceIp => throw new NotImplementedException(); 31 | 32 | public string InstancePort => throw new NotImplementedException(); 33 | 34 | public string ServicesJson => throw new NotImplementedException(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerBase.Test/Steeltoe.Extensions.Configuration.ConfigServerBase.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | All 34 | 35 | 36 | 37 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 38 | 39 | 40 | 41 | stylecop.json 42 | Always 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerBase.Test/TestConfigServerStartup.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Builder; 16 | using Microsoft.AspNetCore.Http; 17 | 18 | namespace Steeltoe.Extensions.Configuration.ConfigServer.Test 19 | { 20 | public class TestConfigServerStartup 21 | { 22 | public static void Reset() 23 | { 24 | Response = null; 25 | ReturnStatus = new int[1] { 200 }; 26 | LastRequest = null; 27 | RequestCount = 0; 28 | Label = AppName = Env = string.Empty; 29 | } 30 | 31 | public TestConfigServerStartup() 32 | { 33 | } 34 | 35 | public static string Response { get; set; } 36 | 37 | public static int[] ReturnStatus { get; set; } = new int[1] { 200 }; 38 | 39 | public static HttpRequest LastRequest { get; set; } 40 | 41 | public static int RequestCount { get; set; } = 0; 42 | 43 | public static string Label { get; set; } = string.Empty; 44 | 45 | public static string AppName { get; set; } = string.Empty; 46 | 47 | public static string Env { get; set; } = string.Empty; 48 | 49 | public void Configure(IApplicationBuilder app) 50 | { 51 | app.Run(async context => 52 | { 53 | LastRequest = context.Request; 54 | context.Response.StatusCode = GetStatusCode(context.Request.Path); 55 | RequestCount++; 56 | if (context.Response.StatusCode == 200) 57 | { 58 | await context.Response.WriteAsync(Response); 59 | } 60 | }); 61 | } 62 | 63 | public int GetStatusCode(string path) 64 | { 65 | if (!string.IsNullOrEmpty(Label)) 66 | { 67 | if (!path.Contains(Label)) 68 | { 69 | return 404; 70 | } 71 | } 72 | 73 | if (!string.IsNullOrEmpty(Env)) 74 | { 75 | if (!path.Contains(Env)) 76 | { 77 | return 404; 78 | } 79 | } 80 | 81 | if (!string.IsNullOrEmpty(AppName)) 82 | { 83 | if (!path.Contains(AppName)) 84 | { 85 | return 404; 86 | } 87 | } 88 | 89 | return ReturnStatus[RequestCount]; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerBase.Test/TestHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.IO; 16 | using Xunit; 17 | 18 | namespace Steeltoe.Extensions.Configuration.ConfigServer.Test 19 | { 20 | public class TestHelpers 21 | { 22 | public static string CreateTempFile(string contents) 23 | { 24 | var tempFile = Path.GetTempFileName(); 25 | File.WriteAllText(tempFile, contents); 26 | return tempFile; 27 | } 28 | 29 | public static Stream StringToStream(string str) 30 | { 31 | var memStream = new MemoryStream(); 32 | var textWriter = new StreamWriter(memStream); 33 | textWriter.Write(str); 34 | textWriter.Flush(); 35 | memStream.Seek(0, SeekOrigin.Begin); 36 | 37 | return memStream; 38 | } 39 | 40 | public static string StreamToString(Stream stream) 41 | { 42 | stream.Seek(0, SeekOrigin.Begin); 43 | var reader = new StreamReader(stream); 44 | 45 | return reader.ReadToEnd(); 46 | } 47 | 48 | public static void VerifyDefaults(ConfigServerClientSettings settings) 49 | { 50 | Assert.Equal(ConfigServerClientSettings.DEFAULT_PROVIDER_ENABLED, settings.Enabled); 51 | Assert.Equal(ConfigServerClientSettings.DEFAULT_FAILFAST, settings.FailFast); 52 | Assert.Equal(ConfigServerClientSettings.DEFAULT_URI, settings.Uri); 53 | Assert.Equal(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, settings.Environment); 54 | Assert.Equal(ConfigServerClientSettings.DEFAULT_ACCESS_TOKEN_URI, settings.AccessTokenUri); 55 | Assert.Equal(ConfigServerClientSettings.DEFAULT_CLIENT_ID, settings.ClientId); 56 | Assert.Equal(ConfigServerClientSettings.DEFAULT_CLIENT_SECRET, settings.ClientSecret); 57 | Assert.Equal(ConfigServerClientSettings.DEFAULT_CERTIFICATE_VALIDATION, settings.ValidateCertificates); 58 | Assert.Equal(ConfigServerClientSettings.DEFAULT_INITIAL_RETRY_INTERVAL, settings.RetryInitialInterval); 59 | Assert.Equal(ConfigServerClientSettings.DEFAULT_MAX_RETRY_ATTEMPTS, settings.RetryAttempts); 60 | Assert.Equal(ConfigServerClientSettings.DEFAULT_RETRY_ENABLED, settings.RetryEnabled); 61 | Assert.Equal(ConfigServerClientSettings.DEFAULT_RETRY_MULTIPLIER, settings.RetryMultiplier); 62 | Assert.Equal(ConfigServerClientSettings.DEFAULT_MAX_RETRY_INTERVAL, settings.RetryMaxInterval); 63 | Assert.Equal(ConfigServerClientSettings.DEFAULT_TIMEOUT_MILLISECONDS, settings.Timeout); 64 | Assert.Equal(ConfigServerClientSettings.DEFAULT_VAULT_TOKEN_RENEW_RATE, settings.TokenRenewRate); 65 | Assert.Equal(ConfigServerClientSettings.DEFAULT_VAULT_TOKEN_TTL, settings.TokenTtl); 66 | Assert.Equal(ConfigServerClientSettings.DEFAULT_DISCOVERY_ENABLED, settings.DiscoveryEnabled); 67 | Assert.Equal(ConfigServerClientSettings.DEFAULT_CONFIGSERVER_SERVICEID, settings.DiscoveryServiceId); 68 | Assert.Equal(ConfigServerClientSettings.DEFAULT_HEALTH_ENABLED, settings.HealthEnabled); 69 | Assert.Equal(ConfigServerClientSettings.DEFAULT_HEALTH_TIMETOLIVE, settings.HealthTimeToLive); 70 | Assert.Null(settings.Name); 71 | Assert.Null(settings.Label); 72 | Assert.Null(settings.Username); 73 | Assert.Null(settings.Password); 74 | Assert.Null(settings.Token); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerBase.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerCore.Test/ConfigServerClientSettingsOptionsTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Hosting.Internal; 16 | using Microsoft.Extensions.Configuration; 17 | using Microsoft.Extensions.DependencyInjection; 18 | using Microsoft.Extensions.Options; 19 | using Steeltoe.Extensions.Configuration.ConfigServer; 20 | using Xunit; 21 | 22 | namespace Steeltoe.Extensions.Configuration.ConfigServerCore.Test 23 | { 24 | public class ConfigServerClientSettingsOptionsTest 25 | { 26 | [Fact] 27 | public void ConfigureConfigServerClientSettingsOptions_WithDefaults() 28 | { 29 | // Arrange 30 | var services = new ServiceCollection().AddOptions(); 31 | var environment = new HostingEnvironment(); 32 | 33 | // Act and Assert 34 | var builder = new ConfigurationBuilder().AddConfigServer(environment); 35 | var config = builder.Build(); 36 | 37 | services.ConfigureConfigServerClientOptions(config); 38 | var service = services.BuildServiceProvider().GetService>(); 39 | Assert.NotNull(service); 40 | var options = service.Value; 41 | Assert.NotNull(options); 42 | TestHelpers.VerifyDefaults(options.Settings); 43 | 44 | Assert.Equal(ConfigServerClientSettings.DEFAULT_PROVIDER_ENABLED, options.Enabled); 45 | Assert.Equal(ConfigServerClientSettings.DEFAULT_FAILFAST, options.FailFast); 46 | Assert.Equal(ConfigServerClientSettings.DEFAULT_URI, options.Uri); 47 | Assert.Equal(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, options.Environment); 48 | Assert.Equal(ConfigServerClientSettings.DEFAULT_ACCESS_TOKEN_URI, options.AccessTokenUri); 49 | Assert.Equal(ConfigServerClientSettings.DEFAULT_CLIENT_ID, options.ClientId); 50 | Assert.Equal(ConfigServerClientSettings.DEFAULT_CLIENT_SECRET, options.ClientSecret); 51 | Assert.Equal(ConfigServerClientSettings.DEFAULT_CERTIFICATE_VALIDATION, options.ValidateCertificates); 52 | Assert.Equal(ConfigServerClientSettings.DEFAULT_INITIAL_RETRY_INTERVAL, options.RetryInitialInterval); 53 | Assert.Equal(ConfigServerClientSettings.DEFAULT_MAX_RETRY_ATTEMPTS, options.RetryAttempts); 54 | Assert.Equal(ConfigServerClientSettings.DEFAULT_RETRY_ENABLED, options.RetryEnabled); 55 | Assert.Equal(ConfigServerClientSettings.DEFAULT_RETRY_MULTIPLIER, options.RetryMultiplier); 56 | Assert.Equal(ConfigServerClientSettings.DEFAULT_MAX_RETRY_INTERVAL, options.RetryMaxInterval); 57 | Assert.Equal(ConfigServerClientSettings.DEFAULT_TIMEOUT_MILLISECONDS, options.Timeout); 58 | Assert.Equal(ConfigServerClientSettings.DEFAULT_VAULT_TOKEN_RENEW_RATE, options.TokenRenewRate); 59 | Assert.Equal(ConfigServerClientSettings.DEFAULT_VAULT_TOKEN_TTL, options.TokenTtl); 60 | Assert.Equal(ConfigServerClientSettings.DEFAULT_DISCOVERY_ENABLED, options.DiscoveryEnabled); 61 | Assert.Equal(ConfigServerClientSettings.DEFAULT_CONFIGSERVER_SERVICEID, options.DiscoveryServiceId); 62 | Assert.Null(options.Name); 63 | Assert.Null(options.Label); 64 | Assert.Null(options.Username); 65 | Assert.Null(options.Password); 66 | Assert.Null(options.Token); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerCore.Test/Steeltoe.Extensions.Configuration.ConfigServerCore.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | All 30 | 31 | 32 | 33 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 34 | 35 | 36 | 37 | stylecop.json 38 | Always 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerCore.Test/TestConfigServerStartup.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Builder; 16 | using Microsoft.AspNetCore.Http; 17 | 18 | namespace Steeltoe.Extensions.Configuration.ConfigServerCore.Test 19 | { 20 | public class TestConfigServerStartup 21 | { 22 | public TestConfigServerStartup() 23 | { 24 | LastRequest = null; 25 | } 26 | 27 | public static string Response { get; set; } 28 | 29 | public static int ReturnStatus { get; set; } = 200; 30 | 31 | public static HttpRequest LastRequest { get; set; } 32 | 33 | public static int RequestCount { get; set; } = 0; 34 | 35 | public void Configure(IApplicationBuilder app) 36 | { 37 | app.Run(async context => 38 | { 39 | LastRequest = context.Request; 40 | RequestCount++; 41 | context.Response.StatusCode = ReturnStatus; 42 | await context.Response.WriteAsync(Response); 43 | }); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerCore.Test/TestHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Builder; 16 | using Microsoft.AspNetCore.Http; 17 | using Steeltoe.Extensions.Configuration.ConfigServer; 18 | using System.IO; 19 | using Xunit; 20 | 21 | namespace Steeltoe.Extensions.Configuration.ConfigServerCore.Test 22 | { 23 | public class TestHelpers 24 | { 25 | public static string CreateTempFile(string contents) 26 | { 27 | var tempFile = Path.GetTempFileName(); 28 | File.WriteAllText(tempFile, contents); 29 | return tempFile; 30 | } 31 | 32 | public static Stream StringToStream(string str) 33 | { 34 | var memStream = new MemoryStream(); 35 | var textWriter = new StreamWriter(memStream); 36 | textWriter.Write(str); 37 | textWriter.Flush(); 38 | memStream.Seek(0, SeekOrigin.Begin); 39 | 40 | return memStream; 41 | } 42 | 43 | public static string StreamToString(Stream stream) 44 | { 45 | stream.Seek(0, SeekOrigin.Begin); 46 | var reader = new StreamReader(stream); 47 | 48 | return reader.ReadToEnd(); 49 | } 50 | 51 | public static void VerifyDefaults(ConfigServerClientSettings settings) 52 | { 53 | Assert.Equal(ConfigServerClientSettings.DEFAULT_PROVIDER_ENABLED, settings.Enabled); 54 | Assert.Equal(ConfigServerClientSettings.DEFAULT_FAILFAST, settings.FailFast); 55 | Assert.Equal(ConfigServerClientSettings.DEFAULT_URI, settings.Uri); 56 | Assert.Equal(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, settings.Environment); 57 | Assert.Equal(ConfigServerClientSettings.DEFAULT_CERTIFICATE_VALIDATION, settings.ValidateCertificates); 58 | Assert.Equal(ConfigServerClientSettings.DEFAULT_INITIAL_RETRY_INTERVAL, settings.RetryInitialInterval); 59 | Assert.Equal(ConfigServerClientSettings.DEFAULT_MAX_RETRY_ATTEMPTS, settings.RetryAttempts); 60 | Assert.Equal(ConfigServerClientSettings.DEFAULT_RETRY_ENABLED, settings.RetryEnabled); 61 | Assert.Equal(ConfigServerClientSettings.DEFAULT_RETRY_MULTIPLIER, settings.RetryMultiplier); 62 | Assert.Equal(ConfigServerClientSettings.DEFAULT_MAX_RETRY_INTERVAL, settings.RetryMaxInterval); 63 | Assert.Equal(ConfigServerClientSettings.DEFAULT_TIMEOUT_MILLISECONDS, settings.Timeout); 64 | Assert.Equal(ConfigServerClientSettings.DEFAULT_VAULT_TOKEN_RENEW_RATE, settings.TokenRenewRate); 65 | Assert.Equal(ConfigServerClientSettings.DEFAULT_VAULT_TOKEN_TTL, settings.TokenTtl); 66 | Assert.Equal(ConfigServerClientSettings.DEFAULT_DISCOVERY_ENABLED, settings.DiscoveryEnabled); 67 | Assert.Equal(ConfigServerClientSettings.DEFAULT_CONFIGSERVER_SERVICEID, settings.DiscoveryServiceId); 68 | Assert.Null(settings.Name); 69 | Assert.Null(settings.Label); 70 | Assert.Null(settings.Username); 71 | Assert.Null(settings.Password); 72 | Assert.Null(settings.Token); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.ConfigServerCore.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.PlaceholderBase.Test/PlaceholderResolverSourceTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.Configuration.Memory; 17 | using Microsoft.Extensions.Logging; 18 | using System; 19 | using System.Collections.Generic; 20 | using System.Linq; 21 | using System.Text; 22 | using Xunit; 23 | 24 | namespace Steeltoe.Extensions.Configuration.Placeholder.Test 25 | { 26 | public class PlaceholderResolverSourceTest 27 | { 28 | [Fact] 29 | public void Constructor_ThrowsIfNulls() 30 | { 31 | // Arrange 32 | IList sources = null; 33 | 34 | // Act and Assert 35 | var ex = Assert.Throws(() => new PlaceholderResolverSource(sources)); 36 | } 37 | 38 | [Fact] 39 | public void Constructors__InitializesProperties() 40 | { 41 | var memSource = new MemoryConfigurationSource(); 42 | IList sources = new List() { memSource }; 43 | ILoggerFactory factory = new LoggerFactory(); 44 | 45 | var source = new PlaceholderResolverSource(sources, factory); 46 | Assert.Equal(factory, source._loggerFactory); 47 | Assert.NotNull(source._sources); 48 | Assert.Single(source._sources); 49 | Assert.NotSame(sources, source._sources); 50 | Assert.Contains(memSource, source._sources); 51 | } 52 | 53 | [Fact] 54 | public void Build__ReturnsProvider() 55 | { 56 | // Arrange 57 | var memSource = new MemoryConfigurationSource(); 58 | IList sources = new List() { memSource }; 59 | ILoggerFactory factory = new LoggerFactory(); 60 | 61 | // Act and Assert 62 | var source = new PlaceholderResolverSource(sources, null); 63 | var provider = source.Build(new ConfigurationBuilder()); 64 | Assert.IsType(provider); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.PlaceholderBase.Test/Steeltoe.Extensions.Configuration.PlaceholderBase.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | All 31 | 32 | 33 | 34 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 35 | 36 | 37 | 38 | stylecop.json 39 | Always 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.PlaceholderBase.Test/TestHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.IO; 16 | using Xunit; 17 | 18 | namespace Steeltoe.Extensions.Configuration.Placeholder.Test 19 | { 20 | public class TestHelpers 21 | { 22 | public static string CreateTempFile(string contents) 23 | { 24 | var tempFile = Path.GetTempFileName(); 25 | File.WriteAllText(tempFile, contents); 26 | return tempFile; 27 | } 28 | 29 | public static Stream StringToStream(string str) 30 | { 31 | var memStream = new MemoryStream(); 32 | var textWriter = new StreamWriter(memStream); 33 | textWriter.Write(str); 34 | textWriter.Flush(); 35 | memStream.Seek(0, SeekOrigin.Begin); 36 | 37 | return memStream; 38 | } 39 | 40 | public static string StreamToString(Stream stream) 41 | { 42 | stream.Seek(0, SeekOrigin.Begin); 43 | var reader = new StreamReader(stream); 44 | 45 | return reader.ReadToEnd(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.PlaceholderBase.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.PlaceholderCore.Test/Steeltoe.Extensions.Configuration.PlaceholderCore.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | PreserveNewest 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | All 27 | 28 | 29 | 30 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 31 | 32 | 33 | 34 | stylecop.json 35 | Always 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.PlaceholderCore.Test/TestHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.IO; 16 | using Xunit; 17 | 18 | namespace Steeltoe.Extensions.Configuration.PlaceholderCore.Test 19 | { 20 | public class TestHelpers 21 | { 22 | public static string CreateTempFile(string contents) 23 | { 24 | var tempFile = Path.GetTempFileName(); 25 | File.WriteAllText(tempFile, contents); 26 | return tempFile; 27 | } 28 | 29 | public static Stream StringToStream(string str) 30 | { 31 | var memStream = new MemoryStream(); 32 | var textWriter = new StreamWriter(memStream); 33 | textWriter.Write(str); 34 | textWriter.Flush(); 35 | memStream.Seek(0, SeekOrigin.Begin); 36 | 37 | return memStream; 38 | } 39 | 40 | public static string StreamToString(Stream stream) 41 | { 42 | stream.Seek(0, SeekOrigin.Begin); 43 | var reader = new StreamReader(stream); 44 | 45 | return reader.ReadToEnd(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.PlaceholderCore.Test/TestServerStartup.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Builder; 16 | using Microsoft.Extensions.Configuration; 17 | using Microsoft.Extensions.DependencyInjection; 18 | using System; 19 | 20 | namespace Steeltoe.Extensions.Configuration.PlaceholderCore.Test 21 | { 22 | public class TestServerStartup 23 | { 24 | public static IServiceProvider ServiceProvider { get; set; } 25 | 26 | private IConfiguration _configuration; 27 | 28 | public TestServerStartup(IConfiguration config) 29 | { 30 | _configuration = config; 31 | } 32 | 33 | public void ConfigureServices(IServiceCollection services) 34 | { 35 | services.ConfigurePlaceholderResolver(_configuration); 36 | } 37 | 38 | public void Configure(IApplicationBuilder app) 39 | { 40 | ServiceProvider = app.ApplicationServices; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.PlaceholderCore.Test/TestServerStartup1.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.AspNetCore.Builder; 16 | using Microsoft.Extensions.Configuration; 17 | using Microsoft.Extensions.DependencyInjection; 18 | using System; 19 | 20 | namespace Steeltoe.Extensions.Configuration.PlaceholderCore.Test 21 | { 22 | public class TestServerStartup1 23 | { 24 | public static IServiceProvider ServiceProvider { get; set; } 25 | 26 | public TestServerStartup1(IConfiguration config) 27 | { 28 | } 29 | 30 | public void ConfigureServices(IServiceCollection services) 31 | { 32 | } 33 | 34 | public void Configure(IApplicationBuilder app) 35 | { 36 | ServiceProvider = app.ApplicationServices; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.PlaceholderCore.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.RandomValuesBase.Test/RandomValueProviderTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using Xunit; 17 | 18 | namespace Steeltoe.Extensions.Configuration.RandomValue.Test 19 | { 20 | public class RandomValueProviderTest 21 | { 22 | [Fact] 23 | public void Constructor__ThrowsIfPrefixNull() 24 | { 25 | // Act and Assert 26 | var ex = Assert.Throws(() => new RandomValueProvider(null, null)); 27 | } 28 | 29 | [Fact] 30 | public void TryGet_Ignores() 31 | { 32 | var prov = new RandomValueProvider("random:"); 33 | prov.TryGet("foo:bar", out string value); 34 | Assert.Null(value); 35 | } 36 | 37 | [Fact] 38 | public void TryGet_String() 39 | { 40 | var prov = new RandomValueProvider("random:"); 41 | prov.TryGet("random:string", out string value); 42 | Assert.NotNull(value); 43 | } 44 | 45 | [Fact] 46 | public void TryGet_Uuid() 47 | { 48 | var prov = new RandomValueProvider("random:"); 49 | prov.TryGet("random:uuid", out string value); 50 | Assert.NotNull(value); 51 | } 52 | 53 | [Fact] 54 | public void TryGet_RandomInt() 55 | { 56 | var prov = new RandomValueProvider("random:"); 57 | prov.TryGet("random:int", out string value); 58 | Assert.NotNull(value); 59 | } 60 | 61 | [Fact] 62 | public void TryGet_RandomIntRange() 63 | { 64 | var prov = new RandomValueProvider("random:"); 65 | prov.TryGet("random:int[4,10]", out string value); 66 | Assert.NotNull(value); 67 | int val = int.Parse(value); 68 | Assert.InRange(val, 4, 10); 69 | } 70 | 71 | [Fact] 72 | public void TryGet_RandomIntMax() 73 | { 74 | var prov = new RandomValueProvider("random:"); 75 | prov.TryGet("random:int(10)", out string value); 76 | Assert.NotNull(value); 77 | int val = int.Parse(value); 78 | Assert.InRange(val, 0, 10); 79 | } 80 | 81 | [Fact] 82 | public void TryGet_RandomLong() 83 | { 84 | var prov = new RandomValueProvider("random:"); 85 | prov.TryGet("random:long", out string value); 86 | Assert.NotNull(value); 87 | } 88 | 89 | [Fact] 90 | public void TryGet_RandomLongRange() 91 | { 92 | var prov = new RandomValueProvider("random:"); 93 | prov.TryGet("random:long[4,10]", out string value); 94 | Assert.NotNull(value); 95 | int val = int.Parse(value); 96 | Assert.InRange(val, 4, 10); 97 | } 98 | 99 | [Fact] 100 | public void TryGet_RandomLongMax() 101 | { 102 | var prov = new RandomValueProvider("random:"); 103 | prov.TryGet("random:long(10)", out string value); 104 | Assert.NotNull(value); 105 | int val = int.Parse(value); 106 | Assert.InRange(val, 0, 10); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.RandomValuesBase.Test/RandomValueSourceTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.Logging; 17 | using Xunit; 18 | 19 | namespace Steeltoe.Extensions.Configuration.RandomValue.Test 20 | { 21 | public class RandomValueSourceTest 22 | { 23 | [Fact] 24 | public void Constructors__InitializesDefaults() 25 | { 26 | ILoggerFactory factory = new LoggerFactory(); 27 | 28 | var source = new RandomValueSource(factory); 29 | Assert.Equal(factory, source._loggerFactory); 30 | Assert.NotNull(source._prefix); 31 | Assert.Equal(RandomValueSource.PREFIX, source._prefix); 32 | 33 | source = new RandomValueSource("foobar:", factory); 34 | Assert.Equal(factory, source._loggerFactory); 35 | Assert.NotNull(source._prefix); 36 | Assert.Equal("foobar:", source._prefix); 37 | } 38 | 39 | [Fact] 40 | public void Build__ReturnsProvider() 41 | { 42 | // Arrange 43 | ILoggerFactory factory = new LoggerFactory(); 44 | 45 | // Act and Assert 46 | var source = new RandomValueSource(); 47 | var provider = source.Build(new ConfigurationBuilder()); 48 | Assert.IsType(provider); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.RandomValuesBase.Test/Steeltoe.Extensions.Configuration.RandomValueBase.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | All 26 | 27 | 28 | 29 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 30 | 31 | 32 | 33 | stylecop.json 34 | Always 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/Steeltoe.Extensions.Configuration.RandomValuesBase.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /versions.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | --------------------------------------------------------------------------------