Setting device specific config for nodes using file deploy
Introduction
In a lot of projects, device specific configuration like AWS-Credentials or device name are saved in file and needs to be used in flows. But since it's not possible for all nodes to access these configuration parameters through flow, node-red provides a concept called environment variables that can be accessed from a flow. Current version of Node-red used in enebular does not support the environment variables. This is a work around process that lets the user read environment variables till enebular Node-red version is upgrade. steps below will modify enebular-runtime-agent (compiled code) to read a env.json file which can be deployed through enebular's file deploy.
Steps to be followed
Step 1
Step 1
sudo nano /home/enebular/enebular-runtime-agent/agent/lib/node-red-controller.js
Step 2:
let env = Object.assign(process.env, { ENEBULAR_ASSETS_DATA_PATH: this._assetsDataPath });
let env = Object.assign(process.env, JSON.parse(_fs.default.readFileSync(this._assetsDataPath+'/env.json')));
env['ENEBULAR_ASSETS_DATA_PATH'] = this._assetsDataPath;
Step 3: (Optional: File deploy can be used)
sudo nano /home/enebular/enebular-runtime-agent/ports/awsiot/assets/env.json
{ "DeviceName":"test1" }
Step 4:
sudo service enbular-agent-enebular restart
This will now let your new flow use the environment variables to access configuration parameters stored in json file on each device. This is a powerful tool since you can now use same flow on various devices that are working with device specific settings/configuration parameter
Step 5: Updating the list.
{
"name":"satya",
"email": "[email protected]",
"AWS-accessKey": "AKIAYO*******77CRC3",
"AWS-secretKey": "zcwOoCro0c***********Muew13W9756HzAg",
"AWS-region": "ap-northeast-1",
"AWS-bucket": "eric-farming-project"
}
env.json
Step 6: Using these configuration in a flow. We'll use AWS node as an example
$(ENV_NAME)
. For example, in case of aws-config node. Even the secret access key is $(AWS-secretKey)
. Completing the flow:
Result:
Reference
이 문제에 관하여(Setting device specific config for nodes using file deploy), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/BSatyaKishore/items/897884b090cb9f4fd66e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)