ChustaSoft / SecureConfig

Tool to give security to the configurations of an ASPNET Core application by encrypting sensitive information and handling in a secure way
GNU General Public License v3.0
15 stars 2 forks source link

Can't use Custom section name in Program.cs #42

Closed YellowFlashLeo closed 3 years ago

YellowFlashLeo commented 3 years ago

From your documentation: By default, the tool is looking for a section called "AppSettings" in the appSettings files, from version 1.2.2 if a custom section name wants to be specified, it is mandatory to do it at EncryptSettings (Program, Main) and SetUpSecureConfig (ConfigureServices), in example:

.EncryptSettings<[TSettings]>(true, "AppSettingsCustomName")

services.SetUpSecureConfig<[TSettings]>(Configuration, testApikey, "AppSettingsCustomName");

What I get image CreateWebHostBuilder(args) .Build() .EncryptSettings(true,"ConnectionStrings") .RunAsService(); IWebHost does not contain a definition for "EncryptSettings" and the best extension method overload 'WebHostExtensions.EncryptSettings(IHost,bool,string) required a receiver of type IHost.

I used 1.2.2 and all above version of nuget, still same issue

xaberue commented 3 years ago

Hi @YellowFlashLeo ,

First of all thanks for using the tool and taking time to report the issue.

Could you please provide the code for the ConnectionStrings class?

Thanks

YellowFlashLeo commented 3 years ago

public class ConnectionStrings { public string DatabaseConnection { get; set; } public string StudioConnection { get; set; } }

And in appconfig I have { "ConnectionStrings": { "DatabaseConnection": "dsdsds", "StudioConnection": "dsdsdsds" },

YellowFlashLeo commented 3 years ago

The reason I dont want my appconfig to have "AppSettings": { "ConnectionStrings": {, is because after encryption. I cant get connectionString value in my middleware, dbContextOptions.UseSqlServer(Configuration.GetConnectionString("DatabaseConnection"), b => b.MigrationsAssembly("WebDataExtract"))); this returns null. I also tried bContextOptions.UseSqlServer(Configuration.GetSection("AppSettings:ConnectionStrings:DatabaseConnection").Value, also returns null

xaberue commented 3 years ago

Hi again, the usage of this class it's perfectly understandable, ans it's ok, thanks for sharing, it was my first option.

It is a .Net Core > 3.0 application?

If it is true, seems that it's using IWebHost marked as obsolete from .Net Core 3.0 and above, so the dependency it's no longer required in SecureConfig in projets using this framework version.

You can check the documentation regarding the migration from .Net Core 2.2 to 3.0 here

SecureConfig is using only IHost from .Net Core 3.1 and above versions.

Let me know if this information helps in your current context.

Thanks

YellowFlashLeo commented 3 years ago

It is in .Net Core 3.1

xaberue commented 3 years ago

So, in that case, having a look in the link provided above, it is recommend to move to IHost instead of keeping IWebHost.

Once migrated, this should help.

xaberue commented 3 years ago

Did this documentation help you @YellowFlashLeo ?