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 upgraded. The 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
- Use a gateway device that has enebular agent installed 
- On the gateway device, go to terminal and type the following command 
- `sudo nano /home/enebular/enebular-runtime-agent/agent/lib/node-red-controller.js`

## Step 2: 
- Find the place to update the code for environment variables 
- Press 'ctrl + w' and type 'env' and Press 'enter' 
- You'll find code like below: `let env = Object.assign(process.env, { ENEBULAR_ASSETS_DATA_PATH: this._assetsDataPath });`
-  Update the code to below: 

```
let env = Object.assign(process.env, JSON.parse(_fs.default.readFileSync(this._assetsDataPath+'/env.json'))); 
env['ENEBULAR_ASSETS_DATA_PATH'] = this._assetsDataPath;
```
- Type (ctrl + x) and press enter and on prompt, type Y and enter. 
- The above code will let enebular flow read an env.json stored at the 'file assets location', parse it and add the configuration parameters into environment variables to be passed to enebular-node-red.

## Step 3: (Optional: File deploy can be used) 

- Add a sample file at env.json at '/home/enebular/enebular-runtime-agent/ports/awsiot/assets/' using the command `sudo nano /home/enebular/enebular-runtime-agent/ports/awsiot/assets/env.json`
-  Add the following `{ "DeviceName":"test1" }` 
-  Type (ctrl + x) and press enter. On prompt, type Y and enter. 

## Step 4: 
- Restart the enebular agent using the command to let the changes take effect: ` 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 parameters.

## Step 5: Updating the list.

- Create a json file. Below is an example of the same.

```
{ 
"name":"satya", 
"email": "b.satyakishore@live.com", 
"AWS-accessKey": "AKIAYO*******77CRC3", 
"AWS-secretKey": "zcwOoCro0c***********Muew13W9756HzAg", 
"AWS-region": "ap-northeast-1", 
"AWS-bucket": "eric-farming-project" 
}
```
- Now use file deploy (https://docs.enebular.com/ja/files/introduction) to deploy the same file on device. Please name it as `env.json`
- You need to restart the flow running on the device to update the configuration. You can do it on enebular.com using https://docs.enebular.com/ja/Device/FlowStatus.html
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/222933/eaf3071a-a84b-3fe8-e556-d3275d3ae9e9.png)


## Step 6: Using these configuration in a flow. We'll use AWS node as an example

- Any node can access the above variables using `$(ENV_NAME)`. For example, in case of aws-config node. Even the secret access key is `$(AWS-secretKey)`.

- Install the following AWS-S3 package: node-red-node-aws
- Adding the configuration in AWS-Node
- ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/222933/5ef6b0df-ff51-0719-0f0a-4f5f2a7570f7.png)
- Completing the flow:
    - <img width="762" alt="Screen Shot 2019-12-18 at 11.26.07.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/222933/6fdb5a89-9ffa-f5d1-eb5a-b872d5eb3608.png">
- You can also get the flow from enebular-discover: https://enebular.com/discover/flow/848265e9-7a30-485d-9526-d8e8dd8c2cd9
- Deploy the flow.

### Result:

- The above flow sends env.json to S3 bucket named eric-farming-project.
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/222933/8307e94f-0209-95e1-8418-ff694736b308.png)