first commit
This commit is contained in:
parent
68543df351
commit
a959d1643d
14
App.cs
14
App.cs
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using Vault.Demo.hashicorp.Console.Helper;
|
||||
|
||||
namespace Vault.Demo.hashicorp.Console;
|
||||
|
||||
internal class App
|
||||
{
|
||||
private readonly IConnectionStringProvider _connectionStringProvider;
|
||||
@ -16,9 +17,9 @@ internal class App
|
||||
public App(IConnectionStringProvider 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)
|
||||
{
|
||||
if (file.Contains("/bin/") || file.Contains("\\bin\\"))
|
||||
@ -30,15 +31,18 @@ internal class App
|
||||
|
||||
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;
|
||||
if (jsonReader == null)
|
||||
return;
|
||||
foreach (var item in jsonReader.Properties())
|
||||
{
|
||||
var value = await _connectionStringProvider.GetConnectionString(item.Name);
|
||||
if (value == string.Empty)
|
||||
continue;
|
||||
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;
|
||||
|
||||
namespace Vault.Demo.hashicorp.Console.Helper;
|
||||
|
||||
internal class ConnectionStringProvider : IConnectionStringProvider
|
||||
{
|
||||
private readonly IValueClientProvider _vaultClient;
|
||||
@ -21,8 +22,8 @@ internal class ConnectionStringProvider : IConnectionStringProvider
|
||||
var client = _vaultClient.GetValueClient();
|
||||
var secrate = await _vaultClient.GetSecret(client);
|
||||
|
||||
return secrate.Data.Data.TryGetValue(key, out var val)
|
||||
? val?.ToString() ?? throw new ArgumentException()
|
||||
return secrate.Data.Data.TryGetValue(key, out var val)
|
||||
? val?.ToString() ?? string.Empty
|
||||
: string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
@ -17,4 +17,7 @@ builder.ConfigureServices(s =>
|
||||
using var app = builder.Build();
|
||||
using var scope = app.Services.CreateScope();
|
||||
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>
|
||||
// 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
|
||||
// the code is regenerated.
|
||||
@ -14,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Vault.Demo.hashicorp.Console")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[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.AssemblyTitleAttribute("Vault.Demo.hashicorp.Console")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
02f9ff422eb824a828d6d1157659e667911d2e118ac124ece8137b1ee3fa0b9d
|
||||
aa45860ddd933a0793d80400f5cabc163a673ea9c5f28cfba3345c9733abde4d
|
||||
|
Loading…
x
Reference in New Issue
Block a user