rails_safe_tasks 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: efc6f9c7b18b62d7cfd30682dd4b74a7371d76fa
4
+ data.tar.gz: 893e72b6e20dd467b589ac04ea99494746abbf89
5
+ SHA512:
6
+ metadata.gz: 36fc019a7aa2201cb9d29cb7bb1b5aa128fe0472006cc5477c0845d8c9ab32409751a63e6b11d42afc950516980611087fac151f3158828ec37657d79fd8783a
7
+ data.tar.gz: 389fe332aacfa30565de5503c56f083a623d2f60ac127855bfe93780b2bb7031a224e6c81446cae9522b300ba0d0f01b0c4d85d636ead99d27224291f75b92a8
@@ -0,0 +1,53 @@
1
+ require 'rails_safe_tasks/railtie'
2
+
3
+ module RailsSafeTasks
4
+ class << self
5
+
6
+ #
7
+ # An array of built-in task names which should be protected.
8
+ #
9
+ def dangerous_tasks
10
+ @dangerous_tasks ||= [
11
+ 'db:drop',
12
+ 'db:reset',
13
+ 'db:schema:load',
14
+ 'db:migrate:reset'
15
+ ]
16
+ end
17
+
18
+ #
19
+ # An array of RAILS_ENV values which should not permit dangerous tasks
20
+ # to be executed.
21
+ #
22
+ def restricted_environments
23
+ @restricted_environments ||= ['production']
24
+ end
25
+
26
+ #
27
+ # Add a custom check which will be executed whenever we check to see if the
28
+ # current environment should allow dangerous tasks or not.
29
+ #
30
+ def custom_check(&block)
31
+ @custom_checks ||= []
32
+ @custom_checks << block
33
+ end
34
+
35
+ #
36
+ # Should the current environment be protected from running dangerous tasks?
37
+ #
38
+ def restrict?
39
+ # Check the list of restricted environments
40
+ restricted_environments.include?(Rails.env.to_s) ||
41
+
42
+ # Check that it's not deployed with Capistrano
43
+ File.exist?(Rails.root.join('REVISION')) ||
44
+
45
+ # Check the custom checker
46
+ (@custom_checks && @custom_checks.any? { |c| c.call == true }) ||
47
+
48
+ # Nothing else matched, it's OK
49
+ false
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ module RailsSafeTasks
2
+ class Railtie < ::Rails::Railtie
3
+
4
+ rake_tasks do
5
+ load File.expand_path(File.join('..', '..', 'tasks', 'rails_safe_tasks.rake'), __FILE__)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ namespace :rails_safe_tasks do
2
+ task :disable do
3
+ if RailsSafeTasks.restrict?
4
+ if ENV['I_AM_SURE'] != "1"
5
+ puts
6
+ puts "\e[31m** You cannot run this task with the production environment"
7
+ puts "** If you want to, set the 'I_AM_SURE' environment variable to 1\e[0m"
8
+ puts "** This has been disabled using the 'rails_safe_tasks' gem."
9
+ puts
10
+ exit 1
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ RailsSafeTasks.dangerous_tasks.each do |task|
17
+ Rake::Task[task].enhance ['rails_safe_tasks:disable']
18
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_safe_tasks
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cooke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Automatically disable dangerous Rake tasks in production
14
+ email:
15
+ - me@adamcooke.io
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/rails_safe_tasks.rb
21
+ - lib/rails_safe_tasks/railtie.rb
22
+ - lib/tasks/rails_safe_tasks.rake
23
+ homepage: https://github.com/adamcooke/rails_safe_tasks
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.2.2
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Automatically disable dangerous Rake tasks in production
47
+ test_files: []