From f378ec42394deb1e383207fdd525e4725e676b04 Mon Sep 17 00:00:00 2001 From: "deniz_irgin@yahoo.com" Date: Tue, 21 May 2019 15:49:59 +0300 Subject: [PATCH] * Add LocalStack.Client as git submodule * Clean up code --- .gitignore | 5 +++ .gitmodules | 4 ++ depedencies/README.md | 5 +++ depedencies/localstack-dotnet-client | 1 + .../LocalStack.AwsLocal.csproj | 22 ++++++----- src/LocalStack.AwsLocal/ProcessHelper.cs | 7 ++-- src/LocalStack.AwsLocal/Program.cs | 38 +++++++++---------- src/LocalStack.sln | 2 +- 8 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 .gitmodules create mode 100644 depedencies/README.md create mode 160000 depedencies/localstack-dotnet-client diff --git a/.gitignore b/.gitignore index 3e759b7..fcb7ac6 100644 --- a/.gitignore +++ b/.gitignore @@ -328,3 +328,8 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ + +testrunner + +# Cake +[Tt]ools/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8786d81 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "depedencies/localstack-dotnet-client"] + path = depedencies/localstack-dotnet-client + url = git@github.com:localstack-dotnet/localstack-dotnet-client.git + branch = v0.8.0.163 diff --git a/depedencies/README.md b/depedencies/README.md new file mode 100644 index 0000000..d94d515 --- /dev/null +++ b/depedencies/README.md @@ -0,0 +1,5 @@ +# Depedencies + +The dependencies are taken from the [LocalStack.Client](https://github.com/localstack-dotnet/localstack-dotnet-client), +which is added as git submodule. The reason behind this approach is to keep the [LocalStack.AwsLocal](https://github.com/localstack-dotnet/localstack-awscli-local) library as simple and light as possible. +What we need is just a few enums and utily classes. \ No newline at end of file diff --git a/depedencies/localstack-dotnet-client b/depedencies/localstack-dotnet-client new file mode 160000 index 0000000..8d2900f --- /dev/null +++ b/depedencies/localstack-dotnet-client @@ -0,0 +1 @@ +Subproject commit 8d2900f8b30ae7f95289eb85adcf931fa8e79826 diff --git a/src/LocalStack.AwsLocal/LocalStack.AwsLocal.csproj b/src/LocalStack.AwsLocal/LocalStack.AwsLocal.csproj index 42e09fd..049cd07 100644 --- a/src/LocalStack.AwsLocal/LocalStack.AwsLocal.csproj +++ b/src/LocalStack.AwsLocal/LocalStack.AwsLocal.csproj @@ -3,21 +3,25 @@ Exe netcoreapp2.2 - - true awslocal + true - - + + + - - + + + + + + + - + - - + \ No newline at end of file diff --git a/src/LocalStack.AwsLocal/ProcessHelper.cs b/src/LocalStack.AwsLocal/ProcessHelper.cs index 35fdf36..6538db5 100644 --- a/src/LocalStack.AwsLocal/ProcessHelper.cs +++ b/src/LocalStack.AwsLocal/ProcessHelper.cs @@ -1,8 +1,8 @@ -using System; +using LocalStack.AwsLocal.Contracts; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; -using LocalStack.AwsLocal.Contracts; namespace LocalStack.AwsLocal { @@ -22,7 +22,6 @@ public int CmdExecute(string command, string workingDirectoryPath = null, bool o cmd.StartInfo.UseShellExecute = false; cmd.StartInfo.Arguments = isWindows ? $"/c {command}" : "-c \"" + command + "\""; - if (workingDirectoryPath != null) { cmd.StartInfo.WorkingDirectory = workingDirectoryPath; @@ -87,4 +86,4 @@ public int CmdExecute(string command, string workingDirectoryPath = null, bool o } } } -} +} \ No newline at end of file diff --git a/src/LocalStack.AwsLocal/Program.cs b/src/LocalStack.AwsLocal/Program.cs index 6beff50..a598af9 100644 --- a/src/LocalStack.AwsLocal/Program.cs +++ b/src/LocalStack.AwsLocal/Program.cs @@ -1,34 +1,35 @@ -using System; +using LocalStack.AwsLocal.Contracts; +using LocalStack.Client; +using LocalStack.Client.Contracts; +using LocalStack.Client.Models; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; -using LocalStack.AwsLocal.Contracts; -using LocalStack.Client; -using LocalStack.Client.Models; namespace LocalStack.AwsLocal { - public class Program + internal static class Program { private const string UsageResource = "LocalStack.AwsLocal.Usage.txt"; - private static readonly IProcessHelper ProcessHelper = new ProcessHelper(); - private static string[] _args; - private static IEnumerable Args => _args; + private static readonly IProcessHelper ProcessHelper = new ProcessHelper(); + private static readonly string LocalStackHost = Environment.GetEnvironmentVariable("LOCALSTACK_HOST"); + private static readonly IConfig Config = new Config(LocalStackHost); - static void Main(string[] args) + private static IEnumerable Args { get; set; } + + private static void Main(string[] args) { - _args = args; + Args = args; if (args.Length == 0 || (args[0] == "-h")) { Usage(); } - string localStackHost = Environment.GetEnvironmentVariable("LOCALSTACK_HOST"); - - var awsServiceEndpoint = GetServiceEndpoint(localStackHost); + AwsServiceEndpoint awsServiceEndpoint = GetServiceEndpoint(); string service = GetService(); if (awsServiceEndpoint == null || service == null) @@ -53,7 +54,7 @@ static void Main(string[] args) ProcessHelper.CmdExecute(string.Join(' ', arguments), null, true, true, new Dictionary { {"AWS_DEFAULT_REGION", awsDefaultRegion}, - { "AWS_ACCESS_KEY_ID", awsAccessKeyId}, + {"AWS_ACCESS_KEY_ID", awsAccessKeyId}, {"AWS_SECRET_ACCESS_KEY", awsSecretAccessKey} }); } @@ -71,7 +72,7 @@ private static string GetService() return string.Empty; } - private static AwsServiceEndpoint GetServiceEndpoint(string localStackHost = null) + private static AwsServiceEndpoint GetServiceEndpoint() { string service = GetService(); if (service == "s3api") @@ -79,16 +80,15 @@ private static AwsServiceEndpoint GetServiceEndpoint(string localStackHost = nul service = "s3"; } - var awsServiceEndpoints = Config.GetAwsServiceEndpoints(localStackHost).ToList(); + var awsServiceEndpoints = Config.GetAwsServiceEndpoints(); return awsServiceEndpoints.SingleOrDefault(endpoint => endpoint.CliName == service); } - private static void Usage() { using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(UsageResource)) { - using (StreamReader reader = new StreamReader(stream)) + using (var reader = new StreamReader(stream)) { string result = reader.ReadToEnd(); Console.WriteLine(result); @@ -98,4 +98,4 @@ private static void Usage() Environment.Exit(0); } } -} +} \ No newline at end of file diff --git a/src/LocalStack.sln b/src/LocalStack.sln index 4ff6a88..c9138cf 100644 --- a/src/LocalStack.sln +++ b/src/LocalStack.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.28803.452 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalStack.AwsLocal", "LocalStack.AwsLocal\LocalStack.AwsLocal.csproj", "{D5116356-24F8-4B01-AB33-64CCFC5F0713}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalStack.AwsLocal", "LocalStack.AwsLocal\LocalStack.AwsLocal.csproj", "{D5116356-24F8-4B01-AB33-64CCFC5F0713}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution