botframework-components icon indicating copy to clipboard operation
botframework-components copied to clipboard

Read app settings and override configuration to support encrypted values in app settings

Open praveenvavilla opened this issue 3 years ago • 5 comments

Hi,

We started writing bot using composer and have the below requirement which am not sure how to achieve

  1. Have encrypted values app settings.json
  2. read app settings at runetime and decrypt all the encrypted values
  3. Bot uses configuration with decrypted values in step 2 I tried to see if we can override configuration but I see that

image

and I see that IConfiguration passed in to startup has Appsettings as part of collection and am not sure how can I achieve custom handling of configuration image

praveenvavilla avatar Jun 19 '21 01:06 praveenvavilla

one option is ,

I can have custom class for handling decryption of settings for the encrypted values in appsettings and register with DI like below in startup: ConfigureServices services.AddSingleton<ISettings, Settings>();

however am not sure how can I pass ISettings to custom actions (this is needed in custom actions)

Note: duplicate settings mentioned in above screenshot may need to be fixed

praveenvavilla avatar Jun 19 '21 19:06 praveenvavilla

@praveenvavilla, thank you for opening this issue. For product behavior, how-to, or general understanding questions, please use Stackoverflow.

https://stackoverflow.com/search?q=bot+framework

thomas-chung avatar Jun 21 '21 18:06 thomas-chung

Reopening issue for triaging tomorrow morning.

thomas-chung avatar Jun 21 '21 22:06 thomas-chung

IConfiguration is just an uber object holding all kinds of config merged. You can always override IConfiguration after it's build\load, for example in Start.cs, what you can do is

image

Then, later, in any actions, you should be able to refer to your value via "settings" scope like, "settings.your.path.to.value".

Note the different seperator here, in the configuration override, you have to use ":" as seperator, because that's what asp.net's convention here. But in adaptive dialog, we did a reverse building, to make it "." when contructing the settings scope.

boydc2014 avatar Jun 22 '21 10:06 boydc2014

is there any other way on having custom settings class (read from cofiguration and decrypt them) passed to custom actions without writing back to IConfiguration object as you mentioned (we just want to avoid writing back to it)

praveenvavilla avatar Jun 22 '21 19:06 praveenvavilla