How to make yml configuration available in system properties in dropwizard? - properties

I have created dropwizard service in which I have added yaml configuration file. Now to access configuration from the yml in service and dao layer, I am thinking to use system properties. My question is how we can add configuration of yml file in system properties?
or is there any other mechanism (other than D.I.) to use the configuration in service and dao layer?

Related

How to pass sensitive data to the IConfiguration interface during startup?

I want to use the configuration setup for my .NET Core Web API. I installed the Microsoft.Extensions.Configuration package for the DI container.
First of all I have 4 config files
appsettings.json
Whenever all three environments use the same config value, this is the file where to put it
appsettings.Development.json
Basic config values for development purposes only. E.g. database connection points to localhost and token secret is "secret", example:
.
{
"Database": {
"ConnectionString": "Server=localhost;Port=3306;Database=db;Uid=root;Pwd=admin;Pooling=true;"
}
}
appsettings.Staging.json
Almost the same as the development file
appsettings.Production.json
Things are different here. I can't put sensitive information to that file, e.g. token secret. These values should come from the environment variable
So in my code I can access the config values via dependency injection
public class MyClass
{
public MyClass(IConfiguration configuration)
{
string databaseConnectionString = configuration["Database:ConnectionString"];
}
}
but what if the code runs in production mode? The information doesn't exist in the production file so I would have to read from the environment variables.
Would I have to create an environment variable called Database:ConnectionString and .NET Core maps all the system environment variables into the configuration file during startup if they don't exist? Or how would I pass in sensitive data to the configuration?
With the default builder, ASP.NET Core will load the configuration from multiple sources, where later sources have the chance to overwrite earlier ones. The default sources in non-development environments are the following:
General JSON configuration from appsettings.json
Environment-specific JSON configuration from appsettings.<Environment>.json
Environment variables, e.g. ConnectionStrings:DefaultConnection or ConnectionStrings__DefaultConnection (both map to the same configuration path)
Command-line arguments
So you have the ability to overwrite the configuration from the JSON files by default using both environment variables and command line arguments.
When it comes to production use, there are also other means to protect the secrets. For example, you could simply edit the appsettings.Production.json during deployment, so that the values will never leave the machine itself.
There are several solutions for this. But obviously you want to keep things such as connection strings away from version controlled files.
If running locally i would sugest using the user secrets functionality in visual studio.
However you can also set environment variables from the cli. This is an example from the documentation about configuration:
set MyKey="My key from Environment"
set Position__Title=Environment_Editor
set Position__Name=Environment_Rick
dotnet run
Of course when running in azure the key vault is a good place to put these kinds of secrets and also has great integration into .Net.

Moving configuration outside of IIS root

In regular ASP.NET/MVC development we could move configuration entries from web.config in the application/site directory to machine.config.
With ASP.NET Core is there something similar, now that we have json based configuration files?
Well, technically, you can pull in any JSON from any location. Just pass the full filesystem path, instead of just "appsettings.json".
However, really, if you're talking about externalizing your configuration, you should probably use environment variables or some service like Azure Key Vault.

How do I add a web.config to an owin self-hosted web api?

I actually just created an NServiceBus self-hosted endpoint and bootstrapped owin self-hosted web api 2 by adding the Microsoft.AspNet.WebApi.OwinSelfHost nuget package. It's all up and running fine and I can hit the controller endpoints that I added, but the package didn't add the normal items like the web.config.
I'd like to have the normal web.config available to where I can also add in different build configurations (the transform files like web.debug.config, web.release.config, etc).
How do I add this into my project?
I tried just adding the file, but ConfigurationManager doesn't read it.
web.config is used for asp.net web application on a hosted server. As you are using a self-hosted server then web.config is no applicable. You would need app.config which would resolve to the executable name with the .config file extension.
Add app.config to the project and ConfigurationManager should be able to read it.
UPDATE:
It was indicated that the same config transformation was also needed for app.config
The following VS tool fills in the gap left between web.config transformations.
Configuration Transform
Automatically transform app.config or any other config during build
process. Once the transformation is set, it will run on other build
machines without the extension.
The link includes step by step instructions on how to use it in applying configuration transformations.

how to share connector configurations between applications in mule esb?

Instead of using mule domain project (supports only sharing of connector configurations of jms, http... limited connectors). I need to share connector configuration of Object store connector between applications. I am trying to access common data in multiple applications, hence I need this. please help me.
try with session Objects you can send session data between different mule application.
You could use configuration properties through a properties file in the domain project such as
domain.properties
Example properties:
domain.value1=true
domain.value2=my text
. This file would be under the
src/main/resource
folder in your domain project.
You can refer to this property file in your application as the global configuration element, property-placeholder. Example:
<context:property-placeholder location="..\..\domains\<domain project name>\domain.properties"/>
Simply refer to the property using
${domain.value1}

wcf client configuration

I have wcf client. It uses .NET 3.5.
When I compile the client I get two files:
client.exe and
client.exe.config.
The second file contains configuration for the wcf client.
In my case I need to prevent the user sitting on the computer to see the urls and change some other parameters from the config file.
So the requirements are, the end user not to see and modify the data stored in the config. The config file contains the same data as app.config. I need to forbid the person using the program to see the end point urls so easy.
Also I have a lot of configuration there so I do not like to code in the moment.
Is there any solution for the problem (embedded app.config of something else)?
Edit: I do not need configurable options. The config file is automatically created when adding service reference from the studio.
Regards
You can also create your proxies programatically instead of using the service reference feature.
Every parameter in the serviceModel config section can be represented in code as well.
The ChannelFactory class will help you create proxies to the service.
You can easily encrypt entire parts of your config files - and not just web.config in web scenarios, but also application config's in stand-alone apps.
Check out some resources on how to do this:
Encrypting web.config values
Encrypting passwords in .NET app.config file
Encrypting the app.config file for Winforms application