When I am injecting a RxHttpClient in micronaut, I have an url with a token that I want to get from an environment variable to avoid hardcoding a secret.
In my service, I have injected the client like this:
#Client('${System.getenv(\'BOT_URL\')}')
#Inject
RxHttpClient httpClient
Being BOT_URL my url that's stored in an environment variable.
The project build but it fails while trying to use the client with this error:
2021-03-20 20:05:14.37 Could not resolve placeholder ${System.getenv('BOT_KEY')}
My variable is correctly defined in the server, how can I access to it when injecting the client?
Micronaut ships with pre-made PropertySourceLoaders that will resolve PropertySources from different sources. You can read more on externalized configuration through the docs.
Besides these PropertySourceLoaders, PropertySources are resolved from environment variables and are automatically injected and available for use within the ApplicationContext following the property source key syntax:
i.e. SOME_ENVIRONMENT_VARIABLE translates to some.environment.variable
Hence you can simply inject your HttpClient declaratively with the environment variable key translated to dot-separated-property-key syntax:
#Client('${bot.url}')
#Inject
RxHttpClient httpClient
You should be able to access environment variables just using ${BOT_URL}. I know for a fact that this works in the application.yml file. If it doesn't work in the annotation you can always create a property in application.yml with the value of the environment variable and use the property in your annotation.
For the docs on this, try the "Property value binding" section of the micronaut docs.
Related
I am have created the camel route which use camel-paho component to consume MQTT stream. It is enabled with SSL and i need to pass the socket-factory. I went through the documentation od camel-paho and below parameter is available
socketFactory (security)
Sets the SocketFactory to use. This allows an application to apply its own policies around the creation of network sockets. If using an SSL connection, an SSLSocketFactory can be used to supply application-specific security settings.
I have passed the custom socket-factory in the URL by setting the above parameter to the class name as below
from("paho:"test?brokerUrl="+MQTT_BROKER_URL+"&clientId=subX4&cleanSession=false&socketFactory=com.sample.mqttCustomSocketFactory.java")
Above setting is not working. Is that the correct way of passing the parameter ?
Whenever you set a complex object to the Camel endpoint parameter, it needs to be a bean reference. So in your case, the endpoint should look something like this:
from("paho:test?...&socketFactory=#mySocketFactory")
where the #mySocketFactory is defined in the Camel bean registry like this:
SocketFactory mySocketFactory = ...
context.getRegistry().bind("mySocketFactory", mySocketFactory);
or in Spring context XML:
<bean id="mySocketFactory" ...>
When I am using same development keys and private rsa key in sample app provided by docusign then that is working. But when using same keys in my application is shows below error while creating envelope.
Sample app has docusign.esign.dll 4.1.1 and in my case its docusign.esign.dll 5.0.0.
Anything I am missing while calling CreateEnvelope or is there any configuration issue?
I can't see the code you used to obtain accessToken, but you should ensure that you provided the correct information and the same environment (account-d vs. account.docusign.com).
Also, you create a new Configuration() object called config, but then use _configuration in the code I can use. This is a bit odd. I wonder if you set the BaseUrl correctly for the _configuration object you did use.
Also, you need to pass the config object when to the API so that it is used.
Im using NodeJS action in openwhisk.
Is there any way to pass environment variables into whisk so I can read them in my NodeJS action using process.env ?
This is possible but you need to use a custom Docker runtime. The default built-in Node.js runtime does not support this. Apache OpenWhisk uses default action parameters, rather than environment parameters, to pass things like credentials and other application configuration to action code.
If you extend the existing Node.js Docker runtime for Apache OpenWhisk, you can set environment parameters in the build file for the image. This can then be used as the --docker parameter value when creating the action.
I'm having some problem with accessing my secret environments properties I've set in my build stage. In the build environment properties I got two secret fields called "w_username" and "w_password", however, I can not access these properties inside of my NodeJS runtime. I've tried with process.env['w_username'] but it seems like it can't find it. How is it possible to access them?
Using NodeJS 6.x, npm 6.x with SDK for NodeJS on IBM cloud.
You can directly access the build environment properties in the next stage in the toolchain with their names like w_username and w_password.
You can examine the environment properties for a pipeline job by
running the env command in the job's script.
You can also define your own environment properties. For example, you might define an API_KEY property that passes an API key that is used to access IBM Cloud resources by all scripts in the pipeline.
You can add the following types of properties:
Text: A property key with a single-line value.
Text Area: A property key with a multi-line value.
Secure: A property key with a single-line value that is secured with AES-128 encryption. The value is displayed as asterisks.
Properties: A file in the project's
repository. This file can contain multiple properties. Each property
must be on its own line. To separate key-value pairs, use the equals
sign (=). Enclose all string values in quotation marks. For example,
MY_STRING="SOME STRING VALUE".
For more information, refer here
Hope this helps
i have a console application.i want to read some configuration settings from DB. And these settings should be stored in a global or session variable so
i can use the variable through out the application ,
how can i implement it ? what are the ways ? which channels do i need to use ? and how payload should be stored?
It's not at all clear what you mean, but you can declare a Map object as a #Bean (or <bean/>) and load it up during initialization.
You can then reference it directly in your components by #Autowired or via SpEL in expressions in integration components: #mapBean['foo'].