Skip to content

Commit

Permalink
* Add LocalStack.Client as git submodule
Browse files Browse the repository at this point in the history
* Clean up code
  • Loading branch information
Blind-Striker committed May 21, 2019
1 parent c781197 commit f378ec4
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,8 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/

testrunner

# Cake
[Tt]ools/
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "depedencies/localstack-dotnet-client"]
path = depedencies/localstack-dotnet-client
url = [email protected]:localstack-dotnet/localstack-dotnet-client.git
branch = v0.8.0.163
5 changes: 5 additions & 0 deletions depedencies/README.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions depedencies/localstack-dotnet-client
22 changes: 13 additions & 9 deletions src/LocalStack.AwsLocal/LocalStack.AwsLocal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.2</TargetFrameworks>

<PackAsTool>true</PackAsTool>
<ToolCommandName>awslocal</ToolCommandName>
<PackAsTool>true</PackAsTool>
</PropertyGroup>

<ItemGroup>
<None Remove="usage.txt" />
</ItemGroup>
<Folder Include="Depedencies\Contracts\" />
<Folder Include="Depedencies\Models\" />
<Folder Include="Depedencies\Enums\" />

<ItemGroup>
<EmbeddedResource Include="Usage.txt" />
<Compile Include="..\..\depedencies\localstack-dotnet-client\src\LocalStack.Client\Config.cs" Link="Depedencies\Config.cs" />
<Compile Include="..\..\depedencies\localstack-dotnet-client\src\LocalStack.Client\Contracts\IConfig.cs" Link="Depedencies\Contracts\IConfig.cs" />
<Compile Include="..\..\depedencies\localstack-dotnet-client\src\LocalStack.Client\Enums\AwsServiceEndpointMetadata.cs" Link="Depedencies\Enums\AwsServiceEndpointMetadata.cs" />
<Compile Include="..\..\depedencies\localstack-dotnet-client\src\LocalStack.Client\Enums\AwsServiceEnum.cs" Link="Depedencies\Enums\AwsServiceEnum.cs" />
<Compile Include="..\..\depedencies\localstack-dotnet-client\src\LocalStack.Client\Models\AwsServiceEndpoint.cs" Link="Depedencies\Models\AwsServiceEndpoint.cs" />

<None Include="..\..\depedencies\README.md" Link="Depedencies\README.md" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="LocalStack.Client" Version="0.0.1" />
<EmbeddedResource Include="Usage.txt" />
</ItemGroup>

</Project>
</Project>
7 changes: 3 additions & 4 deletions src/LocalStack.AwsLocal/ProcessHelper.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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;
Expand Down Expand Up @@ -87,4 +86,4 @@ public int CmdExecute(string command, string workingDirectoryPath = null, bool o
}
}
}
}
}
38 changes: 19 additions & 19 deletions src/LocalStack.AwsLocal/Program.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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<string> 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)
Expand All @@ -53,7 +54,7 @@ static void Main(string[] args)
ProcessHelper.CmdExecute(string.Join(' ', arguments), null, true, true, new Dictionary<string, string>
{
{"AWS_DEFAULT_REGION", awsDefaultRegion},
{ "AWS_ACCESS_KEY_ID", awsAccessKeyId},
{"AWS_ACCESS_KEY_ID", awsAccessKeyId},
{"AWS_SECRET_ACCESS_KEY", awsSecretAccessKey}
});
}
Expand All @@ -71,24 +72,23 @@ private static string GetService()
return string.Empty;
}

private static AwsServiceEndpoint GetServiceEndpoint(string localStackHost = null)
private static AwsServiceEndpoint GetServiceEndpoint()
{
string service = GetService();
if (service == "s3api")
{
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);
Expand All @@ -98,4 +98,4 @@ private static void Usage()
Environment.Exit(0);
}
}
}
}
2 changes: 1 addition & 1 deletion src/LocalStack.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f378ec4

Please sign in to comment.