TritonDataCenter / sdc-docker

Docker Engine for Triton
Mozilla Public License 2.0
182 stars 49 forks source link

Spaces in enabledLogDrivers list causes sdc-docker service to fail to start #108

Open ynnadrules opened 7 years ago

ynnadrules commented 7 years ago

Currently, enabled log drivers are parsed from a comma-separated list and placed in an array of strings. Those strings are then used as property indexes on a LOG_DRIVERS object.

This breaks if there were any spaces in the comma-separated list of drivers, "json-file, none, gets split(",") that results in ["json-file", " none"] which eventually leads to LOG_DRIVERS.hasOwnProperty(" none") and that ultimately leads to assertion failure.

Here's the snippet of code that does the validation of log drivers.

    if (config.enabledLogDrivers) {
        assert.string(config.enabledLogDrivers, 'config.enabledLogDrivers-raw');
        config.enabledLogDrivers = config.enabledLogDrivers.split(',');
    } else {
        config.enabledLogDrivers = ['json-file'];
    }
    assert.arrayOfString(config.enabledLogDrivers, 'config.enabledLogDrivers');
    config.enabledLogDrivers.forEach(function _checkLogDriver(driver) {
        assert.ok(common.LOG_DRIVERS.hasOwnProperty(driver),
            'config.enabledLogDrivers.' + driver + ' is not a valid driver');
    });

A valid fix is to trim each log driver from the comma-separated list after it's been converted into an array:

config.enabledLogDrivers = config.enabledLogDrivers.split(',').map(function(driver) { 
    return driver.trim();  
});
ynnadrules commented 7 years ago

PR coming right up