carefully 0.1.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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/lib/carefully/version.rb +3 -0
- data/lib/carefully.rb +91 -0
- data/lib/generators/carefully/carefully.rb +10 -0
- data/lib/generators/carefully/carefully_generator.rb +7 -0
- metadata +79 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: ea36f1b96ed68e638bfea2ae39852b729f511a3c
|
|
4
|
+
data.tar.gz: 4d720f76d84d8383aae0a1a4c08655e0ed01498b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 534087a4cc0793607e5b59f593222fb83e654cfa5fca3bc236e766320d83d132c9d220b85b1c733f3d024c52f54d142813cfa951603d3d2357b3f42b5096a83e
|
|
7
|
+
data.tar.gz: 15340bed16ad7cffa76cfd8182dc0d119aca9f51d0685cdae870e8d43541200b05486b595a49ed35479b4973ad1c6d7143d3a1688334d026e7dc7a763de6ff37
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Pauls Liepa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Carefully
|
|
2
|
+
|
|
3
|
+
Additional layer of security when performing actions through rails console in sensitive environments.
|
|
4
|
+
|
|
5
|
+
### Installation
|
|
6
|
+
|
|
7
|
+
##### Add to Gemfile
|
|
8
|
+
```
|
|
9
|
+
gem 'carefully'
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
##### Run from terminal
|
|
13
|
+
```
|
|
14
|
+
rails g carefully
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Optionally you can edit config in `config/intializers/carefully.rb`
|
|
18
|
+
|
|
19
|
+
### Usage
|
|
20
|
+
|
|
21
|
+
Add this to models for which you want to be prompted when destroying it's instances:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
include Carefully
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
You might as well include it in your ActiveRecord::Base wrapper class (like ApplicationRecord) to have it for all models.
|
data/lib/carefully.rb
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
module Carefully
|
|
2
|
+
def self.included(base)
|
|
3
|
+
base.instance_eval do
|
|
4
|
+
def destroy_all
|
|
5
|
+
return super unless Carefully.configuration.enabled?
|
|
6
|
+
|
|
7
|
+
Carefully.confirm_destructive_action && super
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def delete_all
|
|
11
|
+
return super unless Carefully.configuration.enabled?
|
|
12
|
+
|
|
13
|
+
Carefully.confirm_destructive_action && super
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def delete(id)
|
|
17
|
+
puts 'HERE!'
|
|
18
|
+
return super unless Carefully.configuration.enabled?
|
|
19
|
+
|
|
20
|
+
Carefully.confirm_destructive_action && super
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class << self
|
|
26
|
+
attr_accessor :configuration
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.configure
|
|
30
|
+
self.configuration ||= Configuration.new
|
|
31
|
+
|
|
32
|
+
yield configuration if block_given?
|
|
33
|
+
|
|
34
|
+
configuration.set_enabled
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.confirm_destructive_action
|
|
38
|
+
puts Carefully.configuration.confirmation_message
|
|
39
|
+
print '> '
|
|
40
|
+
|
|
41
|
+
if gets.chomp == Carefully.configuration.confirmation_text
|
|
42
|
+
true
|
|
43
|
+
else
|
|
44
|
+
puts "\"#{caller_locations(1, 1)[0].label}\" aborted\n"
|
|
45
|
+
false
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def destroy
|
|
50
|
+
return super unless Carefully.configuration.enabled?
|
|
51
|
+
return super if caller_locations(1, 10).map(&:label).include? 'destroy_all'
|
|
52
|
+
|
|
53
|
+
Carefully.confirm_destructive_action && super
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def delete
|
|
57
|
+
return super unless Carefully.configuration.enabled?
|
|
58
|
+
|
|
59
|
+
Carefully.confirm_destructive_action && super
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
class Configuration
|
|
65
|
+
attr_accessor :protected_environments, :confirmation_message, :confirmation_text
|
|
66
|
+
|
|
67
|
+
def initialize
|
|
68
|
+
self.protected_environments = [:production, :demo, :staging]
|
|
69
|
+
self.confirmation_message = 'You are performing destructive actions in a protected environment. Do you want to continue?'
|
|
70
|
+
self.confirmation_text = 'yes'
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def set_enabled
|
|
74
|
+
@enabled = protected_environment? && rails_console?
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def enabled?
|
|
78
|
+
!!@enabled
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
private
|
|
82
|
+
|
|
83
|
+
def protected_environment?
|
|
84
|
+
protected_environments.map(&:to_s).include?(Rails.env)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def rails_console?
|
|
88
|
+
defined?(Rails::Console)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Carefully.configure do |config|
|
|
2
|
+
# an array of environments in which a confirmation is required to destroy objects
|
|
3
|
+
# config.protected_environments = [:production, :demo, :staging]
|
|
4
|
+
|
|
5
|
+
# confirmatino info message
|
|
6
|
+
# config.confirmation_message = 'You are performing destructive actions in a protected environment. Do you want to continue?'
|
|
7
|
+
|
|
8
|
+
# answer required to count the destroy as confirmed
|
|
9
|
+
# config.confirmation_text = 'yes'
|
|
10
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: carefully
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Pauls Liepa
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
description:
|
|
42
|
+
email:
|
|
43
|
+
- liepauls@gmail.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- LICENSE
|
|
49
|
+
- README.md
|
|
50
|
+
- lib/carefully.rb
|
|
51
|
+
- lib/carefully/version.rb
|
|
52
|
+
- lib/generators/carefully/carefully.rb
|
|
53
|
+
- lib/generators/carefully/carefully_generator.rb
|
|
54
|
+
homepage:
|
|
55
|
+
licenses:
|
|
56
|
+
- MIT
|
|
57
|
+
metadata: {}
|
|
58
|
+
post_install_message:
|
|
59
|
+
rdoc_options: []
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0'
|
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '0'
|
|
72
|
+
requirements: []
|
|
73
|
+
rubyforge_project:
|
|
74
|
+
rubygems_version: 2.6.14
|
|
75
|
+
signing_key:
|
|
76
|
+
specification_version: 4
|
|
77
|
+
summary: Ask for confirmation before destroying ActiveRecord::Base objects in specific
|
|
78
|
+
environments
|
|
79
|
+
test_files: []
|