As it turns out, a websocket request doesn't contain some of the
hashable properties in order to be validated. Because of that, we'll
still use tokens here until we find a better way to do it.
Instead, we want to hash a header to sign a request with a client nonce,
http method and URL. This is a first step towards protecting the backend
against eavesdropping.
Please note that this will still be susceptible to replay attacks.
ProcessManager can be used to "register" processes and along with it, a launch function
that will be executed when a process is requested to launch.
Prior to this commit the IPFS process has not be registered and launching the process
was done manually, bypassing ProcessManager APIs.
With this commit we take advantage of ProcessManager APIs to register the IPFS process
and launch it using the `process:launch` event.
So far, `ProcessManager` was able to only register a `process:launch` handler.
There was no way to tell `ProcessManager` how to stop processes. This hasn't
been a problem so far as most of the service processes can be started without the usage
of the `ProcessManager`, but turns out to be necessary if we want Embark UI to be able
to pick up running services.
A good example is the webserver process, which until now bypasses the `ProcessManager`
all together. The webserver sets up two event handlers to start and stop it respectively:
```
this.events.setCommandHandler('start-webserver', () => this.server.start());
this.events.setCommandHandler('stop-webserver', () => this.server.stop());
```
In the future, this should happen through the `ProcessManager` instead, so the webserver
process can be picked up by Embark UI, like this:
```
this.request('process:register', 'webserver', () => {
this.server.start();
});
// and then
this.request('process:launch', 'webserver', () => {
// server started
});
```
Notice that the given callback to registering a process is actually the function that
gets called to launch the process.
Having that in mind, and considering that we also need a way to stop the process through
`ProcessManager, so we don't introduce a regression, we need a way to register a stop
call back as well.
The new API introduced in this commit looks like this:
```
this.request('process:register', 'webserver', {
launchFn: (callback) => { this.server.start(callback) },
stopFn: (callback) => this.server.stop(callback) }
});
// and then
this.request('process:launch', 'webserver', (err, message, port) => {
// server started
});
this.request('process:stop', 'webserver', err => {
// server stopped
});
```
Notice that `process:register` works exactly the same way as before as well.
Another thing to notice is that all parameters emitted by the underlying process
are propagated to the outside caller, which is why `err`, `message` and `port` are
available inside the launch callback.
After the code was rebased, there were some additional changes for getting websockets logs that needed to be catered for.
When there is a call to get all logs for a process, the state entity is updated with a new array item containing all the logs (this is then reduced and selected for rendering). In the case of a websocket log that simply returns only one log item, the latest full log for the process is found in the state entities, and it’s logs are appending to with the data from the websocket.
Additionally, log limits were updated to be passed in as a parameter to the API calls from the frontend. Parameter validation (for `limit`) was also added in this commit.
*Console.js*
- Moved `DEFAULT_PROCESS` const to outside of the `Console` class (but inside the module).
- Removed `(` and `)` from `.filter` in `getProcessLogs()`.
- Updated comments
*logger.js*
- Moved `dateFormat` and `logRegex` to constants outside of `Logger` class
- Moved the `parseLogFile` method inside of the `Logger` class (ES6 style)
- Added a log limit to the `parseLogFile` method
- Added the log path to the constants file and used inside of `Logger`
*cmd_controller.js*
- Defaulted `this.context` to `[constants.context.any]` in the constructor.
- Changed `’embark’` to split modules`coreProcess` and `loggerApi`.
*engine.js*
- Changed `’embark’` to split modules`coreProcess` and `loggerApi`.
The embark log file is being overwritten each time embark is run. There is a separate log file for each context, so that running, for example, `embark run` then `embark console` doesn’t get the `run` log overwritten with the `console` log.