wip
This commit is contained in:
parent
05d6977a76
commit
c83442b4af
16 changed files with 315 additions and 272 deletions
|
|
@ -1,48 +1,136 @@
|
|||
using Autofac;
|
||||
using Insight.Database;
|
||||
using System.Data;
|
||||
|
||||
namespace SetupInfrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// SETUP APPLICATION USER NAMED sathumper
|
||||
///
|
||||
/// This should be handled on the Postgresql db server with a superadmin or similar.
|
||||
///
|
||||
/// Execute SQL CreateRole.txt
|
||||
///
|
||||
/// After that is executed it is time for running this main program
|
||||
/// Remember to use the newly created sathumper
|
||||
/// "ConnectionStrings": {
|
||||
/// "DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptdb01;User Id=sathumper;Password=<secret>;"
|
||||
/// </summary>
|
||||
internal class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
string userPass;
|
||||
do
|
||||
{
|
||||
Console.WriteLine("Input username:password");
|
||||
userPass = Console.ReadLine() ?? string.Empty;
|
||||
} while (!userPass.Contains(":") || userPass.Split(":").Length != 2 ||
|
||||
string.IsNullOrEmpty(userPass.Split(":")[0]) ||
|
||||
string.IsNullOrEmpty(userPass.Split(":")[1]));
|
||||
/// <summary>
|
||||
/// SETUP APPLICATION USER NAMED sathumper
|
||||
///
|
||||
/// This should be handled on the Postgresql db server with a superadmin or similar.
|
||||
///
|
||||
/// Execute SQL CreateRole.txt
|
||||
///
|
||||
/// After that is executed it is time for running this main program
|
||||
/// Remember to use the newly created sathumper
|
||||
/// "ConnectionStrings": {
|
||||
/// "DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptdb01;User Id=<uid>;Password=<secret>;"
|
||||
/// </summary>
|
||||
internal class Program
|
||||
{
|
||||
static IContainer _container;
|
||||
|
||||
var ctp = new Startup.ConnectionStringTemplateParameters(
|
||||
user: userPass.Split(":")[0],
|
||||
pwd: userPass.Split(":")[1]
|
||||
);
|
||||
var container = new Startup().ConfigureContainer(ctp);
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
|
||||
string userPass;
|
||||
|
||||
// SetupIdentitySystem
|
||||
// ConfigurationDatabaseSetup
|
||||
// input configurations!!! TODO:Missing
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
Console.WriteLine("Input <username>:<password>");
|
||||
userPass = Console.ReadLine() ?? string.Empty;
|
||||
} while (!userPass.Contains(":") || userPass.Split(":").Length != 2 ||
|
||||
string.IsNullOrEmpty(userPass.Split(":")[0]) ||
|
||||
string.IsNullOrEmpty(userPass.Split(":")[1]));
|
||||
|
||||
var ctp = new Startup.ConnectionStringTemplateParameters(
|
||||
user: userPass.Split(":")[0],
|
||||
pwd: userPass.Split(":")[1]
|
||||
);
|
||||
_container = new Startup().ConfigureContainer(ctp);
|
||||
|
||||
if (TestDbRole())
|
||||
{
|
||||
|
||||
// SetupApplicationUser
|
||||
// SetupIdentitySystem
|
||||
// SetupConfiguration
|
||||
|
||||
|
||||
|
||||
//and a lot of other tables that we haven't defined yet
|
||||
|
||||
// input configurations!!! TODO:Missing
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(e);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static bool TestDbRole()
|
||||
{
|
||||
var backgroundColor = Console.BackgroundColor;
|
||||
var foregroundColor = Console.ForegroundColor;
|
||||
|
||||
//test db access
|
||||
Console.WriteLine("Testing db access...");
|
||||
|
||||
string query = @"SELECT usename, usesuper FROM pg_user WHERE usename = CURRENT_USER;";
|
||||
|
||||
var conn = _container.Resolve<IDbConnection>();
|
||||
var result = (dynamic)conn.QuerySql(query).Single();
|
||||
|
||||
string username = result.usename;
|
||||
bool isSuperuser = (bool)result.usesuper;
|
||||
|
||||
if ((bool)result.usesuper)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.BackgroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("TEST SUCCESSFULLY");
|
||||
Console.WriteLine();
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.BackgroundColor = backgroundColor;
|
||||
Console.WriteLine("-------------------------------");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Username: {username}");
|
||||
Console.WriteLine($"Super admin: true");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("-------------------------------");
|
||||
|
||||
|
||||
Console.WriteLine("Press any key to start database setup");
|
||||
Console.Read();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.BackgroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("TEST WAS NOT SUCCESSFULLY");
|
||||
Console.WriteLine();
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.BackgroundColor = backgroundColor;
|
||||
Console.WriteLine("-------------------------------");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Username: {username}");
|
||||
Console.WriteLine($"Super admin: false");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("-------------------------------");
|
||||
|
||||
|
||||
Console.WriteLine("User is required to be super admin");
|
||||
Console.Read();
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,19 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Database\Database.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Database\Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appconfiguration.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="appconfiguration.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace SetupInfrastructure
|
|||
public virtual IConfigurationRoot Configuration()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.AddJsonFile("appconfiguration.json")
|
||||
.Build();
|
||||
|
||||
return configuration;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptdb01;User Id={usr};Password={pwd};"
|
||||
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id={usr};Password={pwd};"
|
||||
},
|
||||
"ApplicationInsights": {
|
||||
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue