Skip to content

Commit 6587fb5

Browse files
committed
Add 'trust' command
1 parent 5df7ed7 commit 6587fb5

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

cli/Valet/Brew.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,17 @@ function restartLinkedPhp()
197197
{
198198
$this->restartService($this->linkedPhp());
199199
}
200+
201+
/**
202+
* Create the "sudoers.d" entry for running Brew.
203+
*
204+
* @return void
205+
*/
206+
function createSudoersEntry()
207+
{
208+
$this->files->ensureDirExists('/etc/sudoers.d');
209+
210+
$this->files->put('/etc/sudoers.d/brew', 'Cmnd_Alias BREW = /usr/local/bin/brew *
211+
%admin ALL=(root) NOPASSWD: BREW'.PHP_EOL);
212+
}
200213
}

cli/Valet/Valet.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,17 @@ function onLatestVersion($currentVersion)
6565

6666
return version_compare($currentVersion, trim($response->body->tag_name, 'v'), '>=');
6767
}
68+
69+
/**
70+
* Create the "sudoers.d" entry for running Valet.
71+
*
72+
* @return void
73+
*/
74+
function createSudoersEntry()
75+
{
76+
$this->files->ensureDirExists('/etc/sudoers.d');
77+
78+
$this->files->put('/etc/sudoers.d/valet', 'Cmnd_Alias VALET = /usr/local/bin/valet *
79+
%admin ALL=(root) NOPASSWD: VALET'.PHP_EOL);
80+
}
6881
}

cli/valet.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@
253253
output('NO');
254254
}
255255
})->descriptions('Determine if this is the latest version of Valet');
256+
257+
/**
258+
* Install the sudoers.d entries so password is no longer required.
259+
*/
260+
$app->command('trust', function () {
261+
Brew::createSudoersEntry();
262+
Valet::createSudoersEntry();
263+
264+
info('Sudoers entries have been added for Brew and Valet.');
265+
})->descriptions('Add sudoers files for Brew and Valet to make Valet commands run without passwords');
256266
}
257267

258268
/**

tests/ConfigurationTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Valet\Brew;
4+
use Valet\Valet;
35
use Valet\Filesystem;
46
use Valet\Configuration;
57
use Illuminate\Container\Container;
@@ -120,4 +122,15 @@ public function test_update_key_updates_the_specified_configuration_key()
120122
$config->shouldReceive('write')->once()->with(['foo' => 'bar', 'bar' => 'baz']);
121123
$config->updateKey('bar', 'baz');
122124
}
125+
126+
127+
public function test_trust_adds_the_sudoer_files()
128+
{
129+
$files = Mockery::mock(Filesystem::class.'[ensureDirExists,put]');
130+
$files->shouldReceive('ensureDirExists')->with('/etc/sudoers.d')->twice();
131+
$files->shouldReceive('put')->twice();
132+
swap(Filesystem::class, $files);
133+
resolve(Brew::class)->createSudoersEntry();
134+
resolve(Valet::class)->createSudoersEntry();
135+
}
123136
}

0 commit comments

Comments
 (0)