policy.drush.inc

  1. 8.0.x examples/policy.drush.inc
  2. 6.x examples/policy.drush.inc
  3. 7.x examples/policy.drush.inc
  4. 4.x examples/policy.drush.inc
  5. 5.x examples/policy.drush.inc
  6. master examples/policy.drush.inc

Example policy commandfile. Modify as desired.

Validates commands as they are issued and returns an error or changes options when policy is violated.

You can copy this file to any of the following 1. A .drush folder in your HOME folder. 2. Anywhere in a folder tree below an active module on your site. 3. /usr/share/drush/commands (configurable) 4. In an arbitrary folder specified with the --include option.

Functions

File

examples/policy.drush.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Example policy commandfile. Modify as desired.
  5. *
  6. * Validates commands as they are issued and returns an error
  7. * or changes options when policy is violated.
  8. *
  9. * You can copy this file to any of the following
  10. * 1. A .drush folder in your HOME folder.
  11. * 2. Anywhere in a folder tree below an active module on your site.
  12. * 3. /usr/share/drush/commands (configurable)
  13. * 4. In an arbitrary folder specified with the --include option.
  14. */
  15. /**
  16. * Implement of drush_hook_COMMAND_validate().
  17. *
  18. * Prevent catastrophic braino. Note that this file has to be local to the machine
  19. * that intitiates sql-sync command.
  20. */
  21. function drush_policy_sql_sync_validate($source = NULL, $destination = NULL) {
  22. if ($destination == '@prod') {
  23. return drush_set_error(dt('Per examples/policy.drush.inc, you may never overwrite the production database.'));
  24. }
  25. }
  26. /**
  27. * Implement of drush_hook_COMMAND_validate().
  28. *
  29. * To test this example without copying, execute `drush --include=./examples updatedb`
  30. * from within your drush directory.
  31. *
  32. * Unauthorized users may view pending updates but not execute them.
  33. */
  34. function drush_policy_updatedb_validate() {
  35. // Check for a token in the request. In this case, we require --token=secret.
  36. if (!drush_get_option('token') == 'secret') {
  37. drush_log(dt('Per site policy, you must add a secret --token complete this command. See examples/policy.drush.inc. If you are running a version of drush prior to 4.3 and are not sure why you are seeing this message, please see http://drupal.org/node/1024824.'), 'warning');
  38. drush_set_context('DRUSH_AFFIRMATIVE', FALSE);
  39. drush_set_context('DRUSH_NEGATIVE', TRUE);
  40. }
  41. }
  42. /**
  43. * Implementation of drush_hook_COMMAND_validate().
  44. *
  45. * Only sudo tells me to make a sandwich: http://xkcd.com/149/
  46. */
  47. function drush_policy_make_me_a_sandwich_validate() {
  48. $name = posix_getpwuid(posix_geteuid());
  49. if ($name['name'] !== 'root') {
  50. return drush_set_error('MAKE_IT_YOUSELF', dt('What? Make your own sandwich.'));
  51. }
  52. }