From 66c7806cfa30e65dcef3ef060d89e7a86f5bbf4a Mon Sep 17 00:00:00 2001 From: Benedict Aas Date: Wed, 9 May 2018 11:06:18 +0100 Subject: [PATCH] feat(GUI): blacklist drives with an env var (#2315) We add an environment variable `ETCHER_BLACKLISTED_DRIVES` that allows us to filter certain drives from ever showing up in Etcher with comma separated device paths, e.g. `/dev/sda,/dev/sdb,/dev/mmcblk0`. Closes: https://github.com/resin-io/etcher/issues/2264 Change-Type: patch Changelog-Entry: Allow blacklisting of drives through and environment variable ETCHER_BLACKLISTED_DRIVES. --- lib/gui/app/app.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/gui/app/app.js b/lib/gui/app/app.js index a434456f..080802e8 100644 --- a/lib/gui/app/app.js +++ b/lib/gui/app/app.js @@ -47,6 +47,8 @@ const driveScanner = require('./modules/drive-scanner') const osDialog = require('./os/dialog') const exceptionReporter = require('./modules/exception-reporter') +/* eslint-disable lodash/prefer-lodash-method */ + // Enable debug information from all modules that use `debug` // See https://github.com/visionmedia/debug#browser-support // @@ -55,6 +57,16 @@ const exceptionReporter = require('./modules/exception-reporter') process.env.DRIVELIST_DEBUG = /drivelist|^\*$/i.test(process.env.DEBUG) ? '1' : '' window.localStorage.debug = process.env.DEBUG +/** + * @summary Environment variable blacklisted drives by path + * @type {Array} + * @constant + * @private + */ +const BLACKLISTED_DRIVES = process.env.ETCHER_BLACKLISTED_DRIVES + ? process.env.ETCHER_BLACKLISTED_DRIVES.split(',') + : [] + const app = angular.module('Etcher', [ require('angular-ui-router'), require('angular-ui-bootstrap'), @@ -209,7 +221,14 @@ app.run(($timeout) => { // available drives list has changed, and incorrectly // keeps asking the user to "Connect a drive". $timeout(() => { - availableDrives.setDrives(drives) + if (BLACKLISTED_DRIVES.length) { + const allowedDrives = drives.filter((drive) => { + return !BLACKLISTED_DRIVES.includes(drive.device) + }) + availableDrives.setDrives(allowedDrives) + } else { + availableDrives.setDrives(drives) + } }) })