Skip to content

Commit

Permalink
Merge pull request #210 from gigya/develop
Browse files Browse the repository at this point in the history
merge develop to master
  • Loading branch information
bronsh authored Oct 7, 2018
2 parents 0186df8 + 0ee6bc7 commit 3aeb22f
Show file tree
Hide file tree
Showing 145 changed files with 5,478 additions and 732 deletions.
53 changes: 15 additions & 38 deletions .paket/Paket.Restore.targets
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,23 @@
<!-- Step 1 Check if lockfile is properly restored -->
<PropertyGroup>
<PaketRestoreRequired>true</PaketRestoreRequired>
<NoWarn>$(NoWarn);NU1603;NU1604;NU1605;NU1608</NoWarn>
<NoWarn>$(NoWarn);NU1603</NoWarn>
</PropertyGroup>

<!-- Because ReadAllText is slow on osx/linux, try to find shasum and awk -->
<PropertyGroup>
<PaketRestoreCachedHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreCachedHasher)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum "$(PaketRestoreCacheFile)" | /usr/bin/awk '{ print $1 }'</PaketRestoreCachedHasher>
<PaketRestoreLockFileHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreLockFileHash)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum "$(PaketLockFilePath)" | /usr/bin/awk '{ print $1 }'</PaketRestoreLockFileHasher>
<PaketRestoreCachedHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreCachedHasher)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum $(PaketRestoreCacheFile) | /usr/bin/awk '{ print $1 }'</PaketRestoreCachedHasher>
<PaketRestoreLockFileHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreLockFileHash)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum $(PaketLockFilePath) | /usr/bin/awk '{ print $1 }'</PaketRestoreLockFileHasher>
</PropertyGroup>

<!-- If shasum and awk exist get the hashes -->
<Exec StandardOutputImportance="Low" Condition=" '$(PaketRestoreCachedHasher)' != '' " Command="$(PaketRestoreCachedHasher)" ConsoleToMSBuild='true'>
<Output TaskParameter="ConsoleOutput" PropertyName="PaketRestoreCachedHash" />
<Output TaskParameter="ConsoleOutput" PropertyName="PaketRestoreCachedHash" />
</Exec>
<Exec StandardOutputImportance="Low" Condition=" '$(PaketRestoreLockFileHasher)' != '' " Command="$(PaketRestoreLockFileHasher)" ConsoleToMSBuild='true'>
<Output TaskParameter="ConsoleOutput" PropertyName="PaketRestoreLockFileHash" />
<Output TaskParameter="ConsoleOutput" PropertyName="PaketRestoreLockFileHash" />
</Exec>

<!-- Debug whats going on -->
<Message Importance="low" Text="calling paket restore with targetframework=$(TargetFramework) targetframeworks=$(TargetFrameworks)" />

<PropertyGroup Condition="Exists('$(PaketRestoreCacheFile)') ">
<!-- if no hash has been done yet fall back to just reading in the files and comparing them -->
<PaketRestoreCachedHash Condition=" '$(PaketRestoreCachedHash)' == '' ">$([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)'))</PaketRestoreCachedHash>
Expand All @@ -71,23 +68,12 @@
<PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(PaketRestoreCachedHash)' ">false</PaketRestoreRequired>
<PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '' ">true</PaketRestoreRequired>
</PropertyGroup>

<PropertyGroup Condition="'$(PaketPropsVersion)' != '5.174.2' ">
<PaketRestoreRequired>true</PaketRestoreRequired>
</PropertyGroup>

<!-- Do a global restore if required -->
<Exec Command='$(PaketBootStrapperCommand)' Condition="Exists('$(PaketBootStrapperExePath)') AND !(Exists('$(PaketExePath)'))" ContinueOnError="false" />
<Exec Command='$(PaketCommand) restore' Condition=" '$(PaketRestoreRequired)' == 'true' " ContinueOnError="false" />

<!-- Step 2 Detect project specific changes -->
<ItemGroup>
<MyTargetFrameworks Condition="'$(TargetFramework)' != '' " Include="$(TargetFramework)"></MyTargetFrameworks>
<!-- Don't include all frameworks when msbuild explicitly asks for a single one -->
<MyTargetFrameworks Condition="'$(TargetFrameworks)' != '' AND '$(TargetFramework)' == '' " Include="$(TargetFrameworks)"></MyTargetFrameworks>
<PaketResolvedFilePaths Include="@(MyTargetFrameworks -> '$(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).%(Identity).paket.resolved')"></PaketResolvedFilePaths>
</ItemGroup>
<Message Importance="low" Text="MyTargetFrameworks=@(MyTargetFrameworks) PaketResolvedFilePaths=@(PaketResolvedFilePaths)" />
<PropertyGroup>
<PaketReferencesCachedFilePath>$(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).paket.references.cached</PaketReferencesCachedFilePath>
<!-- MyProject.fsproj.paket.references has the highest precedence -->
Expand All @@ -96,9 +82,7 @@
<PaketOriginalReferencesFilePath Condition=" !Exists('$(PaketOriginalReferencesFilePath)')">$(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references</PaketOriginalReferencesFilePath>
<!-- paket.references -->
<PaketOriginalReferencesFilePath Condition=" !Exists('$(PaketOriginalReferencesFilePath)')">$(MSBuildProjectDirectory)\paket.references</PaketOriginalReferencesFilePath>

<DoAllResolvedFilesExist>false</DoAllResolvedFilesExist>
<DoAllResolvedFilesExist Condition="Exists(%(PaketResolvedFilePaths.Identity))">true</DoAllResolvedFilesExist>
<PaketResolvedFilePath>$(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).$(TargetFramework).paket.resolved</PaketResolvedFilePath>
<PaketRestoreRequired>true</PaketRestoreRequired>
<PaketRestoreRequiredReason>references-file-or-cache-not-found</PaketRestoreRequiredReason>
</PropertyGroup>
Expand All @@ -117,39 +101,32 @@
</PropertyGroup>

<!-- Step 2 b detect relevant changes in project file (new targetframework) -->
<PropertyGroup Condition=" '$(DoAllResolvedFilesExist)' != 'true' ">
<PropertyGroup Condition=" !Exists('$(PaketResolvedFilePath)') AND '$(TargetFramework)' != '' ">
<PaketRestoreRequired>true</PaketRestoreRequired>
<PaketRestoreRequiredReason>target-framework '$(TargetFramework)' or '$(TargetFrameworks)' files @(PaketResolvedFilePaths)</PaketRestoreRequiredReason>
<PaketRestoreRequiredReason>target-framework '$(TargetFramework)'</PaketRestoreRequiredReason>
</PropertyGroup>

<!-- Step 3 Restore project specific stuff if required -->
<Message Condition=" '$(PaketRestoreRequired)' == 'true' " Importance="low" Text="Detected a change ('$(PaketRestoreRequiredReason)') in the project file '$(MSBuildProjectFullPath)', calling paket restore" />
<Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)" --target-framework "$(TargetFrameworks)"' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(TargetFramework)' == '' " ContinueOnError="false" />
<Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)" --target-framework "$(TargetFramework)"' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(TargetFramework)' != '' " ContinueOnError="false" />
<Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)"' Condition=" '$(PaketRestoreRequired)' == 'true' " ContinueOnError="false" />

<!-- This shouldn't actually happen, but just to be sure. -->
<PropertyGroup>
<DoAllResolvedFilesExist>false</DoAllResolvedFilesExist>
<DoAllResolvedFilesExist Condition="Exists(%(PaketResolvedFilePaths.Identity))">true</DoAllResolvedFilesExist>
</PropertyGroup>
<Error Condition=" '$(DoAllResolvedFilesExist)' != 'true' AND '$(ResolveNuGetPackages)' != 'False' " Text="One Paket file '@(PaketResolvedFilePaths)' is missing while restoring $(MSBuildProjectFile). Please delete 'paket-files/paket.restore.cached' and call 'paket restore'." />
<Error Condition=" !Exists('$(PaketResolvedFilePath)') AND '$(TargetFramework)' != '' AND '$(ResolveNuGetPackages)' != 'False' " Text="Paket file '$(PaketResolvedFilePath)' is missing while restoring $(MSBuildProjectFile). Please delete 'paket-files/paket.restore.cached' and call 'paket restore'." />

<!-- Step 4 forward all msbuild properties (PackageReference, DotNetCliToolReference) to msbuild -->
<ReadLinesFromFile Condition="($(DesignTimeBuild) != true OR '$(PaketPropsLoaded)' != 'true') AND '@(PaketResolvedFilePaths)' != ''" File="%(PaketResolvedFilePaths.Identity)" >
<ReadLinesFromFile Condition="Exists('$(PaketResolvedFilePath)')" File="$(PaketResolvedFilePath)" >
<Output TaskParameter="Lines" ItemName="PaketReferencesFileLines"/>
</ReadLinesFromFile>

<ItemGroup Condition="($(DesignTimeBuild) != true OR '$(PaketPropsLoaded)' != 'true') AND '@(PaketReferencesFileLines)' != '' " >
<ItemGroup Condition=" Exists('$(PaketResolvedFilePath)') AND '@(PaketReferencesFileLines)' != '' " >
<PaketReferencesFileLinesInfo Include="@(PaketReferencesFileLines)" >
<PackageName>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0])</PackageName>
<PackageVersion>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1])</PackageVersion>
<AllPrivateAssets>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[4])</AllPrivateAssets>
</PaketReferencesFileLinesInfo>
<PackageReference Include="%(PaketReferencesFileLinesInfo.PackageName)">
<Version>%(PaketReferencesFileLinesInfo.PackageVersion)</Version>
<PrivateAssets Condition=" ('%(PaketReferencesFileLinesInfo.AllPrivateAssets)' == 'true') Or ('$(PackAsTool)' == 'true') ">All</PrivateAssets>
<ExcludeAssets Condition="%(PaketReferencesFileLinesInfo.AllPrivateAssets) == 'exclude'">runtime</ExcludeAssets>
<Publish Condition=" '$(PackAsTool)' == 'true' ">true</Publish>
<PrivateAssets Condition="%(PaketReferencesFileLinesInfo.AllPrivateAssets) == 'true'">All</PrivateAssets>
</PackageReference>
</ItemGroup>

Expand Down Expand Up @@ -206,8 +183,8 @@

<ConvertToAbsolutePath Condition="@(_NuspecFiles) != ''" Paths="@(_NuspecFiles)">
<Output TaskParameter="AbsolutePaths" PropertyName="NuspecFileAbsolutePath" />
</ConvertToAbsolutePath>

</ConvertToAbsolutePath>

<!-- Call Pack -->
<PackTask Condition="$(UseNewPack)"
Expand Down
8 changes: 4 additions & 4 deletions Gigya.Microdot.Configuration/ConfigurationLocationsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ private class ErrorAggregator
public string ConfigRoot { get; }
public string LoadPathsFilePath { get; }

public ConfigurationLocationsParser(IEnvironment environment, IFileSystem fileSystemInstance, IEnvironmentVariableProvider environmentVariableProvider)
public ConfigurationLocationsParser(IFileSystem fileSystemInstance, IEnvironmentVariableProvider environmentVariableProvider)
{
AppName = CurrentApplicationInfo.Name;
environment.SetEnvironmentVariableForProcess("AppName", CurrentApplicationInfo.Name);
environmentVariableProvider.SetEnvironmentVariableForProcess("AppName", CurrentApplicationInfo.Name);

ConfigRoot = environmentVariableProvider.GetEnvironmentVariable(GIGYA_CONFIG_ROOT);

if (string.IsNullOrEmpty(ConfigRoot))
ConfigRoot = environment.PlatformSpecificPathPrefix + GIGYA_CONFIG_ROOT_DEFAULT;
ConfigRoot = environmentVariableProvider.PlatformSpecificPathPrefix + GIGYA_CONFIG_ROOT_DEFAULT;

LoadPathsFilePath = environmentVariableProvider.GetEnvironmentVariable(GIGYA_CONFIG_PATHS_FILE);

Expand All @@ -84,7 +84,7 @@ public ConfigurationLocationsParser(IEnvironment environment, IFileSystem fileSy

var configPathDeclarations = ParseAndValidateConfigLines(LoadPathsFilePath, fileSystemInstance);

ConfigFileDeclarations = ExpandConfigPathDeclarations(environmentVariableProvider, configPathDeclarations, environment.PlatformSpecificPathPrefix).ToArray();
ConfigFileDeclarations = ExpandConfigPathDeclarations(environmentVariableProvider, configPathDeclarations, environmentVariableProvider.PlatformSpecificPathPrefix).ToArray();
}


Expand Down
79 changes: 66 additions & 13 deletions Gigya.Microdot.Configuration/EnvironmentVariableProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,89 @@
// POSSIBILITY OF SUCH DAMAGE.
#endregion

using System;
using System.Linq;
using Gigya.Common.Contracts.Exceptions;
using Gigya.Microdot.Interfaces.Configuration;
using Gigya.Microdot.Interfaces.SystemWrappers;
using Gigya.Microdot.SharedLogic.Exceptions;
using Newtonsoft.Json.Linq;

namespace Gigya.Microdot.Configuration
{
public class EnvironmentVariableProvider : IEnvironmentVariableProvider
{
private readonly IEnvironment _environment;

public EnvironmentVariableProvider(IEnvironment environment, EnvironmentVariablesFileReader fileReader)
{
private const string GIGYA_ENV_VARS_FILE = "GIGYA_ENVVARS_FILE";
private const string ENV_FILEPATH = "{0}/gigya/environmentVariables.json";

private IFileSystem FileSystem { get; }

public EnvironmentVariableProvider(IFileSystem fileSystem)
{
_environment = environment;
FileSystem = fileSystem;
PlatformSpecificPathPrefix = Environment.OSVersion.Platform == PlatformID.Unix ? "/etc" : "D:";

var locEnvFilePath = GetEnvironmentVariable(GIGYA_ENV_VARS_FILE);

fileReader.ReadFromFile();
DataCenter = environment.GetEnvironmentVariable("DC");
DeploymentEnvironment = environment.GetEnvironmentVariable("ENV");
ConsulAddress = environment.GetEnvironmentVariable("CONSUL");
if (string.IsNullOrEmpty(locEnvFilePath))
{
locEnvFilePath = string.Format(ENV_FILEPATH, PlatformSpecificPathPrefix);
}

if (string.IsNullOrEmpty(DataCenter) || string.IsNullOrEmpty(DeploymentEnvironment))
throw new EnvironmentException("One or more of the following environment variables, which are required, have not been set: %DC%, %ENV%");
ReadFromFile(locEnvFilePath);

DataCenter = GetEnvironmentVariable("ZONE") ?? GetEnvironmentVariable("DC");
DeploymentEnvironment = GetEnvironmentVariable("ENV");
}

public string ConsulAddress { get; }
public void SetEnvironmentVariableForProcess(string name, string value)
{
Environment.SetEnvironmentVariable(name, value.ToLower(), EnvironmentVariableTarget.Process);
}

public string GetEnvironmentVariable(string name) { return Environment.GetEnvironmentVariable(name)?.ToLower(); }

public string PlatformSpecificPathPrefix { get; }

[Obsolete("To be deleted on version 2.0")]
public string DataCenter { get; }

[Obsolete("To be deleted on version 2.0")]
public string DeploymentEnvironment { get; }

public string GetEnvironmentVariable(string name) { return _environment.GetEnvironmentVariable(name); }

/// <summary>
/// Reads each property in file and sets its environment variable.
/// </summary>
/// <returns>Names of environment variables read from file</returns>
public void ReadFromFile(string locEnvFilePath)
{
JObject envVarsObject;

try
{
var text = FileSystem.TryReadAllTextFromFile(locEnvFilePath);

if (string.IsNullOrEmpty(text))
return;

envVarsObject = JObject.Parse(text);
}
catch (Exception ex)
{
throw new ConfigurationException($"Missing or invalid configuration file: {locEnvFilePath}", ex);
}

if (envVarsObject == null)
return;

var properties = envVarsObject.Properties().Where(a => a.HasValues).ToArray();

foreach (var property in properties)
{
SetEnvironmentVariableForProcess(property.Name, property.Value.Value<string>());
}
}

}
}
16 changes: 8 additions & 8 deletions Gigya.Microdot.Configuration/EnvironmentVariablesFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

using System;
using System.Linq;
using Gigya.Microdot.Interfaces.Configuration;
using Gigya.Microdot.Interfaces.SystemWrappers;
using Gigya.Microdot.SharedLogic.Exceptions;
using Newtonsoft.Json.Linq;
Expand All @@ -42,23 +43,22 @@ public class EnvironmentVariablesFileReader
private const string ENV_FILEPATH = "{0}/gigya/environmentVariables.json";
private readonly string locEnvFilePath;

private IEnvironment Environment { get; }
private IEnvironmentVariableProvider EnvironmentVariableProvider { get; }
private IFileSystem FileSystem { get; }


/// <summary>
/// Parses the content of environment variables file content.
/// </summary>
public EnvironmentVariablesFileReader(IFileSystem fileSystem, IEnvironment environment)
public EnvironmentVariablesFileReader(IFileSystem fileSystem, IEnvironmentVariableProvider environmentVariableProvider)
{
locEnvFilePath = environment.GetEnvironmentVariable(GIGYA_ENV_VARS_FILE);
locEnvFilePath = environmentVariableProvider.GetEnvironmentVariable(GIGYA_ENV_VARS_FILE);

if (string.IsNullOrEmpty(locEnvFilePath))
{
locEnvFilePath = string.Format(ENV_FILEPATH, environment.PlatformSpecificPathPrefix);
locEnvFilePath = string.Format(ENV_FILEPATH, environmentVariableProvider.PlatformSpecificPathPrefix);
}
Environment = environment;

EnvironmentVariableProvider = environmentVariableProvider;
FileSystem = fileSystem;
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public void ReadFromFile()

foreach (var property in properties)
{
Environment.SetEnvironmentVariableForProcess(property.Name, property.Value.Value<string>());
EnvironmentVariableProvider.SetEnvironmentVariableForProcess(property.Name, property.Value.Value<string>());
}
}
}
Expand Down
27 changes: 23 additions & 4 deletions Gigya.Microdot.Fakes/DateTimeFake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Gigya.Microdot.Interfaces.SystemWrappers;

namespace Gigya.Microdot.Fakes
{
public class DateTimeFake: IDateTime
public class DateTimeFake : IDateTime
{
public DateTime UtcNow { get; set; }
public DateTime UtcNow { get; set; } = DateTime.UtcNow;

private TaskCompletionSource<bool> _delayTask = new TaskCompletionSource<bool>();

Expand All @@ -46,10 +47,28 @@ public DateTimeFake(bool manualDelay)
_manualDelay = manualDelay;
}

public Task Delay(TimeSpan delay)
public Task Delay(TimeSpan delay) => Delay(delay, default(CancellationToken));
public async Task Delay(TimeSpan delay, CancellationToken cancellationToken = default(CancellationToken))
{
DelaysRequested.Add(delay);
return _manualDelay ? _delayTask.Task : Task.Delay(delay);

if (_manualDelay)
await _delayTask.Task;
else
await Task.Delay(delay, cancellationToken);

UtcNow += delay;
}

public async Task DelayUntil(DateTime until, CancellationToken cancellationToken = default(CancellationToken))
{
TimeSpan delayTime = until - UtcNow;

if (delayTime > TimeSpan.Zero)
{
await Delay(delayTime, cancellationToken).ConfigureAwait(false);
UtcNow += delayTime;
}
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Gigya.Microdot.Fakes/Discovery/AlwaysLocalHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace Gigya.Microdot.Fakes.Discovery
{
public class AlwaysLocalHost : IDiscoverySourceLoader
{
public IServiceDiscoverySource GetDiscoverySource(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig serviceDiscoveryConfig)
public IServiceDiscoverySource GetDiscoverySource(DeploymentIdentifier deploymentIdentifier, ServiceDiscoveryConfig serviceDiscoveryConfig)
{
return new LocalDiscoverySource(serviceDeployment);
return new LocalDiscoverySource(deploymentIdentifier);
}
}
}
Loading

0 comments on commit 3aeb22f

Please sign in to comment.