This PR addresses an issue where selecting env as the configuration source and providing a string value would incorrectly treat the string as a hostname. If the string is actually a JSON configuration, this results in an error as the JSON string is incorrectly used as a hostname.
Changes:
Added a check to determine if the value is a string and if the configuration type is env.
Attempt to parse the string as JSON if both conditions are met.
If JSON parsing is successful, use the resulting object for the configuration.
If JSON parsing fails, keep the string value as is, ensuring the previous behavior remains unchanged.
When env is selected as the configuration source and the value is a string, it can either be a simple hostname or a JSON configuration. Without this change, JSON strings cause errors since they are misinterpreted as hostnames. This enhancement ensures that environment variable configurations are more flexible. This improves the usability of the Redis Config Node in environments where configuration is provided via environment variables like in Docker or Kubernetes.
Example 1:
REDIS_CONFIG = '{"host":"localhost","port":6379}'
is parsed and used as a object.
REDIS_CONFIG = 'localhost'
continues to be used as a hostname.
Example 2:
in my use-case i execute NodeRED in Kubernetes and pass configurations via environment variables to it. For anyone how is interested, here is a snipped of my manifest and how I use it in NodeRed:
This PR addresses an issue where selecting
env
as the configuration source and providing a string value would incorrectly treat the string as a hostname. If the string is actually a JSON configuration, this results in an error as the JSON string is incorrectly used as a hostname.Changes:
When env is selected as the configuration source and the value is a string, it can either be a simple hostname or a JSON configuration. Without this change, JSON strings cause errors since they are misinterpreted as hostnames. This enhancement ensures that environment variable configurations are more flexible. This improves the usability of the Redis Config Node in environments where configuration is provided via environment variables like in Docker or Kubernetes.
Example 1:
is parsed and used as a object.
continues to be used as a hostname.
Example 2:
in my use-case i execute NodeRED in Kubernetes and pass configurations via environment variables to it. For anyone how is interested, here is a snipped of my manifest and how I use it in NodeRed: