Skip to content

Commit 7d1386a

Browse files
StavoveiCfago
andauthored
DEV-1993: Add drush policy to make drush sync command safer. (#48)
* DEV-1993: Alter drush sync command with safe defaults. * Update PolicyCommands.php Co-authored-by: Wolfgang Ziegler <fago@users.noreply.github.com>
1 parent 6deeed2 commit 7d1386a

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

drush/Commands/PolicyCommands.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Drush\Commands;
4+
5+
use Consolidation\AnnotatedCommand\CommandData;
6+
7+
/**
8+
* Edit this file to reflect your organization's needs.
9+
*/
10+
class PolicyCommands extends DrushCommands {
11+
12+
/**
13+
* Prevent catastrophic braino. Note that this file has to be local to the
14+
* machine that initiates the sql:sync command.
15+
*
16+
* @hook validate sql:sync
17+
*
18+
* @throws \Exception
19+
*/
20+
public function sqlSyncValidate(CommandData $commandData) {
21+
if ($commandData->input()->getArgument('target') == '@live') {
22+
throw new \Exception(dt('Per !file, you may never overwrite the production database.', ['!file' => __FILE__]));
23+
}
24+
}
25+
26+
/**
27+
* Limit rsync operations to production site.
28+
*
29+
* @hook validate core:rsync
30+
*
31+
* @throws \Exception
32+
*/
33+
public function rsyncValidate(CommandData $commandData) {
34+
if (preg_match("/^@live/", $commandData->input()->getArgument('target'))) {
35+
throw new \Exception(dt('Per !file, you may never rsync to the production site.', ['!file' => __FILE__]));
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)