|
| 1 | +<?php |
| 2 | +namespace Drush\Commands; |
| 3 | + |
| 4 | +use Consolidation\AnnotatedCommand\CommandData; |
| 5 | +use Drush\Commands\DrushCommands; |
| 6 | +use Symfony\Component\Console\Input\InputOption; |
| 7 | + |
| 8 | +/** |
| 9 | + * Edit this file to reflect your organization's needs. |
| 10 | + */ |
| 11 | + |
| 12 | +class PolicyCommands extends DrushCommands { |
| 13 | + |
| 14 | + /** |
| 15 | + * Prevent catastrophic braino. Note that this file has to be local to the |
| 16 | + * machine that initiates the sql:sync command. |
| 17 | + * |
| 18 | + * hook validate sql:sync |
| 19 | + * |
| 20 | + * @throws \Exception |
| 21 | + */ |
| 22 | + public function sqlSyncValidate(CommandData $commandData) { |
| 23 | + if ($commandData->input()->getArgument('destination') == '@prod') { |
| 24 | + throw new \Exception(dt('Per !file, you may never overwrite the production database.', ['!file' => __FILE__])); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Limit rsync operations to production site. |
| 30 | + * |
| 31 | + * hook validate core:rsync |
| 32 | + */ |
| 33 | + public function rsyncValidate(CommandData $commandData) { |
| 34 | + if (preg_match("/^@prod/", $commandData->input()->getArgument('destination'))) { |
| 35 | + throw new \Exception(dt('Per !file, you may never rsync to the production site.', ['!file' => __FILE__])); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Unauthorized may not execute updates. |
| 41 | + * |
| 42 | + * @hook validate updatedb |
| 43 | + */ |
| 44 | + public function validateUpdateDb(CommandData $commandData) { |
| 45 | + if (!$commandData->input()->getOption('secret') == 'mysecret') { |
| 46 | + throw new \Exception(dt('UpdateDb command requires a secret token per site policy.')); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @hook option updatedb |
| 52 | + * @option secret A required token else user may not run updatedb command. |
| 53 | + */ |
| 54 | + public function optionsetUpdateDb($options = ['secret' => self::REQ]) {} |
| 55 | +} |
0 commit comments