From a959d1643d05d86809368a8eec73ca7717c642aa Mon Sep 17 00:00:00 2001 From: Ayan Poddar Date: Tue, 24 Jun 2025 10:19:30 +0530 Subject: [PATCH] first commit --- App.cs | 14 +++++++++----- Helper/ConnectionStringProvider.cs | 7 ++++--- Program.cs | 5 ++++- .../Vault.Demo.hashicorp.Console.AssemblyInfo.cs | 3 +-- ...Demo.hashicorp.Console.AssemblyInfoInputs.cache | 2 +- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/App.cs b/App.cs index 0bccd54..db272b7 100644 --- a/App.cs +++ b/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()); } -} +} \ No newline at end of file diff --git a/Helper/ConnectionStringProvider.cs b/Helper/ConnectionStringProvider.cs index 5b13964..eabb7d5 100644 --- a/Helper/ConnectionStringProvider.cs +++ b/Helper/ConnectionStringProvider.cs @@ -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; } -} +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index a1cf112..2e22e1c 100644 --- a/Program.cs +++ b/Program.cs @@ -17,4 +17,7 @@ builder.ConfigureServices(s => using var app = builder.Build(); using var scope = app.Services.CreateScope(); var application = scope.ServiceProvider.GetRequiredService(); -await application.Run(["C:\\Users\\SENTIENTGEEKS\\Desktop\\New_folder_(2)\\Acme.BookStore"]); \ No newline at end of file +if (args.Length > 0) + await application.Run(args[0]); +else + Console.WriteLine("No project found to run"); \ No newline at end of file diff --git a/obj/Debug/net9.0/Vault.Demo.hashicorp.Console.AssemblyInfo.cs b/obj/Debug/net9.0/Vault.Demo.hashicorp.Console.AssemblyInfo.cs index 45f72bb..6628bfb 100644 --- a/obj/Debug/net9.0/Vault.Demo.hashicorp.Console.AssemblyInfo.cs +++ b/obj/Debug/net9.0/Vault.Demo.hashicorp.Console.AssemblyInfo.cs @@ -1,7 +1,6 @@ //------------------------------------------------------------------------------ // // 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")] diff --git a/obj/Debug/net9.0/Vault.Demo.hashicorp.Console.AssemblyInfoInputs.cache b/obj/Debug/net9.0/Vault.Demo.hashicorp.Console.AssemblyInfoInputs.cache index fbe961d..66092ab 100644 --- a/obj/Debug/net9.0/Vault.Demo.hashicorp.Console.AssemblyInfoInputs.cache +++ b/obj/Debug/net9.0/Vault.Demo.hashicorp.Console.AssemblyInfoInputs.cache @@ -1 +1 @@ -02f9ff422eb824a828d6d1157659e667911d2e118ac124ece8137b1ee3fa0b9d +aa45860ddd933a0793d80400f5cabc163a673ea9c5f28cfba3345c9733abde4d