Browse Source

Outsourced connection strings to appsettings.json

master
Daniel Gyulai 4 years ago
parent
commit
fa5386bfb7
  1. 5
      CoviDok/BLL/Sessions/SessionHandler.cs
  2. 2
      CoviDok/Controllers/AssistantController.cs
  3. 2
      CoviDok/Controllers/AuthController.cs
  4. 2
      CoviDok/Controllers/CaseController.cs
  5. 2
      CoviDok/Controllers/ChildController.cs
  6. 2
      CoviDok/Controllers/DoctorController.cs
  7. 14
      CoviDok/Controllers/ImagesController.cs
  8. 2
      CoviDok/Controllers/ParentController.cs
  9. 5
      CoviDok/Data/MySQL/MySqlContext.cs
  10. 7
      CoviDok/Data/SessionProviders/RedisProvider.cs
  11. 6
      CoviDok/Data/StorageProviders/MinioProvider.cs
  12. 14
      CoviDok/Data/StorageProviders/MinioSettings.cs
  13. 4
      CoviDok/Program.cs
  14. 13
      CoviDok/Startup.cs
  15. 9
      CoviDok/appsettings.json

5
CoviDok/BLL/Sessions/SessionHandler.cs

@ -4,6 +4,7 @@ using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using CoviDok.Api;
using CoviDok.Data.SessionProviders;
using NCuid;
namespace CoviDok.BLL.Sessions
@ -12,9 +13,9 @@ namespace CoviDok.BLL.Sessions
{
private readonly ISessionProvider SessionStore;
public SessionHandler(ISessionProvider Provider)
public SessionHandler()
{
SessionStore = Provider;
SessionStore = new RedisProvider();
}
public async Task<Session> GetSession(string SessionId)

2
CoviDok/Controllers/AssistantController.cs

@ -16,7 +16,7 @@ namespace CoviDok.Controllers
[ApiController]
public class AssistantController : ControllerBase
{
private readonly SessionHandler Handler = new SessionHandler(new RedisProvider("redis"));
private readonly SessionHandler Handler = new SessionHandler();
private readonly AssistantManager mgr = new AssistantManager();

2
CoviDok/Controllers/AuthController.cs

@ -17,7 +17,7 @@ namespace CoviDok.Controllers
[ApiController]
public class AuthController : ControllerBase
{
SessionHandler Handler = new SessionHandler(new RedisProvider("redis"));
SessionHandler Handler = new SessionHandler();

2
CoviDok/Controllers/CaseController.cs

@ -20,7 +20,7 @@ namespace CoviDok.Controllers
[ApiController]
public class CaseController : ControllerBase
{
private readonly SessionHandler Handler = new SessionHandler(new RedisProvider("redis"));
private readonly SessionHandler Handler = new SessionHandler();
private readonly CaseManager mgr = new CaseManager();
// POST /api/Case/{id}

2
CoviDok/Controllers/ChildController.cs

@ -17,7 +17,7 @@ namespace CoviDok.Controllers
[ApiController]
public class ChildController : ControllerBase
{
private readonly SessionHandler Handler = new SessionHandler(new RedisProvider("redis"));
private readonly SessionHandler Handler = new SessionHandler();
private readonly ChildManager ChildManager = new ChildManager();

2
CoviDok/Controllers/DoctorController.cs

@ -18,7 +18,7 @@ namespace CoviDok.Controllers
[ApiController]
public class DoctorController : ControllerBase
{
private readonly SessionHandler Handler = new SessionHandler(new RedisProvider("redis"));
private readonly SessionHandler Handler = new SessionHandler();
private readonly DoctorManager doctorHandler = new DoctorManager();
// GET /api/Doc

14
CoviDok/Controllers/ImagesController.cs

@ -13,6 +13,8 @@ using CoviDok.Data.SessionProviders;
using CoviDok.Data.StorageProviders;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using NCuid;
namespace CoviDok.Controllers
@ -21,13 +23,15 @@ namespace CoviDok.Controllers
[ApiController]
public class ImagesController : ControllerBase
{
private StorageHandler MinioHandler = new StorageHandler(new MinioProvider(
"minio:9000",
"secretaccesskey",
"secretsecretkey"));
private StorageHandler MinioHandler;
private readonly string BucketName = "test1";
private readonly SessionHandler Handler = new SessionHandler(new RedisProvider("redis"));
private readonly SessionHandler Handler = new SessionHandler();
public ImagesController(IOptions<MinioSettings> config)
{
MinioHandler = new StorageHandler(new MinioProvider(config));
}
private static Stream MakeStream(string s)
{

2
CoviDok/Controllers/ParentController.cs

@ -17,7 +17,7 @@ namespace CoviDok.Controllers
[ApiController]
public class ParentController : ControllerBase
{
private readonly SessionHandler sessionHandler = new SessionHandler(new RedisProvider("redis"));
private readonly SessionHandler sessionHandler = new SessionHandler();
private readonly ParentManager parentManager = new ParentManager();

5
CoviDok/Data/MySQL/MySqlContext.cs

@ -1,5 +1,6 @@
using CoviDok.Data.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,6 +10,7 @@ namespace CoviDok.Data.MySQL
{
public class MySqlContext : DbContext
{
public static string MySqlString;
public DbSet<Assistant> Assistants { get; set; }
public DbSet<Doctor> Doctors { get; set; }
public DbSet<Parent> Parents { get; set; }
@ -19,7 +21,8 @@ namespace CoviDok.Data.MySQL
public DbSet<Image> Images { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySQL("server=mysql;database=covidok;user=covidok;password=covidok");
//optionsBuilder.UseMySQL("server=mysql;database=covidok;user=covidok;password=covidok");
optionsBuilder.UseMySQL(MySqlString);
}
}
}

7
CoviDok/Data/SessionProviders/RedisProvider.cs

@ -10,9 +10,12 @@ namespace CoviDok.Data.SessionProviders
{
// The Multiplexer is thread safe, connections are not
private readonly ConnectionMultiplexer muxer;
public RedisProvider(string host, string port = "6379")
public static string Host { get; set; }
public RedisProvider()
{
muxer = ConnectionMultiplexer.Connect(host+":"+port);
muxer = ConnectionMultiplexer.Connect(Host);
}
public void Del(string key)
{

6
CoviDok/Data/StorageProviders/MinioProvider.cs

@ -5,15 +5,17 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Minio;
using Microsoft.Extensions.Options;
namespace CoviDok.Data.StorageProviders
{
public class MinioProvider : IStorageProvider
{
private readonly MinioClient Client = null;
public MinioProvider(string Host, string AccessKey, string SecretKey)
public MinioProvider(IOptions<MinioSettings> options)
{
Client = new MinioClient(Host, AccessKey, SecretKey);
var _settings = options.Value;
Client = new MinioClient(_settings.HostName, _settings.AccessKey, _settings.SecretKey);
}
public async Task CreateNamespace(string ns)

14
CoviDok/Data/StorageProviders/MinioSettings.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CoviDok.Data.StorageProviders
{
public class MinioSettings {
public string HostName { get; set; }
public string AccessKey { get; set; }
public string SecretKey { get; set; }
}
}

4
CoviDok/Program.cs

@ -21,6 +21,10 @@ namespace CoviDok
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
}).ConfigureAppConfiguration((buildercontext, config) =>
{
config.AddJsonFile("settings/appsettings.k8s.json", optional: true);
});
}
}

13
CoviDok/Startup.cs

@ -3,10 +3,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CoviDok.Data.MySQL;
using CoviDok.Data.SessionProviders;
using CoviDok.Data.StorageProviders;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@ -16,9 +19,16 @@ namespace CoviDok
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddMvc(options => options.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.AddSingleton<IConfiguration>(configuration);
var minioSection = configuration.GetSection("MinioSettings");
services.Configure<MinioSettings>(minioSection);
MySqlContext.MySqlString = configuration.GetConnectionString("MySQLDatabase");
RedisProvider.Host = configuration.GetConnectionString("RedisHost");
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -33,6 +43,7 @@ namespace CoviDok
app.UseMvc();
MySqlContext ctx = new MySqlContext();
ctx.Database.EnsureCreated();

9
CoviDok/appsettings.json

@ -1,4 +1,13 @@
{
"ConnectionStrings": {
"MySQLDatabase": "server=mysql;database=covidok;user=covidok;password=covidok",
"RedisHost": "redis:6379"
},
"MinioSettings": {
"HostName": "minio",
"AccessKey": "secretaccesskey",
"SecretKey": "secretsecretkey"
},
"Logging": {
"LogLevel": {
"Default": "Information",

Loading…
Cancel
Save