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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user