From a4232d8e59d5cbf30691faa5f47339f853152d27 Mon Sep 17 00:00:00 2001 From: Nishchal Date: Sun, 13 Jun 2021 15:07:24 +0700 Subject: [PATCH 1/4] chore(*): refactor storage into separate project --- .../Controllers/WeatherForecast.cs | 15 ------- .../Controllers/WeatherForecastController.cs | 40 ------------------- .../Configs/SlackLoggingConfig.cs | 2 +- .../HealthCheck/ConnectionToDbCheck.cs | 4 +- .../{ => Internal}/HealthCheck/MemoryCheck.cs | 2 +- .../StartupExtensions/Configuration.cs | 5 ++- .../StartupExtensions/Database.cs | 4 +- .../StartupExtensions/DependencyInjection.cs | 7 ++-- .../StartupExtensions/HealthChecks.cs | 4 +- .../StartupExtensions/Logger.cs | 4 +- .../StartupExtensions/Swagger.cs | 2 +- .../StartupExtensions/Workers.cs | 4 +- .../{ => Internal}/Workers/Worker.cs | 4 +- Micro.Starter.Api/Micro.Starter.Api.csproj | 12 +++++- Micro.Starter.Api/Program.cs | 4 +- .../Repository/IWeatherRepository.cs | 15 ------- Micro.Starter.Api/Startup.cs | 4 +- .../Micro.Starter.Common.csproj | 7 ++++ .../Uuid/IUuidService.cs | 2 +- .../Uuid/UuidService.cs | 2 +- .../ApplicationContext.cs | 3 +- .../DatabaseConfig.cs | 2 +- .../Micro.Starter.Storage.csproj | 17 ++++++++ .../20210613080356_InitialCreate.Designer.cs | 14 +++---- .../20210613080356_InitialCreate.cs | 6 +-- .../ApplicationContextModelSnapshot.cs | 12 +++--- .../Weather.cs | 2 +- .../WeatherRepository.cs | 14 +++++-- Micro.Starter.UnitTest/UnitTest1.cs | 2 +- Micro.Starter.sln | 12 ++++++ 30 files changed, 104 insertions(+), 123 deletions(-) delete mode 100644 Micro.Starter.Api/Controllers/WeatherForecast.cs delete mode 100644 Micro.Starter.Api/Controllers/WeatherForecastController.cs rename Micro.Starter.Api/{ => Internal}/Configs/SlackLoggingConfig.cs (80%) rename Micro.Starter.Api/{ => Internal}/HealthCheck/ConnectionToDbCheck.cs (92%) rename Micro.Starter.Api/{ => Internal}/HealthCheck/MemoryCheck.cs (95%) rename Micro.Starter.Api/{ => Internal}/StartupExtensions/Configuration.cs (79%) rename Micro.Starter.Api/{ => Internal}/StartupExtensions/Database.cs (94%) rename Micro.Starter.Api/{ => Internal}/StartupExtensions/DependencyInjection.cs (74%) rename Micro.Starter.Api/{ => Internal}/StartupExtensions/HealthChecks.cs (94%) rename Micro.Starter.Api/{ => Internal}/StartupExtensions/Logger.cs (87%) rename Micro.Starter.Api/{ => Internal}/StartupExtensions/Swagger.cs (94%) rename Micro.Starter.Api/{ => Internal}/StartupExtensions/Workers.cs (71%) rename Micro.Starter.Api/{ => Internal}/Workers/Worker.cs (94%) delete mode 100644 Micro.Starter.Api/Repository/IWeatherRepository.cs create mode 100644 Micro.Starter.Common/Micro.Starter.Common.csproj rename {Micro.Starter.Api => Micro.Starter.Common}/Uuid/IUuidService.cs (69%) rename {Micro.Starter.Api => Micro.Starter.Common}/Uuid/UuidService.cs (82%) rename {Micro.Starter.Api/Models => Micro.Starter.Storage}/ApplicationContext.cs (94%) rename {Micro.Starter.Api/Configs => Micro.Starter.Storage}/DatabaseConfig.cs (87%) create mode 100644 Micro.Starter.Storage/Micro.Starter.Storage.csproj rename Micro.Starter.Api/Migrations/20190828165715_InitialCreate.Designer.cs => Micro.Starter.Storage/Migrations/20210613080356_InitialCreate.Designer.cs (75%) rename Micro.Starter.Api/Migrations/20190828165715_InitialCreate.cs => Micro.Starter.Storage/Migrations/20210613080356_InitialCreate.cs (75%) rename {Micro.Starter.Api => Micro.Starter.Storage}/Migrations/ApplicationContextModelSnapshot.cs (77%) rename {Micro.Starter.Api/Models => Micro.Starter.Storage}/Weather.cs (78%) rename {Micro.Starter.Api/Repository => Micro.Starter.Storage}/WeatherRepository.cs (78%) diff --git a/Micro.Starter.Api/Controllers/WeatherForecast.cs b/Micro.Starter.Api/Controllers/WeatherForecast.cs deleted file mode 100644 index cc6143f..0000000 --- a/Micro.Starter.Api/Controllers/WeatherForecast.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace Micro.Starter.Api.Controllers -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int) (TemperatureC / 0.5556); - - public string Summary { get; set; } - } -} diff --git a/Micro.Starter.Api/Controllers/WeatherForecastController.cs b/Micro.Starter.Api/Controllers/WeatherForecastController.cs deleted file mode 100644 index 8a6ebf7..0000000 --- a/Micro.Starter.Api/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; - -namespace Micro.Starter.Api.Controllers -{ - [ApiController] - [Route("api/[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] - public IEnumerable Get() - { - var rng = new Random(); - return Enumerable.Range(1, 8).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} diff --git a/Micro.Starter.Api/Configs/SlackLoggingConfig.cs b/Micro.Starter.Api/Internal/Configs/SlackLoggingConfig.cs similarity index 80% rename from Micro.Starter.Api/Configs/SlackLoggingConfig.cs rename to Micro.Starter.Api/Internal/Configs/SlackLoggingConfig.cs index 7668d90..9199670 100644 --- a/Micro.Starter.Api/Configs/SlackLoggingConfig.cs +++ b/Micro.Starter.Api/Internal/Configs/SlackLoggingConfig.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Logging; -namespace Micro.Starter.Api.Configs +namespace Micro.Starter.Api.Internal.Configs { public class SlackLoggingConfig { diff --git a/Micro.Starter.Api/HealthCheck/ConnectionToDbCheck.cs b/Micro.Starter.Api/Internal/HealthCheck/ConnectionToDbCheck.cs similarity index 92% rename from Micro.Starter.Api/HealthCheck/ConnectionToDbCheck.cs rename to Micro.Starter.Api/Internal/HealthCheck/ConnectionToDbCheck.cs index 7d94dc4..ca3100a 100644 --- a/Micro.Starter.Api/HealthCheck/ConnectionToDbCheck.cs +++ b/Micro.Starter.Api/Internal/HealthCheck/ConnectionToDbCheck.cs @@ -1,9 +1,9 @@ using System.Threading; using System.Threading.Tasks; -using Micro.Starter.Api.Models; +using Micro.Starter.Storage; using Microsoft.Extensions.Diagnostics.HealthChecks; -namespace Micro.Starter.Api.HealthCheck +namespace Micro.Starter.Api.Internal.HealthCheck { public class ConnectionToDbCheck : IHealthCheck { diff --git a/Micro.Starter.Api/HealthCheck/MemoryCheck.cs b/Micro.Starter.Api/Internal/HealthCheck/MemoryCheck.cs similarity index 95% rename from Micro.Starter.Api/HealthCheck/MemoryCheck.cs rename to Micro.Starter.Api/Internal/HealthCheck/MemoryCheck.cs index f0731e3..fac4921 100644 --- a/Micro.Starter.Api/HealthCheck/MemoryCheck.cs +++ b/Micro.Starter.Api/Internal/HealthCheck/MemoryCheck.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.Diagnostics.HealthChecks; -namespace Micro.Starter.Api.HealthCheck +namespace Micro.Starter.Api.Internal.HealthCheck { public class MemoryCheck : IHealthCheck { diff --git a/Micro.Starter.Api/StartupExtensions/Configuration.cs b/Micro.Starter.Api/Internal/StartupExtensions/Configuration.cs similarity index 79% rename from Micro.Starter.Api/StartupExtensions/Configuration.cs rename to Micro.Starter.Api/Internal/StartupExtensions/Configuration.cs index 1169339..6f3a068 100644 --- a/Micro.Starter.Api/StartupExtensions/Configuration.cs +++ b/Micro.Starter.Api/Internal/StartupExtensions/Configuration.cs @@ -1,8 +1,9 @@ -using Micro.Starter.Api.Configs; +using Micro.Starter.Api.Internal.Configs; +using Micro.Starter.Storage; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -namespace Micro.Starter.Api.StartupExtensions +namespace Micro.Starter.Api.Internal.StartupExtensions { public static class Configuration { diff --git a/Micro.Starter.Api/StartupExtensions/Database.cs b/Micro.Starter.Api/Internal/StartupExtensions/Database.cs similarity index 94% rename from Micro.Starter.Api/StartupExtensions/Database.cs rename to Micro.Starter.Api/Internal/StartupExtensions/Database.cs index ff8f349..6a4d2d0 100644 --- a/Micro.Starter.Api/StartupExtensions/Database.cs +++ b/Micro.Starter.Api/Internal/StartupExtensions/Database.cs @@ -1,12 +1,12 @@ using System; using System.Threading.Tasks; -using Micro.Starter.Api.Models; +using Micro.Starter.Storage; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.Logging; -namespace Micro.Starter.Api.StartupExtensions +namespace Micro.Starter.Api.Internal.StartupExtensions { public static class Database { diff --git a/Micro.Starter.Api/StartupExtensions/DependencyInjection.cs b/Micro.Starter.Api/Internal/StartupExtensions/DependencyInjection.cs similarity index 74% rename from Micro.Starter.Api/StartupExtensions/DependencyInjection.cs rename to Micro.Starter.Api/Internal/StartupExtensions/DependencyInjection.cs index a1f726c..a1b316d 100644 --- a/Micro.Starter.Api/StartupExtensions/DependencyInjection.cs +++ b/Micro.Starter.Api/Internal/StartupExtensions/DependencyInjection.cs @@ -1,9 +1,8 @@ -using Micro.Starter.Api.Models; -using Micro.Starter.Api.Repository; -using Micro.Starter.Api.Uuid; +using Micro.Starter.Common.Uuid; +using Micro.Starter.Storage; using Microsoft.Extensions.DependencyInjection; -namespace Micro.Starter.Api.StartupExtensions +namespace Micro.Starter.Api.Internal.StartupExtensions { public static class DependencyInjection { diff --git a/Micro.Starter.Api/StartupExtensions/HealthChecks.cs b/Micro.Starter.Api/Internal/StartupExtensions/HealthChecks.cs similarity index 94% rename from Micro.Starter.Api/StartupExtensions/HealthChecks.cs rename to Micro.Starter.Api/Internal/StartupExtensions/HealthChecks.cs index b0bf64a..f796b7c 100644 --- a/Micro.Starter.Api/StartupExtensions/HealthChecks.cs +++ b/Micro.Starter.Api/Internal/StartupExtensions/HealthChecks.cs @@ -1,6 +1,6 @@ using System.Linq; using System.Threading.Tasks; -using Micro.Starter.Api.HealthCheck; +using Micro.Starter.Api.Internal.HealthCheck; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Http; @@ -10,7 +10,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace Micro.Starter.Api.StartupExtensions +namespace Micro.Starter.Api.Internal.StartupExtensions { public static class HealthChecks { diff --git a/Micro.Starter.Api/StartupExtensions/Logger.cs b/Micro.Starter.Api/Internal/StartupExtensions/Logger.cs similarity index 87% rename from Micro.Starter.Api/StartupExtensions/Logger.cs rename to Micro.Starter.Api/Internal/StartupExtensions/Logger.cs index 72b3632..63b67eb 100644 --- a/Micro.Starter.Api/StartupExtensions/Logger.cs +++ b/Micro.Starter.Api/Internal/StartupExtensions/Logger.cs @@ -1,10 +1,10 @@ using System; -using Micro.Starter.Api.Configs; +using Micro.Starter.Api.Internal.Configs; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Slack; -namespace Micro.Starter.Api.StartupExtensions +namespace Micro.Starter.Api.Internal.StartupExtensions { public static class Logger { diff --git a/Micro.Starter.Api/StartupExtensions/Swagger.cs b/Micro.Starter.Api/Internal/StartupExtensions/Swagger.cs similarity index 94% rename from Micro.Starter.Api/StartupExtensions/Swagger.cs rename to Micro.Starter.Api/Internal/StartupExtensions/Swagger.cs index a9f79d1..e3983a5 100644 --- a/Micro.Starter.Api/StartupExtensions/Swagger.cs +++ b/Micro.Starter.Api/Internal/StartupExtensions/Swagger.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; -namespace Micro.Starter.Api.StartupExtensions +namespace Micro.Starter.Api.Internal.StartupExtensions { public static class Swagger { diff --git a/Micro.Starter.Api/StartupExtensions/Workers.cs b/Micro.Starter.Api/Internal/StartupExtensions/Workers.cs similarity index 71% rename from Micro.Starter.Api/StartupExtensions/Workers.cs rename to Micro.Starter.Api/Internal/StartupExtensions/Workers.cs index 83d1fe6..936f92d 100644 --- a/Micro.Starter.Api/StartupExtensions/Workers.cs +++ b/Micro.Starter.Api/Internal/StartupExtensions/Workers.cs @@ -1,7 +1,7 @@ -using Micro.Starter.Api.Workers; +using Micro.Starter.Api.Internal.Workers; using Microsoft.Extensions.DependencyInjection; -namespace Micro.Starter.Api.StartupExtensions +namespace Micro.Starter.Api.Internal.StartupExtensions { public static class Workers { diff --git a/Micro.Starter.Api/Workers/Worker.cs b/Micro.Starter.Api/Internal/Workers/Worker.cs similarity index 94% rename from Micro.Starter.Api/Workers/Worker.cs rename to Micro.Starter.Api/Internal/Workers/Worker.cs index 36e5c66..43d691e 100644 --- a/Micro.Starter.Api/Workers/Worker.cs +++ b/Micro.Starter.Api/Internal/Workers/Worker.cs @@ -1,12 +1,12 @@ using System; using System.Threading; using System.Threading.Tasks; -using Micro.Starter.Api.Repository; +using Micro.Starter.Storage; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -namespace Micro.Starter.Api.Workers +namespace Micro.Starter.Api.Internal.Workers { public class Worker : BackgroundService { diff --git a/Micro.Starter.Api/Micro.Starter.Api.csproj b/Micro.Starter.Api/Micro.Starter.Api.csproj index f8ab73f..353238f 100644 --- a/Micro.Starter.Api/Micro.Starter.Api.csproj +++ b/Micro.Starter.Api/Micro.Starter.Api.csproj @@ -9,17 +9,25 @@ + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + + + + + + diff --git a/Micro.Starter.Api/Program.cs b/Micro.Starter.Api/Program.cs index 85518e1..03087b4 100644 --- a/Micro.Starter.Api/Program.cs +++ b/Micro.Starter.Api/Program.cs @@ -4,8 +4,8 @@ using App.Metrics.AspNetCore; using App.Metrics.Extensions.Configuration; using App.Metrics.Formatters.InfluxDB; -using Micro.Starter.Api.Models; -using Micro.Starter.Api.StartupExtensions; +using Micro.Starter.Api.Internal.StartupExtensions; +using Micro.Starter.Storage; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.Configuration; diff --git a/Micro.Starter.Api/Repository/IWeatherRepository.cs b/Micro.Starter.Api/Repository/IWeatherRepository.cs deleted file mode 100644 index c0cce8b..0000000 --- a/Micro.Starter.Api/Repository/IWeatherRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Threading.Tasks; -using Micro.Starter.Api.Models; - -namespace Micro.Starter.Api.Repository -{ - public interface IWeatherRepository - { - Task> GetAll(); - Task FindById(string id); - Task Create([NotNull] Weather weather); - Task Delete(string id); - } -} diff --git a/Micro.Starter.Api/Startup.cs b/Micro.Starter.Api/Startup.cs index 835bca4..09ca9cd 100644 --- a/Micro.Starter.Api/Startup.cs +++ b/Micro.Starter.Api/Startup.cs @@ -1,5 +1,5 @@ -using Micro.Starter.Api.Configs; -using Micro.Starter.Api.StartupExtensions; +using Micro.Starter.Api.Internal.Configs; +using Micro.Starter.Api.Internal.StartupExtensions; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; diff --git a/Micro.Starter.Common/Micro.Starter.Common.csproj b/Micro.Starter.Common/Micro.Starter.Common.csproj new file mode 100644 index 0000000..cbfa581 --- /dev/null +++ b/Micro.Starter.Common/Micro.Starter.Common.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/Micro.Starter.Api/Uuid/IUuidService.cs b/Micro.Starter.Common/Uuid/IUuidService.cs similarity index 69% rename from Micro.Starter.Api/Uuid/IUuidService.cs rename to Micro.Starter.Common/Uuid/IUuidService.cs index 1b6c7c8..727b9e8 100644 --- a/Micro.Starter.Api/Uuid/IUuidService.cs +++ b/Micro.Starter.Common/Uuid/IUuidService.cs @@ -1,4 +1,4 @@ -namespace Micro.Starter.Api.Uuid +namespace Micro.Starter.Common.Uuid { public interface IUuidService { diff --git a/Micro.Starter.Api/Uuid/UuidService.cs b/Micro.Starter.Common/Uuid/UuidService.cs similarity index 82% rename from Micro.Starter.Api/Uuid/UuidService.cs rename to Micro.Starter.Common/Uuid/UuidService.cs index 505bd5d..c925dae 100644 --- a/Micro.Starter.Api/Uuid/UuidService.cs +++ b/Micro.Starter.Common/Uuid/UuidService.cs @@ -1,4 +1,4 @@ -namespace Micro.Starter.Api.Uuid +namespace Micro.Starter.Common.Uuid { public class UuidService : IUuidService { diff --git a/Micro.Starter.Api/Models/ApplicationContext.cs b/Micro.Starter.Storage/ApplicationContext.cs similarity index 94% rename from Micro.Starter.Api/Models/ApplicationContext.cs rename to Micro.Starter.Storage/ApplicationContext.cs index 86e6569..3f66d95 100644 --- a/Micro.Starter.Api/Models/ApplicationContext.cs +++ b/Micro.Starter.Storage/ApplicationContext.cs @@ -1,9 +1,8 @@ -using Micro.Starter.Api.Configs; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; using Npgsql; -namespace Micro.Starter.Api.Models +namespace Micro.Starter.Storage { public class ApplicationContext : DbContext { diff --git a/Micro.Starter.Api/Configs/DatabaseConfig.cs b/Micro.Starter.Storage/DatabaseConfig.cs similarity index 87% rename from Micro.Starter.Api/Configs/DatabaseConfig.cs rename to Micro.Starter.Storage/DatabaseConfig.cs index 35ad90e..f051938 100644 --- a/Micro.Starter.Api/Configs/DatabaseConfig.cs +++ b/Micro.Starter.Storage/DatabaseConfig.cs @@ -1,4 +1,4 @@ -namespace Micro.Starter.Api.Configs +namespace Micro.Starter.Storage { public class DatabaseConfig { diff --git a/Micro.Starter.Storage/Micro.Starter.Storage.csproj b/Micro.Starter.Storage/Micro.Starter.Storage.csproj new file mode 100644 index 0000000..eda6d68 --- /dev/null +++ b/Micro.Starter.Storage/Micro.Starter.Storage.csproj @@ -0,0 +1,17 @@ + + + + net5.0 + + + + + + + + + + + + + diff --git a/Micro.Starter.Api/Migrations/20190828165715_InitialCreate.Designer.cs b/Micro.Starter.Storage/Migrations/20210613080356_InitialCreate.Designer.cs similarity index 75% rename from Micro.Starter.Api/Migrations/20190828165715_InitialCreate.Designer.cs rename to Micro.Starter.Storage/Migrations/20210613080356_InitialCreate.Designer.cs index d32ae7a..7dbc11d 100644 --- a/Micro.Starter.Api/Migrations/20190828165715_InitialCreate.Designer.cs +++ b/Micro.Starter.Storage/Migrations/20210613080356_InitialCreate.Designer.cs @@ -1,26 +1,26 @@ // -using Micro.Starter.Api.Models; +using Micro.Starter.Storage; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -namespace Micro.Starter.Api.Migrations +namespace Micro.Starter.Storage.Migrations { [DbContext(typeof(ApplicationContext))] - [Migration("20190828165715_InitialCreate")] + [Migration("20210613080356_InitialCreate")] partial class InitialCreate { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .HasAnnotation("ProductVersion", "3.0.0-preview8.19405.11") - .HasAnnotation("Relational:MaxIdentifierLength", 63); + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.6") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - modelBuilder.Entity("Micro.Starter.Api.Models.Weather", b => + modelBuilder.Entity("Micro.Starter.Storage.Weather", b => { b.Property("Id") .HasColumnType("text"); diff --git a/Micro.Starter.Api/Migrations/20190828165715_InitialCreate.cs b/Micro.Starter.Storage/Migrations/20210613080356_InitialCreate.cs similarity index 75% rename from Micro.Starter.Api/Migrations/20190828165715_InitialCreate.cs rename to Micro.Starter.Storage/Migrations/20210613080356_InitialCreate.cs index 16feb97..63cbc1d 100644 --- a/Micro.Starter.Api/Migrations/20190828165715_InitialCreate.cs +++ b/Micro.Starter.Storage/Migrations/20210613080356_InitialCreate.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore.Migrations; -namespace Micro.Starter.Api.Migrations +namespace Micro.Starter.Storage.Migrations { public partial class InitialCreate : Migration { @@ -10,8 +10,8 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Weathers", columns: table => new { - Id = table.Column(nullable: false), - Temperature = table.Column(nullable: false) + Id = table.Column(type: "text", nullable: false), + Temperature = table.Column(type: "double precision", nullable: false) }, constraints: table => { diff --git a/Micro.Starter.Api/Migrations/ApplicationContextModelSnapshot.cs b/Micro.Starter.Storage/Migrations/ApplicationContextModelSnapshot.cs similarity index 77% rename from Micro.Starter.Api/Migrations/ApplicationContextModelSnapshot.cs rename to Micro.Starter.Storage/Migrations/ApplicationContextModelSnapshot.cs index 036fa32..8663448 100644 --- a/Micro.Starter.Api/Migrations/ApplicationContextModelSnapshot.cs +++ b/Micro.Starter.Storage/Migrations/ApplicationContextModelSnapshot.cs @@ -1,11 +1,11 @@ // -using Micro.Starter.Api.Models; +using Micro.Starter.Storage; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -namespace Micro.Starter.Api.Migrations +namespace Micro.Starter.Storage.Migrations { [DbContext(typeof(ApplicationContext))] partial class ApplicationContextModelSnapshot : ModelSnapshot @@ -14,11 +14,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .HasAnnotation("ProductVersion", "3.0.0-preview8.19405.11") - .HasAnnotation("Relational:MaxIdentifierLength", 63); + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.6") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - modelBuilder.Entity("Micro.Starter.Api.Models.Weather", b => + modelBuilder.Entity("Micro.Starter.Storage.Weather", b => { b.Property("Id") .HasColumnType("text"); diff --git a/Micro.Starter.Api/Models/Weather.cs b/Micro.Starter.Storage/Weather.cs similarity index 78% rename from Micro.Starter.Api/Models/Weather.cs rename to Micro.Starter.Storage/Weather.cs index 9ba7763..4010c20 100644 --- a/Micro.Starter.Api/Models/Weather.cs +++ b/Micro.Starter.Storage/Weather.cs @@ -1,4 +1,4 @@ -namespace Micro.Starter.Api.Models +namespace Micro.Starter.Storage { public class Weather { diff --git a/Micro.Starter.Api/Repository/WeatherRepository.cs b/Micro.Starter.Storage/WeatherRepository.cs similarity index 78% rename from Micro.Starter.Api/Repository/WeatherRepository.cs rename to Micro.Starter.Storage/WeatherRepository.cs index c7b2727..5d76bbf 100644 --- a/Micro.Starter.Api/Repository/WeatherRepository.cs +++ b/Micro.Starter.Storage/WeatherRepository.cs @@ -1,12 +1,20 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; -using Micro.Starter.Api.Models; -using Micro.Starter.Api.Uuid; +using Micro.Starter.Common.Uuid; using Microsoft.EntityFrameworkCore; -namespace Micro.Starter.Api.Repository +namespace Micro.Starter.Storage { + public interface IWeatherRepository + { + Task> GetAll(); + Task FindById(string id); + Task Create([NotNull] Weather weather); + Task Delete(string id); + } + public class WeatherRepository : IWeatherRepository { private readonly ApplicationContext _db; diff --git a/Micro.Starter.UnitTest/UnitTest1.cs b/Micro.Starter.UnitTest/UnitTest1.cs index 9723a67..6e0d1e6 100644 --- a/Micro.Starter.UnitTest/UnitTest1.cs +++ b/Micro.Starter.UnitTest/UnitTest1.cs @@ -1,6 +1,6 @@ using NUnit.Framework; -namespace Tests +namespace Micro.Starter.UnitTest { public class Tests { diff --git a/Micro.Starter.sln b/Micro.Starter.sln index 6cfc22e..3f5c03f 100644 --- a/Micro.Starter.sln +++ b/Micro.Starter.sln @@ -4,6 +4,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Micro.Starter.Api", "Micro. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Micro.Starter.UnitTest", "Micro.Starter.UnitTest\Micro.Starter.UnitTest.csproj", "{4384EF12-1CE6-4672-BC61-2F20F83D2744}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Micro.Starter.Storage", "Micro.Starter.Storage\Micro.Starter.Storage.csproj", "{06038A4F-82E8-4AA4-8A37-6B8450B7E06A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Micro.Starter.Common", "Micro.Starter.Common\Micro.Starter.Common.csproj", "{21EB1C0F-3AF3-475C-8667-1BF3B351DABA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,5 +22,13 @@ Global {4384EF12-1CE6-4672-BC61-2F20F83D2744}.Debug|Any CPU.Build.0 = Debug|Any CPU {4384EF12-1CE6-4672-BC61-2F20F83D2744}.Release|Any CPU.ActiveCfg = Release|Any CPU {4384EF12-1CE6-4672-BC61-2F20F83D2744}.Release|Any CPU.Build.0 = Release|Any CPU + {06038A4F-82E8-4AA4-8A37-6B8450B7E06A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06038A4F-82E8-4AA4-8A37-6B8450B7E06A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06038A4F-82E8-4AA4-8A37-6B8450B7E06A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06038A4F-82E8-4AA4-8A37-6B8450B7E06A}.Release|Any CPU.Build.0 = Release|Any CPU + {21EB1C0F-3AF3-475C-8667-1BF3B351DABA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {21EB1C0F-3AF3-475C-8667-1BF3B351DABA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {21EB1C0F-3AF3-475C-8667-1BF3B351DABA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {21EB1C0F-3AF3-475C-8667-1BF3B351DABA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal From 65eefc6f8f34a169b87a7204da92fa0576a134de Mon Sep 17 00:00:00 2001 From: Nishchal Date: Sun, 13 Jun 2021 15:43:31 +0700 Subject: [PATCH 2/4] feat(graphql): enable federated graphql BREAKING CHANGE: old endpoints no longer work, controllers are removed --- .../GraphQL/Directives/AuthorizeDirective.cs | 50 +++++++++++++++++ .../Exceptions/NotAuthorizedException.cs | 11 ++++ .../GraphQL/Extensions/Directives.cs | 21 +++++++ .../GraphQL/Extensions/Startup.cs | 56 +++++++++++++++++++ Micro.Starter.Api/GraphQL/Query.cs | 21 +++++++ Micro.Starter.Api/GraphQL/StarterSchema.cs | 17 ++++++ Micro.Starter.Api/GraphQL/Types/EntityType.cs | 10 ++++ .../GraphQL/Types/WeatherType.cs | 21 +++++++ .../StartupExtensions/DependencyInjection.cs | 1 + Micro.Starter.Api/Micro.Starter.Api.csproj | 39 +++++++------ Micro.Starter.Api/Startup.cs | 3 + 11 files changed, 234 insertions(+), 16 deletions(-) create mode 100644 Micro.Starter.Api/GraphQL/Directives/AuthorizeDirective.cs create mode 100644 Micro.Starter.Api/GraphQL/Directives/Exceptions/NotAuthorizedException.cs create mode 100644 Micro.Starter.Api/GraphQL/Extensions/Directives.cs create mode 100644 Micro.Starter.Api/GraphQL/Extensions/Startup.cs create mode 100644 Micro.Starter.Api/GraphQL/Query.cs create mode 100644 Micro.Starter.Api/GraphQL/StarterSchema.cs create mode 100644 Micro.Starter.Api/GraphQL/Types/EntityType.cs create mode 100644 Micro.Starter.Api/GraphQL/Types/WeatherType.cs diff --git a/Micro.Starter.Api/GraphQL/Directives/AuthorizeDirective.cs b/Micro.Starter.Api/GraphQL/Directives/AuthorizeDirective.cs new file mode 100644 index 0000000..6aa9031 --- /dev/null +++ b/Micro.Starter.Api/GraphQL/Directives/AuthorizeDirective.cs @@ -0,0 +1,50 @@ +using GraphQL; +using GraphQL.Resolvers; +using GraphQL.Types; +using GraphQL.Utilities; +using Micro.Starter.Api.GraphQL.Directives.Exceptions; +using Microsoft.AspNetCore.Http; + +namespace Micro.Starter.Api.GraphQL.Directives +{ + public class AuthorizeDirective : DirectiveGraphType + { + public const string DirectiveName = "authorize"; + public override bool? Introspectable => true; + + public AuthorizeDirective() : base( + DirectiveName, + DirectiveLocation.Field, + DirectiveLocation.Mutation, + DirectiveLocation.Query, + DirectiveLocation.FieldDefinition) + { + } + } + public class AuthorizeDirectiveVisitor : BaseSchemaNodeVisitor + { + private readonly IHttpContextAccessor _contextAccessor; + + public AuthorizeDirectiveVisitor(IHttpContextAccessor contextAccessor) + { + _contextAccessor = contextAccessor; + } + + public override void VisitObjectFieldDefinition(FieldType field, IObjectGraphType type, ISchema schema) + { + var applied = field.FindAppliedDirective(AuthorizeDirective.DirectiveName); + if (applied == null) + { + return; + } + + var isAuthenticated = _contextAccessor.HttpContext?.User.Identity?.IsAuthenticated; + if (isAuthenticated == true) + { + return; + } + + field.Resolver = new AsyncFieldResolver(async context => { throw new NotAuthorizedException(); }); + } + } +} diff --git a/Micro.Starter.Api/GraphQL/Directives/Exceptions/NotAuthorizedException.cs b/Micro.Starter.Api/GraphQL/Directives/Exceptions/NotAuthorizedException.cs new file mode 100644 index 0000000..09a02ce --- /dev/null +++ b/Micro.Starter.Api/GraphQL/Directives/Exceptions/NotAuthorizedException.cs @@ -0,0 +1,11 @@ +using System; + +namespace Micro.Starter.Api.GraphQL.Directives.Exceptions +{ + public class NotAuthorizedException : Exception + { + public NotAuthorizedException() : base("This operation requires logging in") + { + } + } +} diff --git a/Micro.Starter.Api/GraphQL/Extensions/Directives.cs b/Micro.Starter.Api/GraphQL/Extensions/Directives.cs new file mode 100644 index 0000000..38e9f87 --- /dev/null +++ b/Micro.Starter.Api/GraphQL/Extensions/Directives.cs @@ -0,0 +1,21 @@ +using GraphQL; +using GraphQL.Builders; +using GraphQL.Types; +using Micro.Starter.Api.GraphQL.Directives; + +namespace Micro.Starter.Api.GraphQL.Extensions +{ + public static class Directives + { + public static FieldType Authorize(this FieldType type) + { + return type.ApplyDirective(AuthorizeDirective.DirectiveName); + } + + public static FieldBuilder Authorize( + this FieldBuilder type) + { + return type.Directive(AuthorizeDirective.DirectiveName); + } + } +} diff --git a/Micro.Starter.Api/GraphQL/Extensions/Startup.cs b/Micro.Starter.Api/GraphQL/Extensions/Startup.cs new file mode 100644 index 0000000..b4bfdb9 --- /dev/null +++ b/Micro.Starter.Api/GraphQL/Extensions/Startup.cs @@ -0,0 +1,56 @@ +using GraphQL; +using GraphQL.DataLoader; +using GraphQL.Execution; +using GraphQL.Server; +using GraphQL.Server.Ui.GraphiQL; +using GraphQL.Server.Ui.Playground; +using GraphQL.SystemTextJson; +using GraphQL.Types; +using Micro.GraphQL.Federation; +using Micro.Starter.Api.GraphQL.Directives; +using Micro.Starter.Api.GraphQL.Types; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; + +namespace Micro.Starter.Api.GraphQL.Extensions +{ + public static class Startup + { + public static void ConfigureGraphql(this IServiceCollection services) + { + services.EnableFederation(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddScoped(); + services + .AddGraphQL(options => + { + options.UnhandledExceptionDelegate = ctx => + { + ctx.ErrorMessage = ctx.OriginalException.Message; + }; + }) + .AddDataLoader() + .AddSystemTextJson() + .AddErrorInfoProvider(opts => opts.ExposeExceptionStackTrace = true); + } + public static void SetupGraphQl(this IApplicationBuilder app) + { + app.UseGraphQL(); + app.UseGraphQLGraphiQL(new GraphiQLOptions + { + SubscriptionsEndPoint = null, + GraphQLEndPoint = "/graphql" + }, "/ui/graphql"); + app.UseGraphQLPlayground(new PlaygroundOptions + { + GraphQLEndPoint = "/graphql", + }, "/ui/playground"); + } + } +} diff --git a/Micro.Starter.Api/GraphQL/Query.cs b/Micro.Starter.Api/GraphQL/Query.cs new file mode 100644 index 0000000..1ed0967 --- /dev/null +++ b/Micro.Starter.Api/GraphQL/Query.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; +using Micro.GraphQL.Federation; +using Micro.Starter.Api.GraphQL.Types; +using Micro.Starter.Storage; + +namespace Micro.Starter.Api.GraphQL +{ + public sealed class Query : Query + { + public Query() + { + Field() + .Name("weather") + .ResolveAsync(x => Task.FromResult(new Weather + { + Id = "id", + Temperature = 23.3 + })); + } + } +} diff --git a/Micro.Starter.Api/GraphQL/StarterSchema.cs b/Micro.Starter.Api/GraphQL/StarterSchema.cs new file mode 100644 index 0000000..cb47478 --- /dev/null +++ b/Micro.Starter.Api/GraphQL/StarterSchema.cs @@ -0,0 +1,17 @@ +using System; +using Micro.GraphQL.Federation; +using Micro.Starter.Api.GraphQL.Directives; +using Micro.Starter.Api.GraphQL.Types; + +namespace Micro.Starter.Api.GraphQL +{ + public class StarterSchema : Schema + { + public StarterSchema(IServiceProvider services, Query query) : base(services) + { + Query = query; + Directives.Register(new AuthorizeDirective()); + RegisterVisitor(typeof(AuthorizeDirectiveVisitor)); + } + } +} diff --git a/Micro.Starter.Api/GraphQL/Types/EntityType.cs b/Micro.Starter.Api/GraphQL/Types/EntityType.cs new file mode 100644 index 0000000..0a98205 --- /dev/null +++ b/Micro.Starter.Api/GraphQL/Types/EntityType.cs @@ -0,0 +1,10 @@ +namespace Micro.Starter.Api.GraphQL.Types +{ + public class EntityType : Micro.GraphQL.Federation.Types.EntityType + { + public EntityType() + { + Type(); + } + } +} diff --git a/Micro.Starter.Api/GraphQL/Types/WeatherType.cs b/Micro.Starter.Api/GraphQL/Types/WeatherType.cs new file mode 100644 index 0000000..2b28283 --- /dev/null +++ b/Micro.Starter.Api/GraphQL/Types/WeatherType.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; +using Micro.GraphQL.Federation; +using Micro.Starter.Storage; + +namespace Micro.Starter.Api.GraphQL.Types +{ + public sealed class WeatherType : ObjectGraphType + { + public WeatherType() + { + Name = "Weather"; + Field("id", x => x.Id); + Field("temperature", x => x.Temperature); + ResolveReferenceAsync(ctx => Task.FromResult(new Weather + { + Id = "id", + Temperature = 32.2 + })); + } + } +} diff --git a/Micro.Starter.Api/Internal/StartupExtensions/DependencyInjection.cs b/Micro.Starter.Api/Internal/StartupExtensions/DependencyInjection.cs index a1b316d..c17b3e9 100644 --- a/Micro.Starter.Api/Internal/StartupExtensions/DependencyInjection.cs +++ b/Micro.Starter.Api/Internal/StartupExtensions/DependencyInjection.cs @@ -8,6 +8,7 @@ public static class DependencyInjection { public static void ConfigureRequiredDependencies(this IServiceCollection services) { + services.AddHttpContextAccessor(); services.AddDbContext(); services.AddScoped(); services.AddSingleton(); diff --git a/Micro.Starter.Api/Micro.Starter.Api.csproj b/Micro.Starter.Api/Micro.Starter.Api.csproj index 353238f..37b8294 100644 --- a/Micro.Starter.Api/Micro.Starter.Api.csproj +++ b/Micro.Starter.Api/Micro.Starter.Api.csproj @@ -5,30 +5,37 @@ - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + - + - + - + diff --git a/Micro.Starter.Api/Startup.cs b/Micro.Starter.Api/Startup.cs index 09ca9cd..50b6db9 100644 --- a/Micro.Starter.Api/Startup.cs +++ b/Micro.Starter.Api/Startup.cs @@ -1,3 +1,4 @@ +using Micro.Starter.Api.GraphQL.Extensions; using Micro.Starter.Api.Internal.Configs; using Micro.Starter.Api.Internal.StartupExtensions; using Microsoft.AspNetCore.Builder; @@ -29,6 +30,7 @@ public void ConfigureServices(IServiceCollection services) services.AddControllers(); services.ConfigureSwagger(); services.RegisterWorker(); + services.ConfigureGraphql(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -39,6 +41,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF { app.UseDeveloperExceptionPage(); } + app.SetupGraphQl(); app.UseRouting(); app.UseAuthorization(); app.AddSwaggerWithUi(); From b0341761bba4879b7d942fb8165a249da9053528 Mon Sep 17 00:00:00 2001 From: Nishchal Date: Sun, 13 Jun 2021 16:01:54 +0700 Subject: [PATCH 3/4] feat(auth): enable auth --- .../Internal/Configs/Services.cs | 12 ++++++ .../StartupExtensions/Configuration.cs | 1 + Micro.Starter.Api/Micro.Starter.Api.csproj | 38 +++++++++---------- Micro.Starter.Api/Startup.cs | 7 +++- Micro.Starter.Api/appsettings.ci.json | 5 +++ Micro.Starter.Api/appsettings.json | 11 ++++-- docker-compose.yml | 36 ++++++++++++++++-- extras/docker_postgres_init.sql | 3 ++ 8 files changed, 87 insertions(+), 26 deletions(-) create mode 100644 Micro.Starter.Api/Internal/Configs/Services.cs create mode 100644 extras/docker_postgres_init.sql diff --git a/Micro.Starter.Api/Internal/Configs/Services.cs b/Micro.Starter.Api/Internal/Configs/Services.cs new file mode 100644 index 0000000..316b8d7 --- /dev/null +++ b/Micro.Starter.Api/Internal/Configs/Services.cs @@ -0,0 +1,12 @@ +namespace Micro.Starter.Api.Internal.Configs +{ + public class Services + { + public KeyStoreConfig KeyStore { set; get; } + } + + public class KeyStoreConfig + { + public string Url { set; get; } + } +} diff --git a/Micro.Starter.Api/Internal/StartupExtensions/Configuration.cs b/Micro.Starter.Api/Internal/StartupExtensions/Configuration.cs index 6f3a068..fbfbbcf 100644 --- a/Micro.Starter.Api/Internal/StartupExtensions/Configuration.cs +++ b/Micro.Starter.Api/Internal/StartupExtensions/Configuration.cs @@ -10,6 +10,7 @@ public static class Configuration public static void AddConfiguration(this IServiceCollection services, IConfiguration configuration) { services.Configure(configuration.GetSection("DatabaseConfig")); + services.Configure(configuration.GetSection("Services")); services.Configure(configuration.GetSection("Logging").GetSection("Slack")); } } diff --git a/Micro.Starter.Api/Micro.Starter.Api.csproj b/Micro.Starter.Api/Micro.Starter.Api.csproj index 37b8294..7d9dc8f 100644 --- a/Micro.Starter.Api/Micro.Starter.Api.csproj +++ b/Micro.Starter.Api/Micro.Starter.Api.csproj @@ -5,37 +5,37 @@ - - - - - - + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - + + + + + + + + + + - + - + - + diff --git a/Micro.Starter.Api/Startup.cs b/Micro.Starter.Api/Startup.cs index 50b6db9..db6543b 100644 --- a/Micro.Starter.Api/Startup.cs +++ b/Micro.Starter.Api/Startup.cs @@ -1,3 +1,4 @@ +using Micro.Auth.Sdk; using Micro.Starter.Api.GraphQL.Extensions; using Micro.Starter.Api.Internal.Configs; using Micro.Starter.Api.Internal.StartupExtensions; @@ -31,6 +32,10 @@ public void ConfigureServices(IServiceCollection services) services.ConfigureSwagger(); services.RegisterWorker(); services.ConfigureGraphql(); + services.ConfigureAuthServices(new Config + { + KeyStoreUrl = Configuration.GetSection("Services").Get().KeyStore.Url + }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -43,7 +48,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF } app.SetupGraphQl(); app.UseRouting(); - app.UseAuthorization(); + app.SetupAuth(); app.AddSwaggerWithUi(); app.UseEndpoints(endpoints => { diff --git a/Micro.Starter.Api/appsettings.ci.json b/Micro.Starter.Api/appsettings.ci.json index 967d60c..9eb28d0 100644 --- a/Micro.Starter.Api/appsettings.ci.json +++ b/Micro.Starter.Api/appsettings.ci.json @@ -17,6 +17,11 @@ "User": "starter", "Password": "secret" }, + "Services": { + "KeyStore": { + "Url": "http://localhost:15000" + } + }, "MetricsOptions": { "InfluxDb": { "BaseUri": "http://influxdb:8086", diff --git a/Micro.Starter.Api/appsettings.json b/Micro.Starter.Api/appsettings.json index 5cc2a42..a9c6559 100644 --- a/Micro.Starter.Api/appsettings.json +++ b/Micro.Starter.Api/appsettings.json @@ -10,12 +10,17 @@ "LogLevel": "Warning" } }, + "Services": { + "KeyStore": { + "Url": "http://localhost:15000" + } + }, "DatabaseConfig": { "Host": "localhost", "Port": 15433, - "Name": "starter_db", - "User": "starter", - "Password": "secret" + "Name": "starter", + "User": "postgres", + "Password": "postgres" }, "MetricsOptions": { "InfluxDb": { diff --git a/docker-compose.yml b/docker-compose.yml index 54c1ff5..d5c9e96 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,43 @@ version: '3' services: + key_store: + image: fossapps/micro.keystore:1.9.1 + ports: + - 15000:15000 + environment: + - ASPNETCORE_URLS=http://+:15000 + - DatabaseConfig__AutoMigrate=true + - DatabaseConfig__Host=postgres + - DatabaseConfig__Port=5432 + - DatabaseConfig__Name=keys + - DatabaseConfig__User=postgres + - DatabaseConfig__Password=postgres + depends_on: + - postgres + auth: + image: fossapps/micro.auth:2.1.2 + ports: + - 25000:25000 + environment: + - ASPNETCORE_URLS=http://+:25000 + - DatabaseConfig__AutoMigrate=true + - DatabaseConfig__Host=postgres + - DatabaseConfig__Port=5432 + - DatabaseConfig__Name=auth + - DatabaseConfig__User=postgres + - DatabaseConfig__Password=postgres + - Services__KeyStore__Url=http://key_store:15000 + depends_on: + - postgres postgres: image: postgres:11-alpine ports: - 15433:5432 + volumes: + - ./extras/docker_postgres_init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql environment: - - POSTGRES_PASSWORD=secret - - POSTGRES_USER=starter - - POSTGRES_DB=starter_db + - POSTGRES_PASSWORD=postgres + - POSTGRES_USER=postgres influxdb: image: influxdb environment: diff --git a/extras/docker_postgres_init.sql b/extras/docker_postgres_init.sql new file mode 100644 index 0000000..f04eddd --- /dev/null +++ b/extras/docker_postgres_init.sql @@ -0,0 +1,3 @@ +CREATE DATABASE auth WITH OWNER = postgres ENCODING = 'UTF8' CONNECTION LIMIT = -1; +CREATE DATABASE keys WITH OWNER = postgres ENCODING = 'UTF8' CONNECTION LIMIT = -1; +CREATE DATABASE starter WITH OWNER = postgres ENCODING = 'UTF8' CONNECTION LIMIT = -1; From 1f5649a994b6e680ca74eec408a0f8e4f597c27e Mon Sep 17 00:00:00 2001 From: Nishchal Date: Sun, 13 Jun 2021 16:07:16 +0700 Subject: [PATCH 4/4] chore(build): use .NET way to copy git hooks --- Micro.Starter.Api/Micro.Starter.Api.csproj | 7 +++++-- {hooks => extras/hooks}/commit-msg | 0 2 files changed, 5 insertions(+), 2 deletions(-) rename {hooks => extras/hooks}/commit-msg (100%) diff --git a/Micro.Starter.Api/Micro.Starter.Api.csproj b/Micro.Starter.Api/Micro.Starter.Api.csproj index 7d9dc8f..6bc4c1f 100644 --- a/Micro.Starter.Api/Micro.Starter.Api.csproj +++ b/Micro.Starter.Api/Micro.Starter.Api.csproj @@ -35,7 +35,10 @@ - - + + + <_CustomFiles Include="../extras/hooks/commit-msg" /> + + diff --git a/hooks/commit-msg b/extras/hooks/commit-msg similarity index 100% rename from hooks/commit-msg rename to extras/hooks/commit-msg