Skip to content

Commit d4c0750

Browse files
authored
Merge branch 'master' into fix/100-fix-github-powershell-scripts
2 parents 5eb40cc + eb21d76 commit d4c0750

File tree

20 files changed

+1358
-117
lines changed

20 files changed

+1358
-117
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,5 @@ FodyWeavers.xsd
365365
#
366366
Deploy/
367367

368-
App.*.config
369-
WtfIsThis.cs
370368
.idea/
371369
.AssemblyAttributes
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using MFDLabs.Text.Extensions;
3+
using MFDLabs.Reflection.Extensions;
4+
5+
#nullable enable
6+
7+
namespace MFDLabs.Configuration.Extensions
8+
{
9+
public static class SettingExtensions
10+
{
11+
// There's a special kind of var here that does like this:
12+
// ${{ env.VAR_NAME }}, which is a special kind of var that will be replaced with the value of the environment variable VAR_NAME.
13+
// This is useful when you want to pass the value of an environment variable to a command.
14+
// We have to parse this out, and replace it with the value of the environment variable.
15+
public static TResult? FromEnvironmentExpression<TResult>(this object setting)
16+
{
17+
if (setting is not string str) return default;
18+
if (str.IsNullOrEmpty()) return str.To<TResult>();
19+
20+
// Trim the input
21+
str = str.Trim();
22+
23+
// Remove the spaces from the input.
24+
str = str.Replace(" ", "");
25+
26+
// Check if the input contains the special var
27+
if (!str.StartsWith("${{")) return str.To<TResult>();
28+
29+
// Split the input into parts
30+
var parts = str.Split(new[] { "${{" }, StringSplitOptions.None);
31+
32+
// We now need to get the part in the middle of ${{ }}
33+
var otherPart = parts[1];
34+
35+
// Split the middle part into parts
36+
var middleParts = otherPart.Split(new[] { "}}" }, StringSplitOptions.None);
37+
38+
// Get the name of the environment variable
39+
var middlePart = middleParts[0];
40+
41+
// Check if the middle part starts with env.
42+
if (!middlePart.ToLower().StartsWith("env.")) return str.To<TResult>();
43+
44+
// Get the env var name
45+
var envVarName = middlePart.Remove(0, 4);
46+
47+
// Check if the env var is empty
48+
if (envVarName.IsNullOrWhiteSpace()) return str.To<TResult>();
49+
50+
// Get the env var value
51+
var env = Environment.GetEnvironmentVariable(envVarName);
52+
53+
// Check if the env var value is empty, if so, return the original string
54+
if (env.IsNullOrEmpty()) return str.To<TResult>();
55+
56+
// Replace the env var value with the env var name
57+
return env.To<TResult>();
58+
}
59+
}
60+
}

Assemblies/MFDLabs.Configuration/MFDLabs.Configuration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<ProjectReference Include="..\MFDLabs.Hashicorp.ConsulClient\MFDLabs.Hashicorp.ConsulClient.csproj" />
4747
<ProjectReference Include="..\MFDLabs.Hashicorp.VaultClient\MFDLabs.Hashicorp.VaultClient.csproj" />
4848
<ProjectReference Include="..\MFDLabs.Logging\MFDLabs.Logging.csproj" />
49+
<ProjectReference Include="..\MFDLabs.Reflection\MFDLabs.Reflection.csproj" />
4950
<ProjectReference Include="..\MFDLabs.Text\MFDLabs.Text.csproj" />
5051
<ProjectReference Include="..\MFDLabs.Threading\MFDLabs.Threading.csproj" />
5152
</ItemGroup>

Assemblies/MFDLabs.Configuration/Providers/VaultProvider.cs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
using System;
2+
using System.IO;
23
using System.Text;
34
using System.Linq;
4-
using System.IO;
5-
using System.Collections.Concurrent;
5+
using System.Configuration;
66
using System.Collections.Generic;
7+
using System.Collections.Concurrent;
78
using System.Collections.Specialized;
8-
using System.Configuration;
99
using MFDLabs.Threading;
10-
using MFDLabs.Configuration.Sections.Vault;
11-
using MFDLabs.Configuration.Clients.Vault;
12-
using MFDLabs.Configuration.Logging;
1310
using MFDLabs.Text.Extensions;
11+
using MFDLabs.Configuration.Logging;
12+
using MFDLabs.Configuration.Extensions;
13+
using MFDLabs.Configuration.Clients.Vault;
14+
using MFDLabs.Configuration.Sections.Vault;
1415
using MFDLabs.Configuration.Elements.Vault;
1516

1617
namespace MFDLabs.Configuration.Providers
@@ -24,30 +25,35 @@ static VaultProvider()
2425
if (ConfigurationSection != null)
2526
{
2627
var configuration = GetGroupConfigurationElement();
27-
var address = configuration.Address;
2828

29-
if (address == null)
29+
if (configuration != null)
3030
{
31-
if (!global::MFDLabs.Configuration.Properties.Settings.Default.ConsulServiceDiscoveryEnabled)
32-
throw new ConfigurationErrorsException("Consul Service discovery is not enabled, and the vault configuration address was null.");
31+
var address = configuration.Address.FromEnvironmentExpression<string>();
3332

34-
address = ConsulServiceDiscovery.GetFullyQualifiedServiceURL(global::MFDLabs.Configuration.Properties.Settings.Default.ConsulServiceDiscoveryVaultServiceName);
33+
if (address.IsNullOrEmpty())
34+
{
35+
if (!global::MFDLabs.Configuration.Properties.Settings.Default.ConsulServiceDiscoveryEnabled)
36+
throw new ConfigurationErrorsException("Consul Service discovery is not enabled, and the vault configuration address was null.");
3537

36-
if (address == null)
37-
throw new ApplicationException($"Consul Service discovery address lookup for service '{(global::MFDLabs.Configuration.Properties.Settings.Default.ConsulServiceDiscoveryVaultServiceName)}' failed: The Service did not exist.");
38-
}
38+
address = ConsulServiceDiscovery.GetFullyQualifiedServiceURL(global::MFDLabs.Configuration.Properties.Settings.Default.ConsulServiceDiscoveryVaultServiceName);
3939

40-
if (configuration.Credential.IsNullOrEmpty())
41-
throw new ConfigurationErrorsException("The configuration credential was null or empty when that was unexpected!");
40+
if (address == null)
41+
throw new ApplicationException($"Consul Service discovery address lookup for service '{(global::MFDLabs.Configuration.Properties.Settings.Default.ConsulServiceDiscoveryVaultServiceName)}' failed: The Service did not exist.");
42+
}
4243

43-
ConfigurationClient = GetClient(address, configuration.AuthenticationType, configuration.Credential);
44-
ConfigurationLogging.Info("MFDLabs.Configuration.Providers.VaultProvider static init Vault Client point to address '{0}'.", address);
45-
var updateInterval = configuration.UpdateInterval;
46-
Timer = new SelfDisposingTimer(RefreshRegisteredProviders, updateInterval, updateInterval);
47-
Providers = new ConcurrentDictionary<string, VaultProvider>();
48-
ConfigurationLogging.Info("MFDLabs.Configuration.Providers.VaultProvider static init Timer created, refresh every '{0}'.", updateInterval);
49-
return;
44+
if (configuration.Credential.FromEnvironmentExpression<string>().IsNullOrEmpty())
45+
throw new ConfigurationErrorsException("The configuration credential was null or empty when that was unexpected!");
46+
47+
ConfigurationClient = GetClient(address, configuration.AuthenticationType, configuration.Credential.FromEnvironmentExpression<string>());
48+
ConfigurationLogging.Info("MFDLabs.Configuration.Providers.VaultProvider static init Vault Client point to address '{0}'.", address);
49+
var updateInterval = configuration.UpdateInterval;
50+
Timer = new SelfDisposingTimer(RefreshRegisteredProviders, updateInterval, updateInterval);
51+
Providers = new ConcurrentDictionary<string, VaultProvider>();
52+
ConfigurationLogging.Info("MFDLabs.Configuration.Providers.VaultProvider static init Timer created, refresh every '{0}'.", updateInterval);
53+
return;
54+
}
5055
}
56+
5157
ConfigurationLogging.Warning("No config file found with mfdlabsVaultConfiguration.");
5258
}
5359

Assemblies/MFDLabs.Reflection/Extensions/TypeExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22

3+
#nullable enable
4+
35
namespace MFDLabs.Reflection.Extensions
46
{
57
public static class TypeExtensions
@@ -8,5 +10,7 @@ public static class TypeExtensions
810
public static bool IsNumeric(this Type t) => TypeHelper.IsNumericType(t);
911
public static bool IsPrimitive(this Type t) => TypeHelper.IsPrimitive(t);
1012
public static bool IsAnonymous(this Type t) => TypeHelper.IsAnonymousType(t);
13+
14+
public static TResult? To<TResult>(this object obj) => (TResult?)Convert.ChangeType(obj, typeof(TResult));
1115
}
1216
}

MFDLabs.Grid.AutoDeployer/App.config

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,86 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<configSections>
4-
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
5-
<section name="MFDLabs.Grid.AutoDeployer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
6-
<section name="MFDLabs.Networking.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
7-
<section name="MFDLabs.Diagnostics.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
8-
</sectionGroup>
9-
</configSections>
10-
<startup>
11-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
12-
</startup>
13-
<applicationSettings>
14-
<MFDLabs.Grid.AutoDeployer.Properties.Settings>
15-
<setting name="GithubEnterpriseUrl" serializeAs="String">
16-
<value />
17-
</setting>
18-
<setting name="VersioningRegistryVersionKeyName" serializeAs="String">
19-
<value>AppVersion</value>
20-
</setting>
21-
<setting name="CreateDeploymentPathIfNotExists" serializeAs="String">
22-
<value>True</value>
23-
</setting>
24-
<setting name="GithubToken" serializeAs="String">
25-
<value />
26-
</setting>
27-
<setting name="VersioningRegistrySubKey" serializeAs="String">
28-
<value />
29-
</setting>
30-
<setting name="DeploymentPath" serializeAs="String">
31-
<value />
32-
</setting>
33-
<setting name="GithubAccountOrOrganizationName" serializeAs="String">
34-
<value />
35-
</setting>
36-
<setting name="GithubRepositoryName" serializeAs="String">
37-
<value />
38-
</setting>
39-
<setting name="DeploymentPrimaryExecutableName" serializeAs="String">
40-
<value />
41-
</setting>
42-
<setting name="PollingInterval" serializeAs="String">
43-
<value>00:00:00</value>
44-
</setting>
45-
<setting name="EnvironmentLogLevel" serializeAs="String">
46-
<value>Verbose</value>
47-
</setting>
48-
<setting name="DeploymentAppName" serializeAs="String">
49-
<value />
50-
</setting>
51-
<setting name="SkippedVersionInvalidationInterval" serializeAs="String">
52-
<value>00:05:00</value>
53-
</setting>
54-
</MFDLabs.Grid.AutoDeployer.Properties.Settings>
55-
<MFDLabs.Networking.Properties.Settings>
56-
<setting name="LocalIPOverride" serializeAs="String">
57-
<value />
58-
</setting>
59-
</MFDLabs.Networking.Properties.Settings>
60-
<MFDLabs.Diagnostics.Properties.Settings>
61-
<setting name="MachineHostOverride" serializeAs="String">
62-
<value />
63-
</setting>
64-
<setting name="MachineIDOverride" serializeAs="String">
65-
<value />
66-
</setting>
67-
</MFDLabs.Diagnostics.Properties.Settings>
68-
</applicationSettings>
69-
<runtime>
70-
<legacyUnhandledExceptionPolicy enabled="1" />
71-
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
72-
<dependentAssembly>
73-
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
74-
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
75-
</dependentAssembly>
76-
<dependentAssembly>
77-
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
78-
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
79-
</dependentAssembly>&gt;
80-
<dependentAssembly>
81-
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
82-
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
83-
</dependentAssembly>
84-
</assemblyBinding>
85-
</runtime>
3+
<configSections>
4+
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
5+
<section name="MFDLabs.Grid.AutoDeployer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
6+
<section name="MFDLabs.Networking.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
7+
<section name="MFDLabs.Diagnostics.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
8+
</sectionGroup>
9+
</configSections>
10+
<startup>
11+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
12+
</startup>
13+
<applicationSettings>
14+
<MFDLabs.Grid.AutoDeployer.Properties.Settings>
15+
<setting name="GithubEnterpriseUrl" serializeAs="String">
16+
<value />
17+
</setting>
18+
<setting name="VersioningRegistryVersionKeyName" serializeAs="String">
19+
<value>AppVersion</value>
20+
</setting>
21+
<setting name="CreateDeploymentPathIfNotExists" serializeAs="String">
22+
<value>True</value>
23+
</setting>
24+
<setting name="GithubToken" serializeAs="String">
25+
<value />
26+
</setting>
27+
<setting name="VersioningRegistrySubKey" serializeAs="String">
28+
<value />
29+
</setting>
30+
<setting name="DeploymentPath" serializeAs="String">
31+
<value />
32+
</setting>
33+
<setting name="GithubAccountOrOrganizationName" serializeAs="String">
34+
<value />
35+
</setting>
36+
<setting name="GithubRepositoryName" serializeAs="String">
37+
<value />
38+
</setting>
39+
<setting name="DeploymentPrimaryExecutableName" serializeAs="String">
40+
<value />
41+
</setting>
42+
<setting name="PollingInterval" serializeAs="String">
43+
<value>00:00:00</value>
44+
</setting>
45+
<setting name="EnvironmentLogLevel" serializeAs="String">
46+
<value>Verbose</value>
47+
</setting>
48+
<setting name="DeploymentAppName" serializeAs="String">
49+
<value />
50+
</setting>
51+
<setting name="SkippedVersionInvalidationInterval" serializeAs="String">
52+
<value>00:05:00</value>
53+
</setting>
54+
</MFDLabs.Grid.AutoDeployer.Properties.Settings>
55+
<MFDLabs.Networking.Properties.Settings>
56+
<setting name="LocalIPOverride" serializeAs="String">
57+
<value />
58+
</setting>
59+
</MFDLabs.Networking.Properties.Settings>
60+
<MFDLabs.Diagnostics.Properties.Settings>
61+
<setting name="MachineHostOverride" serializeAs="String">
62+
<value />
63+
</setting>
64+
<setting name="MachineIDOverride" serializeAs="String">
65+
<value />
66+
</setting>
67+
</MFDLabs.Diagnostics.Properties.Settings>
68+
</applicationSettings>
69+
<runtime>
70+
<legacyUnhandledExceptionPolicy enabled="1" />
71+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
72+
<dependentAssembly>
73+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
74+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
75+
</dependentAssembly>
76+
<dependentAssembly>
77+
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
78+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
79+
</dependentAssembly>
80+
<dependentAssembly>
81+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
82+
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
83+
</dependentAssembly>
84+
</assemblyBinding>
85+
</runtime>
8686
</configuration>

0 commit comments

Comments
 (0)