first commit
This commit is contained in:
parent
68543df351
commit
a959d1643d
12
App.cs
12
App.cs
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
|||||||
using Vault.Demo.hashicorp.Console.Helper;
|
using Vault.Demo.hashicorp.Console.Helper;
|
||||||
|
|
||||||
namespace Vault.Demo.hashicorp.Console;
|
namespace Vault.Demo.hashicorp.Console;
|
||||||
|
|
||||||
internal class App
|
internal class App
|
||||||
{
|
{
|
||||||
private readonly IConnectionStringProvider _connectionStringProvider;
|
private readonly IConnectionStringProvider _connectionStringProvider;
|
||||||
@ -16,9 +17,9 @@ internal class App
|
|||||||
public App(IConnectionStringProvider connectionStringProvider) =>
|
public App(IConnectionStringProvider connectionStringProvider) =>
|
||||||
this._connectionStringProvider = connectionStringProvider;
|
this._connectionStringProvider = connectionStringProvider;
|
||||||
|
|
||||||
public async Task Run(string[] args)
|
public async Task Run(string arg)
|
||||||
{
|
{
|
||||||
var files = Directory.GetFiles(args[0], "appsettings*.json", SearchOption.AllDirectories);
|
var files = Directory.GetFiles(arg, "appsettings*.json", SearchOption.AllDirectories);
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
if (file.Contains("/bin/") || file.Contains("\\bin\\"))
|
if (file.Contains("/bin/") || file.Contains("\\bin\\"))
|
||||||
@ -30,15 +31,18 @@ internal class App
|
|||||||
|
|
||||||
private async Task UpdateAppSettingFile(string file)
|
private async Task UpdateAppSettingFile(string file)
|
||||||
{
|
{
|
||||||
var content = JObject.Parse(File.ReadAllText(file));
|
var content = JObject.Parse(await File.ReadAllTextAsync(file));
|
||||||
var jsonReader = content["ConnectionStrings"] as JObject;
|
var jsonReader = content["ConnectionStrings"] as JObject;
|
||||||
if (jsonReader == null)
|
if (jsonReader == null)
|
||||||
return;
|
return;
|
||||||
foreach (var item in jsonReader.Properties())
|
foreach (var item in jsonReader.Properties())
|
||||||
{
|
{
|
||||||
var value = await _connectionStringProvider.GetConnectionString(item.Name);
|
var value = await _connectionStringProvider.GetConnectionString(item.Name);
|
||||||
|
if (value == string.Empty)
|
||||||
|
continue;
|
||||||
jsonReader[item.Name] = value;
|
jsonReader[item.Name] = value;
|
||||||
}
|
}
|
||||||
File.WriteAllText(file, jsonReader.ToString());
|
|
||||||
|
await File.WriteAllTextAsync(file, jsonReader.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ using Vault.Demo.hashicorp.Console.Handler;
|
|||||||
using VaultSharp;
|
using VaultSharp;
|
||||||
|
|
||||||
namespace Vault.Demo.hashicorp.Console.Helper;
|
namespace Vault.Demo.hashicorp.Console.Helper;
|
||||||
|
|
||||||
internal class ConnectionStringProvider : IConnectionStringProvider
|
internal class ConnectionStringProvider : IConnectionStringProvider
|
||||||
{
|
{
|
||||||
private readonly IValueClientProvider _vaultClient;
|
private readonly IValueClientProvider _vaultClient;
|
||||||
@ -22,7 +23,7 @@ internal class ConnectionStringProvider : IConnectionStringProvider
|
|||||||
var secrate = await _vaultClient.GetSecret(client);
|
var secrate = await _vaultClient.GetSecret(client);
|
||||||
|
|
||||||
return secrate.Data.Data.TryGetValue(key, out var val)
|
return secrate.Data.Data.TryGetValue(key, out var val)
|
||||||
? val?.ToString() ?? throw new ArgumentException()
|
? val?.ToString() ?? string.Empty
|
||||||
: string.Empty;
|
: string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,4 +17,7 @@ builder.ConfigureServices(s =>
|
|||||||
using var app = builder.Build();
|
using var app = builder.Build();
|
||||||
using var scope = app.Services.CreateScope();
|
using var scope = app.Services.CreateScope();
|
||||||
var application = scope.ServiceProvider.GetRequiredService<App>();
|
var application = scope.ServiceProvider.GetRequiredService<App>();
|
||||||
await application.Run(["C:\\Users\\SENTIENTGEEKS\\Desktop\\New_folder_(2)\\Acme.BookStore"]);
|
if (args.Length > 0)
|
||||||
|
await application.Run(args[0]);
|
||||||
|
else
|
||||||
|
Console.WriteLine("No project found to run");
|
@ -1,7 +1,6 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:4.0.30319.42000
|
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
@ -14,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Vault.Demo.hashicorp.Console")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("Vault.Demo.hashicorp.Console")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+68543df351402cd4edd2e0931ad30d12f91d1e06")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("Vault.Demo.hashicorp.Console")]
|
[assembly: System.Reflection.AssemblyProductAttribute("Vault.Demo.hashicorp.Console")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("Vault.Demo.hashicorp.Console")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("Vault.Demo.hashicorp.Console")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
@ -1 +1 @@
|
|||||||
02f9ff422eb824a828d6d1157659e667911d2e118ac124ece8137b1ee3fa0b9d
|
aa45860ddd933a0793d80400f5cabc163a673ea9c5f28cfba3345c9733abde4d
|
||||||
|
Loading…
x
Reference in New Issue
Block a user