Merge pull request #3000 from balena-io/fix-macos-elevation-in-development

Fix elevation on macos in development
This commit is contained in:
Alexis Svinartchouk 2019-12-06 12:48:17 +01:00 committed by GitHub
commit 517511e5be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -1,7 +1,7 @@
'use strict'
const { execFile } = require('child_process')
const { env, resourcesPath } = require('process')
const { argv, env } = require('process')
const { join } = require('path')
const { promisify } = require('util')
@ -10,6 +10,19 @@ const execFileAsync = promisify(execFile)
const SUCCESSFUL_AUTH_MARKER = 'AUTHENTICATION SUCCEEDED'
const EXPECTED_SUCCESSFUL_AUTH_MARKER = `${SUCCESSFUL_AUTH_MARKER}\n`
/* eslint-disable-next-line require-jsdoc */
const getAppPath = () => {
for (const arg of argv) {
/* eslint-disable-next-line lodash/prefer-lodash-method */
const [ option, value ] = arg.split('=')
if (option === '--app-path') {
return value
}
}
/* eslint-disable-next-line quotes */
throw new Error("Couldn't find --app-path= in argv")
}
exports.sudo = async (command) => {
try {
const { stdout, stderr } = await execFileAsync(
@ -19,7 +32,7 @@ exports.sudo = async (command) => {
encoding: 'utf8',
env: {
PATH: env.PATH,
SUDO_ASKPASS: join(resourcesPath, 'app', __dirname, 'sudo-askpass.osascript.js')
SUDO_ASKPASS: join(getAppPath(), __dirname, 'sudo-askpass.osascript.js')
}
}
)