From 5280f0732cce172aca876c67926d8d08f4c56065 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 19 Jun 2024 14:04:27 +0200 Subject: [PATCH] Sets up docker image for creating keys --- .github/workflows/docker-keymaker.yml | 27 ++++++++++++ Tools/KeyMaker/Controllers/KeyController.cs | 23 +++++++++++ Tools/KeyMaker/KeyMaker.csproj | 18 ++++++++ Tools/KeyMaker/KeyMaker.csproj.user | 6 +++ Tools/KeyMaker/KeyResponse.cs | 9 ++++ Tools/KeyMaker/Program.cs | 31 ++++++++++++++ Tools/KeyMaker/Properties/launchSettings.json | 41 +++++++++++++++++++ Tools/KeyMaker/appsettings.Development.json | 8 ++++ Tools/KeyMaker/appsettings.json | 9 ++++ Tools/KeyMaker/docker/Dockerfile | 26 ++++++++++++ cs-codex-dist-testing.sln | 7 ++++ 11 files changed, 205 insertions(+) create mode 100644 .github/workflows/docker-keymaker.yml create mode 100644 Tools/KeyMaker/Controllers/KeyController.cs create mode 100644 Tools/KeyMaker/KeyMaker.csproj create mode 100644 Tools/KeyMaker/KeyMaker.csproj.user create mode 100644 Tools/KeyMaker/KeyResponse.cs create mode 100644 Tools/KeyMaker/Program.cs create mode 100644 Tools/KeyMaker/Properties/launchSettings.json create mode 100644 Tools/KeyMaker/appsettings.Development.json create mode 100644 Tools/KeyMaker/appsettings.json create mode 100644 Tools/KeyMaker/docker/Dockerfile diff --git a/.github/workflows/docker-keymaker.yml b/.github/workflows/docker-keymaker.yml new file mode 100644 index 0000000..db067c3 --- /dev/null +++ b/.github/workflows/docker-keymaker.yml @@ -0,0 +1,27 @@ +name: Docker - KeyMaker + + +on: + push: + branches: + - master + tags: + - 'v*.*.*' + paths: + - 'Tools/KeyMaker/**' + - 'Framework/**' + - 'ProjectPlugins/**' + - .github/workflows/docker-KeyMaker.yml + - .github/workflows/docker-reusable.yml + workflow_dispatch: + + +jobs: + build-and-push: + name: Build and Push + uses: ./.github/workflows/docker-reusable.yml + with: + docker_file: Tools/KeyMaker/docker/Dockerfile + docker_repo: codexstorage/codex-keymaker + secrets: inherit + diff --git a/Tools/KeyMaker/Controllers/KeyController.cs b/Tools/KeyMaker/Controllers/KeyController.cs new file mode 100644 index 0000000..dd21889 --- /dev/null +++ b/Tools/KeyMaker/Controllers/KeyController.cs @@ -0,0 +1,23 @@ +using GethPlugin; +using Microsoft.AspNetCore.Mvc; + +namespace KeyMaker.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class KeyController : ControllerBase + { + [HttpGet] + public KeyResponse Get() + { + var account = EthAccount.GenerateNew(); + + return new KeyResponse + { + Public = account.EthAddress.Address, + Private = account.PrivateKey, + Secure = "Not Secure! For demo/development purposes only!" + }; + } + } +} diff --git a/Tools/KeyMaker/KeyMaker.csproj b/Tools/KeyMaker/KeyMaker.csproj new file mode 100644 index 0000000..9ee1ab2 --- /dev/null +++ b/Tools/KeyMaker/KeyMaker.csproj @@ -0,0 +1,18 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + + diff --git a/Tools/KeyMaker/KeyMaker.csproj.user b/Tools/KeyMaker/KeyMaker.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/Tools/KeyMaker/KeyMaker.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/Tools/KeyMaker/KeyResponse.cs b/Tools/KeyMaker/KeyResponse.cs new file mode 100644 index 0000000..df8fb0b --- /dev/null +++ b/Tools/KeyMaker/KeyResponse.cs @@ -0,0 +1,9 @@ +namespace KeyMaker +{ + public class KeyResponse + { + public string Public { get; set; } = string.Empty; + public string Private { get; set; } = string.Empty; + public string Secure { get; set; } = string.Empty; + } +} diff --git a/Tools/KeyMaker/Program.cs b/Tools/KeyMaker/Program.cs new file mode 100644 index 0000000..9c24f8f --- /dev/null +++ b/Tools/KeyMaker/Program.cs @@ -0,0 +1,31 @@ +var builder = WebApplication.CreateBuilder(args); + +var listenPort = Environment.GetEnvironmentVariable("APIPORT"); +if (string.IsNullOrEmpty(listenPort)) listenPort = "31090"; + +builder.WebHost.ConfigureKestrel((context, options) => +{ + options.ListenAnyIP(Convert.ToInt32(listenPort)); +}); + +builder.Services.AddControllers(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +Console.WriteLine("KeyMaker listening on port " + listenPort); + +app.Run(); diff --git a/Tools/KeyMaker/Properties/launchSettings.json b/Tools/KeyMaker/Properties/launchSettings.json new file mode 100644 index 0000000..7517b23 --- /dev/null +++ b/Tools/KeyMaker/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:17248", + "sslPort": 44396 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5069", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7056;http://localhost:5069", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Tools/KeyMaker/appsettings.Development.json b/Tools/KeyMaker/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Tools/KeyMaker/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Tools/KeyMaker/appsettings.json b/Tools/KeyMaker/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Tools/KeyMaker/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Tools/KeyMaker/docker/Dockerfile b/Tools/KeyMaker/docker/Dockerfile new file mode 100644 index 0000000..74d929b --- /dev/null +++ b/Tools/KeyMaker/docker/Dockerfile @@ -0,0 +1,26 @@ +# Variables +ARG BUILDER=mcr.microsoft.com/dotnet/sdk:7.0 +ARG IMAGE=${BUILDER} +ARG APP_HOME=/app + + +# Build +FROM ${IMAGE} AS builder +ARG APP_HOME + +WORKDIR ${APP_HOME} +COPY ./Tools/KeyMaker ./Tools/KeyMaker +COPY ./Framework ./Framework +COPY ./ProjectPlugins ./ProjectPlugins +RUN dotnet restore Tools/KeyMaker +RUN dotnet publish Tools/KeyMaker -c Release -o out + + +# Create +FROM ${IMAGE} +ARG APP_HOME +ENV APP_HOME=${APP_HOME} + +WORKDIR ${APP_HOME} +COPY --from=builder ${APP_HOME}/out . +CMD dotnet ${APP_HOME}/KeyMaker.dll diff --git a/cs-codex-dist-testing.sln b/cs-codex-dist-testing.sln index ada6893..beec9e6 100644 --- a/cs-codex-dist-testing.sln +++ b/cs-codex-dist-testing.sln @@ -66,6 +66,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KeyMaker", "Tools\KeyMaker\KeyMaker.csproj", "{B57A4789-D8EF-42E0-8D20-581C4057FFD3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -172,6 +174,10 @@ Global {88C212E9-308A-46A4-BAAD-468E8EBD8EDF}.Debug|Any CPU.Build.0 = Debug|Any CPU {88C212E9-308A-46A4-BAAD-468E8EBD8EDF}.Release|Any CPU.ActiveCfg = Release|Any CPU {88C212E9-308A-46A4-BAAD-468E8EBD8EDF}.Release|Any CPU.Build.0 = Release|Any CPU + {B57A4789-D8EF-42E0-8D20-581C4057FFD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B57A4789-D8EF-42E0-8D20-581C4057FFD3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B57A4789-D8EF-42E0-8D20-581C4057FFD3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B57A4789-D8EF-42E0-8D20-581C4057FFD3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -202,6 +208,7 @@ Global {F730DA73-1C92-4107-BCFB-D33759DAB0C3} = {81AE04BC-CBFA-4E6F-B039-8208E9AFAAE7} {B07820C4-309F-4454-BCC1-1D4902C9C67B} = {81AE04BC-CBFA-4E6F-B039-8208E9AFAAE7} {88C212E9-308A-46A4-BAAD-468E8EBD8EDF} = {8F1F1C2A-E313-4E0C-BE40-58FB0BA91124} + {B57A4789-D8EF-42E0-8D20-581C4057FFD3} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {237BF0AA-9EC4-4659-AD9A-65DEB974250C}