Skip to content

Commit

Permalink
Merge branch 'master' into fix/100-fix-github-powershell-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jf-06 authored Oct 21, 2022
2 parents 5eb40cc + eb21d76 commit d4c0750
Show file tree
Hide file tree
Showing 20 changed files with 1,358 additions and 117 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,5 @@ FodyWeavers.xsd
#
Deploy/

App.*.config
WtfIsThis.cs
.idea/
.AssemblyAttributes
60 changes: 60 additions & 0 deletions Assemblies/MFDLabs.Configuration/Extensions/SettingExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using MFDLabs.Text.Extensions;
using MFDLabs.Reflection.Extensions;

#nullable enable

namespace MFDLabs.Configuration.Extensions
{
public static class SettingExtensions
{
// There's a special kind of var here that does like this:
// ${{ env.VAR_NAME }}, which is a special kind of var that will be replaced with the value of the environment variable VAR_NAME.
// This is useful when you want to pass the value of an environment variable to a command.
// We have to parse this out, and replace it with the value of the environment variable.
public static TResult? FromEnvironmentExpression<TResult>(this object setting)
{
if (setting is not string str) return default;
if (str.IsNullOrEmpty()) return str.To<TResult>();

// Trim the input
str = str.Trim();

// Remove the spaces from the input.
str = str.Replace(" ", "");

// Check if the input contains the special var
if (!str.StartsWith("${{")) return str.To<TResult>();

// Split the input into parts
var parts = str.Split(new[] { "${{" }, StringSplitOptions.None);

// We now need to get the part in the middle of ${{ }}
var otherPart = parts[1];

// Split the middle part into parts
var middleParts = otherPart.Split(new[] { "}}" }, StringSplitOptions.None);

// Get the name of the environment variable
var middlePart = middleParts[0];

// Check if the middle part starts with env.
if (!middlePart.ToLower().StartsWith("env.")) return str.To<TResult>();

// Get the env var name
var envVarName = middlePart.Remove(0, 4);

// Check if the env var is empty
if (envVarName.IsNullOrWhiteSpace()) return str.To<TResult>();

// Get the env var value
var env = Environment.GetEnvironmentVariable(envVarName);

// Check if the env var value is empty, if so, return the original string
if (env.IsNullOrEmpty()) return str.To<TResult>();

// Replace the env var value with the env var name
return env.To<TResult>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<ProjectReference Include="..\MFDLabs.Hashicorp.ConsulClient\MFDLabs.Hashicorp.ConsulClient.csproj" />
<ProjectReference Include="..\MFDLabs.Hashicorp.VaultClient\MFDLabs.Hashicorp.VaultClient.csproj" />
<ProjectReference Include="..\MFDLabs.Logging\MFDLabs.Logging.csproj" />
<ProjectReference Include="..\MFDLabs.Reflection\MFDLabs.Reflection.csproj" />
<ProjectReference Include="..\MFDLabs.Text\MFDLabs.Text.csproj" />
<ProjectReference Include="..\MFDLabs.Threading\MFDLabs.Threading.csproj" />
</ItemGroup>
Expand Down
52 changes: 29 additions & 23 deletions Assemblies/MFDLabs.Configuration/Providers/VaultProvider.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.IO;
using System.Collections.Concurrent;
using System.Configuration;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Specialized;
using System.Configuration;
using MFDLabs.Threading;
using MFDLabs.Configuration.Sections.Vault;
using MFDLabs.Configuration.Clients.Vault;
using MFDLabs.Configuration.Logging;
using MFDLabs.Text.Extensions;
using MFDLabs.Configuration.Logging;
using MFDLabs.Configuration.Extensions;
using MFDLabs.Configuration.Clients.Vault;
using MFDLabs.Configuration.Sections.Vault;
using MFDLabs.Configuration.Elements.Vault;

namespace MFDLabs.Configuration.Providers
Expand All @@ -24,30 +25,35 @@ static VaultProvider()
if (ConfigurationSection != null)
{
var configuration = GetGroupConfigurationElement();
var address = configuration.Address;

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

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

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

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

ConfigurationClient = GetClient(address, configuration.AuthenticationType, configuration.Credential);
ConfigurationLogging.Info("MFDLabs.Configuration.Providers.VaultProvider static init Vault Client point to address '{0}'.", address);
var updateInterval = configuration.UpdateInterval;
Timer = new SelfDisposingTimer(RefreshRegisteredProviders, updateInterval, updateInterval);
Providers = new ConcurrentDictionary<string, VaultProvider>();
ConfigurationLogging.Info("MFDLabs.Configuration.Providers.VaultProvider static init Timer created, refresh every '{0}'.", updateInterval);
return;
if (configuration.Credential.FromEnvironmentExpression<string>().IsNullOrEmpty())
throw new ConfigurationErrorsException("The configuration credential was null or empty when that was unexpected!");

ConfigurationClient = GetClient(address, configuration.AuthenticationType, configuration.Credential.FromEnvironmentExpression<string>());
ConfigurationLogging.Info("MFDLabs.Configuration.Providers.VaultProvider static init Vault Client point to address '{0}'.", address);
var updateInterval = configuration.UpdateInterval;
Timer = new SelfDisposingTimer(RefreshRegisteredProviders, updateInterval, updateInterval);
Providers = new ConcurrentDictionary<string, VaultProvider>();
ConfigurationLogging.Info("MFDLabs.Configuration.Providers.VaultProvider static init Timer created, refresh every '{0}'.", updateInterval);
return;
}
}

ConfigurationLogging.Warning("No config file found with mfdlabsVaultConfiguration.");
}

Expand Down
4 changes: 4 additions & 0 deletions Assemblies/MFDLabs.Reflection/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;

#nullable enable

namespace MFDLabs.Reflection.Extensions
{
public static class TypeExtensions
Expand All @@ -8,5 +10,7 @@ public static class TypeExtensions
public static bool IsNumeric(this Type t) => TypeHelper.IsNumericType(t);
public static bool IsPrimitive(this Type t) => TypeHelper.IsPrimitive(t);
public static bool IsAnonymous(this Type t) => TypeHelper.IsAnonymousType(t);

public static TResult? To<TResult>(this object obj) => (TResult?)Convert.ChangeType(obj, typeof(TResult));
}
}
166 changes: 83 additions & 83 deletions MFDLabs.Grid.AutoDeployer/App.config
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MFDLabs.Grid.AutoDeployer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="MFDLabs.Networking.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="MFDLabs.Diagnostics.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<applicationSettings>
<MFDLabs.Grid.AutoDeployer.Properties.Settings>
<setting name="GithubEnterpriseUrl" serializeAs="String">
<value />
</setting>
<setting name="VersioningRegistryVersionKeyName" serializeAs="String">
<value>AppVersion</value>
</setting>
<setting name="CreateDeploymentPathIfNotExists" serializeAs="String">
<value>True</value>
</setting>
<setting name="GithubToken" serializeAs="String">
<value />
</setting>
<setting name="VersioningRegistrySubKey" serializeAs="String">
<value />
</setting>
<setting name="DeploymentPath" serializeAs="String">
<value />
</setting>
<setting name="GithubAccountOrOrganizationName" serializeAs="String">
<value />
</setting>
<setting name="GithubRepositoryName" serializeAs="String">
<value />
</setting>
<setting name="DeploymentPrimaryExecutableName" serializeAs="String">
<value />
</setting>
<setting name="PollingInterval" serializeAs="String">
<value>00:00:00</value>
</setting>
<setting name="EnvironmentLogLevel" serializeAs="String">
<value>Verbose</value>
</setting>
<setting name="DeploymentAppName" serializeAs="String">
<value />
</setting>
<setting name="SkippedVersionInvalidationInterval" serializeAs="String">
<value>00:05:00</value>
</setting>
</MFDLabs.Grid.AutoDeployer.Properties.Settings>
<MFDLabs.Networking.Properties.Settings>
<setting name="LocalIPOverride" serializeAs="String">
<value />
</setting>
</MFDLabs.Networking.Properties.Settings>
<MFDLabs.Diagnostics.Properties.Settings>
<setting name="MachineHostOverride" serializeAs="String">
<value />
</setting>
<setting name="MachineIDOverride" serializeAs="String">
<value />
</setting>
</MFDLabs.Diagnostics.Properties.Settings>
</applicationSettings>
<runtime>
<legacyUnhandledExceptionPolicy enabled="1" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>&gt;
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MFDLabs.Grid.AutoDeployer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="MFDLabs.Networking.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="MFDLabs.Diagnostics.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<applicationSettings>
<MFDLabs.Grid.AutoDeployer.Properties.Settings>
<setting name="GithubEnterpriseUrl" serializeAs="String">
<value />
</setting>
<setting name="VersioningRegistryVersionKeyName" serializeAs="String">
<value>AppVersion</value>
</setting>
<setting name="CreateDeploymentPathIfNotExists" serializeAs="String">
<value>True</value>
</setting>
<setting name="GithubToken" serializeAs="String">
<value />
</setting>
<setting name="VersioningRegistrySubKey" serializeAs="String">
<value />
</setting>
<setting name="DeploymentPath" serializeAs="String">
<value />
</setting>
<setting name="GithubAccountOrOrganizationName" serializeAs="String">
<value />
</setting>
<setting name="GithubRepositoryName" serializeAs="String">
<value />
</setting>
<setting name="DeploymentPrimaryExecutableName" serializeAs="String">
<value />
</setting>
<setting name="PollingInterval" serializeAs="String">
<value>00:00:00</value>
</setting>
<setting name="EnvironmentLogLevel" serializeAs="String">
<value>Verbose</value>
</setting>
<setting name="DeploymentAppName" serializeAs="String">
<value />
</setting>
<setting name="SkippedVersionInvalidationInterval" serializeAs="String">
<value>00:05:00</value>
</setting>
</MFDLabs.Grid.AutoDeployer.Properties.Settings>
<MFDLabs.Networking.Properties.Settings>
<setting name="LocalIPOverride" serializeAs="String">
<value />
</setting>
</MFDLabs.Networking.Properties.Settings>
<MFDLabs.Diagnostics.Properties.Settings>
<setting name="MachineHostOverride" serializeAs="String">
<value />
</setting>
<setting name="MachineIDOverride" serializeAs="String">
<value />
</setting>
</MFDLabs.Diagnostics.Properties.Settings>
</applicationSettings>
<runtime>
<legacyUnhandledExceptionPolicy enabled="1" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Loading

0 comments on commit d4c0750

Please sign in to comment.