1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-06 08:40:09 +01:00

Add 'trust' command

This commit is contained in:
Matt Stauffer
2018-01-04 16:36:16 -05:00
parent 5df7ed7a1a
commit 6587fb53a5
4 changed files with 49 additions and 0 deletions

View File

@@ -197,4 +197,17 @@ function restartLinkedPhp()
{
$this->restartService($this->linkedPhp());
}
/**
* Create the "sudoers.d" entry for running Brew.
*
* @return void
*/
function createSudoersEntry()
{
$this->files->ensureDirExists('/etc/sudoers.d');
$this->files->put('/etc/sudoers.d/brew', 'Cmnd_Alias BREW = /usr/local/bin/brew *
%admin ALL=(root) NOPASSWD: BREW'.PHP_EOL);
}
}

View File

@@ -65,4 +65,17 @@ function onLatestVersion($currentVersion)
return version_compare($currentVersion, trim($response->body->tag_name, 'v'), '>=');
}
/**
* Create the "sudoers.d" entry for running Valet.
*
* @return void
*/
function createSudoersEntry()
{
$this->files->ensureDirExists('/etc/sudoers.d');
$this->files->put('/etc/sudoers.d/valet', 'Cmnd_Alias VALET = /usr/local/bin/valet *
%admin ALL=(root) NOPASSWD: VALET'.PHP_EOL);
}
}

View File

@@ -253,6 +253,16 @@
output('NO');
}
})->descriptions('Determine if this is the latest version of Valet');
/**
* Install the sudoers.d entries so password is no longer required.
*/
$app->command('trust', function () {
Brew::createSudoersEntry();
Valet::createSudoersEntry();
info('Sudoers entries have been added for Brew and Valet.');
})->descriptions('Add sudoers files for Brew and Valet to make Valet commands run without passwords');
}
/**

View File

@@ -1,5 +1,7 @@
<?php
use Valet\Brew;
use Valet\Valet;
use Valet\Filesystem;
use Valet\Configuration;
use Illuminate\Container\Container;
@@ -120,4 +122,15 @@ public function test_update_key_updates_the_specified_configuration_key()
$config->shouldReceive('write')->once()->with(['foo' => 'bar', 'bar' => 'baz']);
$config->updateKey('bar', 'baz');
}
public function test_trust_adds_the_sudoer_files()
{
$files = Mockery::mock(Filesystem::class.'[ensureDirExists,put]');
$files->shouldReceive('ensureDirExists')->with('/etc/sudoers.d')->twice();
$files->shouldReceive('put')->twice();
swap(Filesystem::class, $files);
resolve(Brew::class)->createSudoersEntry();
resolve(Valet::class)->createSudoersEntry();
}
}