safer_rails_console 0.1.3 → 0.4.1
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 +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +12 -9
- data/Appraisals +8 -8
- data/CHANGELOG.md +47 -1
- data/README.md +22 -1
- data/gemfiles/{4.1.gemfile → 5.2.gemfile} +1 -1
- data/gemfiles/{4.2.gemfile → 6.0.gemfile} +1 -1
- data/lib/safer_rails_console.rb +29 -4
- data/lib/safer_rails_console/console.rb +1 -1
- data/lib/safer_rails_console/consoles/irb.rb +6 -2
- data/lib/safer_rails_console/patches/boot/sandbox_flag.rb +16 -46
- data/lib/safer_rails_console/patches/railtie/sandbox.rb +10 -3
- data/lib/safer_rails_console/patches/sandbox/auto_rollback.rb +25 -8
- data/lib/safer_rails_console/patches/sandbox/transaction_read_only.rb +26 -0
- data/lib/safer_rails_console/rails_version.rb +21 -11
- data/lib/safer_rails_console/version.rb +1 -1
- data/safer_rails_console.gemspec +4 -3
- metadata +41 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa38df80bc34ac51afa200a586bfefe0795b2dd69057b0ca1bc03c71ac15d133
|
4
|
+
data.tar.gz: 2ca8d07ece23d035ac20f7a4efa6506e44a573642336dd63b3918c12cef9ca87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2384f5f7e310411ed41d8d9448201fb4d6d408e5c558089848d38e7532d540e6aa3bd81c31f4c6df78cb4e651cba2b1a07bce91a6e26d6b9da60e0133fee76c
|
7
|
+
data.tar.gz: '019e4acd21560cf9f6f4f0c88f919aa2319655c3ce96463717e4352ab8d0e52434984e2f57e630b384c11136e0aecf86374417191b1799aee91e2ab8f25827cb'
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,28 +1,31 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
|
4
|
+
services:
|
5
|
+
- postgresql
|
6
|
+
|
4
7
|
bundler_args: --without test --jobs 3 --retry 3
|
5
8
|
before_install:
|
6
9
|
- gem install bundler
|
7
10
|
|
11
|
+
before_script:
|
12
|
+
- cp spec/internal/database.yml.travis spec/internal/rails_5_0/config/database.yml
|
13
|
+
- cp spec/internal/database.yml.travis spec/internal/rails_5_1/config/database.yml
|
14
|
+
- cp spec/internal/database.yml.travis spec/internal/rails_5_2/config/database.yml
|
15
|
+
- cp spec/internal/database.yml.travis spec/internal/rails_6_0/config/database.yml
|
16
|
+
|
8
17
|
script:
|
9
18
|
- bundle exec rubocop
|
10
19
|
- bundle exec rspec
|
11
20
|
|
12
21
|
rvm:
|
13
|
-
- 2.
|
14
|
-
- 2.3.4
|
15
|
-
- 2.4.1
|
22
|
+
- 2.5.6
|
16
23
|
|
17
24
|
gemfile:
|
18
|
-
- gemfiles/4.1.gemfile
|
19
|
-
- gemfiles/4.2.gemfile
|
20
25
|
- gemfiles/5.0.gemfile
|
21
26
|
- gemfiles/5.1.gemfile
|
27
|
+
- gemfiles/5.2.gemfile
|
28
|
+
- gemfiles/6.0.gemfile
|
22
29
|
|
23
30
|
matrix:
|
24
|
-
allow_failures:
|
25
|
-
- gemfile: gemfiles/4.1.gemfile
|
26
|
-
rvm: 2.4.1
|
27
|
-
|
28
31
|
fast_finish: true
|
data/Appraisals
CHANGED
@@ -1,11 +1,3 @@
|
|
1
|
-
appraise '4.1' do
|
2
|
-
gem 'rails', '~> 4.1.0'
|
3
|
-
end
|
4
|
-
|
5
|
-
appraise '4.2' do
|
6
|
-
gem 'rails', '~> 4.2.0'
|
7
|
-
end
|
8
|
-
|
9
1
|
appraise '5.0' do
|
10
2
|
gem 'rails', '~> 5.0.0'
|
11
3
|
end
|
@@ -13,3 +5,11 @@ end
|
|
13
5
|
appraise '5.1' do
|
14
6
|
gem 'rails', '~> 5.1.0'
|
15
7
|
end
|
8
|
+
|
9
|
+
appraise '5.2' do
|
10
|
+
gem 'rails', '~> 5.2.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise '6.0' do
|
14
|
+
gem 'rails', '~> 6.0.0'
|
15
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,51 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v0.4.0](https://github.com/salsify/safer_rails_console/tree/v0.4.0) (2019-09-19)
|
4
|
+
[Full Changelog](https://github.com/salsify/safer_rails_console/compare/v0.3.0...v0.4.0)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- safer\_rails\_console breaks newrelic reporting [\#23](https://github.com/salsify/safer_rails_console/issues/23)
|
9
|
+
|
10
|
+
**Merged pull requests:**
|
11
|
+
|
12
|
+
- Use Postgres for local development too [\#28](https://github.com/salsify/safer_rails_console/pull/28) ([jturkel](https://github.com/jturkel))
|
13
|
+
- Rails 6.0 support [\#26](https://github.com/salsify/safer_rails_console/pull/27) ([jturkel](https://github.com/jturkel))
|
14
|
+
- Drop Rails 4.2 support [\#26](https://github.com/salsify/safer_rails_console/pull/26) ([jturkel](https://github.com/jturkel))
|
15
|
+
|
16
|
+
## [v0.3.0](https://github.com/salsify/safer_rails_console/tree/v0.3.0) (2018-04-16)
|
17
|
+
[Full Changelog](https://github.com/salsify/safer_rails_console/compare/v0.2.0...v0.3.0)
|
18
|
+
|
19
|
+
**Merged pull requests:**
|
20
|
+
|
21
|
+
- Add support for Rails 5.2; remove support for Rails 4.1 [\#24](https://github.com/salsify/safer_rails_console/pull/24) ([timothysu](https://github.com/timothysu))
|
22
|
+
|
23
|
+
## [v0.2.0](https://github.com/salsify/safer_rails_console/tree/v0.2.0) (2017-09-07)
|
24
|
+
[Full Changelog](https://github.com/salsify/safer_rails_console/compare/v0.1.4...v0.2.0)
|
25
|
+
|
26
|
+
**Implemented enhancements:**
|
27
|
+
|
28
|
+
- Sandbox mode should make it clear that edits don't stick [\#19](https://github.com/salsify/safer_rails_console/issues/19)
|
29
|
+
- Writes made in sandbox mode take out DB locks [\#18](https://github.com/salsify/safer_rails_console/issues/18)
|
30
|
+
- Confusion over unsandboxed/sandboxed terminology in command prompt [\#17](https://github.com/salsify/safer_rails_console/issues/17)
|
31
|
+
|
32
|
+
**Merged pull requests:**
|
33
|
+
|
34
|
+
- Set DB transactions to read-only and provide messaging for non-read operations [\#21](https://github.com/salsify/safer_rails_console/pull/21) ([timothysu](https://github.com/timothysu))
|
35
|
+
- Change 'sandboxed' and 'unsandboxed' to 'read-only' and 'writable' and add respective flags [\#20](https://github.com/salsify/safer_rails_console/pull/20) ([timothysu](https://github.com/timothysu))
|
36
|
+
|
37
|
+
## [v0.1.4](https://github.com/salsify/safer_rails_console/tree/v0.1.4) (2017-08-15)
|
38
|
+
[Full Changelog](https://github.com/salsify/safer_rails_console/compare/v0.1.3...v0.1.4)
|
39
|
+
|
40
|
+
**Fixed bugs:**
|
41
|
+
|
42
|
+
- Invalid cached and prepared statements do not trigger a automatic rollback with PostgreSQL [\#16](https://github.com/salsify/safer_rails_console/issues/16)
|
43
|
+
- safer\_rails\_console doesn't work in alerts service rails console mode in sandbox mode [\#13](https://github.com/salsify/safer_rails_console/issues/13)
|
44
|
+
|
45
|
+
**Merged pull requests:**
|
46
|
+
|
47
|
+
- Patch PostgreSQLAdapter\#execute\_and\_clear instead of AbstractAdapter\#log for auto-rollback [\#15](https://github.com/salsify/safer_rails_console/pull/15) ([timothysu](https://github.com/timothysu))
|
48
|
+
|
3
49
|
## [v0.1.3](https://github.com/salsify/safer_rails_console/tree/v0.1.3) (2017-08-02)
|
4
50
|
[Full Changelog](https://github.com/salsify/safer_rails_console/compare/v0.1.2...v0.1.3)
|
5
51
|
|
@@ -37,4 +83,4 @@
|
|
37
83
|
|
38
84
|
|
39
85
|
|
40
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
86
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/README.md
CHANGED
@@ -27,11 +27,14 @@ require 'safer_rails_console/patches/boot'
|
|
27
27
|
|
28
28
|
The quickest way to demo this gem is to run `bundle exec rails console --sandbox`.
|
29
29
|
|
30
|
-
|
30
|
+
Several ways to explicitly enable or disable the sandbox are added to Rails console as flags with the last install step. The order of precedence is `-s`, `-r`, then `-w` if multiple sandbox related flags are specified.
|
31
31
|
```ruby
|
32
32
|
bundle exec rails console --help
|
33
33
|
|
34
|
+
Usage: rails console [environment] [options]
|
34
35
|
-s, --[no-]sandbox Explicitly enable/disable sandbox mode.
|
36
|
+
-w, --writable Alias for --no-sandbox.
|
37
|
+
-r, --read-only Alias for --sandbox.
|
35
38
|
-e, --environment=name Specifies the environment to run this console under (test/development/production).
|
36
39
|
Default: development
|
37
40
|
--debugger Enable the debugger.
|
@@ -70,6 +73,24 @@ config.safer_rails_console.warn_text = "WARNING: YOU ARE USING RAILS CONSOLE IN
|
|
70
73
|
'Make sure you know what you\'re doing.'
|
71
74
|
```
|
72
75
|
|
76
|
+
configuration settings can also be overridden using ENV variables. The following ENV vars can be used:
|
77
|
+
```
|
78
|
+
# Set the color prompt to a new color. See colors.rb for a listing of supported colors.
|
79
|
+
SAFER_RAILS_CONSOLE_PROMPT_COLOR=red/yellow/green
|
80
|
+
|
81
|
+
# Set the short name for the rails console prompt
|
82
|
+
SAFER_RAILS_CONSOLE_ENVIRONMENT_NAME=short-name
|
83
|
+
|
84
|
+
# Set the warning text to be displayed when warning for the environments rails consoled is enabled
|
85
|
+
SAFER_RAILS_CONSOLE_WARN_TEXT=New warning prompt text
|
86
|
+
|
87
|
+
# Enable or disable sandboxing of the rails console
|
88
|
+
SAFER_RAILS_CONSOLE_SANDBOX_ENVIRONMENT=true/false
|
89
|
+
|
90
|
+
# Enable or disable warning prompt of the rails console
|
91
|
+
SAFER_RAILS_CONSOLE_WARN_ENVIRONMENT=true/false
|
92
|
+
```
|
93
|
+
|
73
94
|
## Development
|
74
95
|
|
75
96
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `wwtd` to simulate the entire build matrix (ruby version / rails version) or `appraisal` to test against each supported rails version with your active ruby version. Run `rubocop` to check for style.
|
data/lib/safer_rails_console.rb
CHANGED
@@ -3,23 +3,48 @@ require 'safer_rails_console/railtie'
|
|
3
3
|
require 'safer_rails_console/colors'
|
4
4
|
require 'safer_rails_console/rails_version'
|
5
5
|
require 'safer_rails_console/console'
|
6
|
+
require 'active_model/type'
|
6
7
|
|
7
8
|
module SaferRailsConsole
|
8
9
|
class << self
|
9
10
|
def environment_name
|
10
|
-
|
11
|
+
if ENV.key?('SAFER_RAILS_CONSOLE_ENVIRONMENT_NAME')
|
12
|
+
ENV['SAFER_RAILS_CONSOLE_ENVIRONMENT_NAME']
|
13
|
+
else
|
14
|
+
config.environment_names.key?(::Rails.env.downcase) ? config.environment_names[::Rails.env.downcase] : 'unknown env'
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
def prompt_color
|
14
|
-
|
19
|
+
if ENV.key?('SAFER_RAILS_CONSOLE_PROMPT_COLOR')
|
20
|
+
SaferRailsConsole::Colors.const_get(ENV['SAFER_RAILS_CONSOLE_PROMPT_COLOR'].upcase)
|
21
|
+
else
|
22
|
+
config.environment_prompt_colors.key?(::Rails.env.downcase) ? config.environment_prompt_colors[::Rails.env.downcase] : SaferRailsConsole::Colors::NONE
|
23
|
+
end
|
15
24
|
end
|
16
25
|
|
17
26
|
def sandbox_environment?
|
18
|
-
|
27
|
+
if ENV.key?('SAFER_RAILS_CONSOLE_SANDBOX_ENVIRONMENT')
|
28
|
+
ActiveModel::Type::Boolean.new.cast(ENV['SAFER_RAILS_CONSOLE_SANDBOX_ENVIRONMENT'])
|
29
|
+
else
|
30
|
+
config.sandbox_environments.include?(::Rails.env.downcase)
|
31
|
+
end
|
19
32
|
end
|
20
33
|
|
21
34
|
def warn_environment?
|
22
|
-
|
35
|
+
if ENV.key?('SAFER_RAILS_CONSOLE_WARN_ENVIRONMENT')
|
36
|
+
ActiveModel::Type::Boolean.new.cast(ENV['SAFER_RAILS_CONSOLE_WARN_ENVIRONMENT'])
|
37
|
+
else
|
38
|
+
config.warn_environments.include?(::Rails.env.downcase)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def warn_text
|
43
|
+
if ENV.key?('SAFER_RAILS_CONSOLE_WARN_TEXT')
|
44
|
+
ENV['SAFER_RAILS_CONSOLE_WARN_TEXT']
|
45
|
+
else
|
46
|
+
config.warn_text
|
47
|
+
end
|
23
48
|
end
|
24
49
|
|
25
50
|
def config
|
@@ -8,7 +8,7 @@ module SaferRailsConsole
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def print_warning
|
11
|
-
puts color_text(SaferRailsConsole.
|
11
|
+
puts color_text(SaferRailsConsole.warn_text, SaferRailsConsole.prompt_color) # rubocop:disable Rails/Output
|
12
12
|
end
|
13
13
|
|
14
14
|
def load_config
|
@@ -1,8 +1,12 @@
|
|
1
1
|
include SaferRailsConsole::Colors
|
2
2
|
|
3
|
-
app_name = ::
|
3
|
+
app_name = if SaferRailsConsole::RailsVersion.six_or_above?
|
4
|
+
::Rails.application.class.module_parent.to_s.underscore.dasherize
|
5
|
+
else
|
6
|
+
::Rails.application.class.parent.to_s.underscore.dasherize
|
7
|
+
end
|
4
8
|
env_name = SaferRailsConsole.environment_name
|
5
|
-
status = ::Rails.application.sandbox ? '
|
9
|
+
status = ::Rails.application.sandbox ? 'read-only' : 'writable'
|
6
10
|
color = SaferRailsConsole.prompt_color
|
7
11
|
|
8
12
|
prompt = "#{app_name}(#{env_name})(#{status}):%03n:%i"
|
@@ -4,42 +4,17 @@ module SaferRailsConsole
|
|
4
4
|
module Patches
|
5
5
|
module Boot
|
6
6
|
module SandboxFlag
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
module Console4
|
17
|
-
def parse_arguments(arguments)
|
18
|
-
options = {}
|
19
|
-
|
20
|
-
OptionParser.new do |opt|
|
21
|
-
opt.banner = 'Usage: rails console [environment] [options]'
|
22
|
-
opt.on('-s', '--[no-]sandbox', 'Explicitly enable/disable sandbox mode.') { |v| options[:sandbox] = v }
|
23
|
-
opt.on('-e', '--environment=name', String,
|
24
|
-
'Specifies the environment to run this console under (test/development/production).',
|
25
|
-
'Default: development') { |v| options[:environment] = v.strip }
|
26
|
-
opt.on('--debugger', 'Enable the debugger.') { |v| options[:debugger] = v }
|
27
|
-
opt.parse!(arguments)
|
28
|
-
end
|
29
|
-
|
30
|
-
if arguments.first && arguments.first[0] != '-'
|
31
|
-
env = arguments.first
|
32
|
-
options[:environment] = if available_environments.include? env
|
33
|
-
env
|
34
|
-
else
|
35
|
-
%w(production development test).detect { |e| e =~ /^#{env}/ } || env
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
options
|
40
|
-
end
|
41
|
-
end
|
7
|
+
def self.console_options(opt, options = {})
|
8
|
+
opt.banner = 'Usage: rails console [environment] [options]'
|
9
|
+
opt.on('-s', '--[no-]sandbox', 'Explicitly enable/disable sandbox mode.') { |v| options[:sandbox] = v }
|
10
|
+
opt.on('-w', '--writable', 'Alias for --no-sandbox.') { |v| options[:writable] = v }
|
11
|
+
opt.on('-r', '--read-only', 'Alias for --sandbox.') { |v| options[:'read-only'] = v }
|
12
|
+
opt.on('-e', '--environment=name', String,
|
13
|
+
'Specifies the environment to run this console under (test/development/production).',
|
14
|
+
'Default: development') { |v| options[:environment] = v.strip }
|
15
|
+
end
|
42
16
|
|
17
|
+
module Rails
|
43
18
|
module CommandsTasks50
|
44
19
|
def console
|
45
20
|
require_command!('console')
|
@@ -53,11 +28,7 @@ module SaferRailsConsole
|
|
53
28
|
options = {}
|
54
29
|
|
55
30
|
OptionParser.new do |opt|
|
56
|
-
opt
|
57
|
-
opt.on('-s', '--[no-]sandbox', 'Explicitly enable/disable sandbox mode.') { |v| options[:sandbox] = v }
|
58
|
-
opt.on('-e', '--environment=name', String,
|
59
|
-
'Specifies the environment to run this console under (test/development/production).',
|
60
|
-
'Default: development') { |v| options[:environment] = v.strip }
|
31
|
+
::SaferRailsConsole::Patches::Boot::SandboxFlag.console_options(opt, options)
|
61
32
|
opt.parse!(arguments)
|
62
33
|
end
|
63
34
|
|
@@ -70,19 +41,18 @@ module SaferRailsConsole
|
|
70
41
|
end
|
71
42
|
end
|
72
43
|
|
73
|
-
if SaferRailsConsole::RailsVersion.
|
74
|
-
require 'rails/commands/commands_tasks'
|
75
|
-
::Rails::CommandsTasks.prepend(SaferRailsConsole::Patches::Boot::SandboxFlag::Rails::CommandsTasks4)
|
76
|
-
elsif SaferRailsConsole::RailsVersion.five_zero?
|
44
|
+
if SaferRailsConsole::RailsVersion.five_zero?
|
77
45
|
require 'rails/commands/commands_tasks'
|
78
46
|
::Rails::CommandsTasks.prepend(SaferRailsConsole::Patches::Boot::SandboxFlag::Rails::CommandsTasks50)
|
79
|
-
elsif SaferRailsConsole::RailsVersion.
|
47
|
+
elsif SaferRailsConsole::RailsVersion.five_one_or_above?
|
80
48
|
require 'rails/command'
|
81
49
|
require 'rails/commands/console/console_command'
|
82
|
-
# Rails 5.1 defaults `sandbox` to `false`, but we need it to NOT have a default value and be `nil` when it is not user-specified
|
50
|
+
# Rails 5.1 and 5.2 defaults `sandbox` to `false`, but we need it to NOT have a default value and be `nil` when it is not user-specified
|
83
51
|
::Rails::Command::ConsoleCommand.class_eval do
|
84
52
|
remove_class_option :sandbox
|
85
53
|
class_option :sandbox, aliases: '-s', type: :boolean, desc: 'Explicitly enable/disable sandbox mode.'
|
54
|
+
class_option :writable, aliases: '-w', type: :boolean, desc: 'Alias for --no-sandbox.'
|
55
|
+
class_option :'read-only', aliases: '-r', type: :boolean, desc: 'Alias for --sandbox.'
|
86
56
|
end
|
87
57
|
else
|
88
58
|
unless SaferRailsConsole::RailsVersion.supported?
|
@@ -6,8 +6,15 @@ module SaferRailsConsole
|
|
6
6
|
def start(*args)
|
7
7
|
options = args.last
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
if options[:sandbox].nil?
|
10
|
+
options[:sandbox] = if options[:'read-only']
|
11
|
+
true
|
12
|
+
elsif options[:writable]
|
13
|
+
false
|
14
|
+
else
|
15
|
+
SaferRailsConsole.sandbox_environment? && SaferRailsConsole.config.sandbox_prompt ? SaferRailsConsole::Console.sandbox_user_prompt : SaferRailsConsole.sandbox_environment?
|
16
|
+
end
|
17
|
+
end
|
11
18
|
|
12
19
|
super *args
|
13
20
|
end
|
@@ -18,7 +25,7 @@ module SaferRailsConsole
|
|
18
25
|
end
|
19
26
|
|
20
27
|
if SaferRailsConsole::RailsVersion.supported?
|
21
|
-
if SaferRailsConsole::RailsVersion.
|
28
|
+
if SaferRailsConsole::RailsVersion.five_one_or_above?
|
22
29
|
require 'rails/commands/console/console_command'
|
23
30
|
else
|
24
31
|
require 'rails/commands/console'
|
@@ -2,16 +2,31 @@ module SaferRailsConsole
|
|
2
2
|
module Patches
|
3
3
|
module Sandbox
|
4
4
|
module AutoRollback
|
5
|
+
extend SaferRailsConsole::Colors
|
6
|
+
|
7
|
+
def self.rollback_and_begin_new_transaction
|
8
|
+
connection = ::ActiveRecord::Base.connection
|
9
|
+
connection.rollback_db_transaction
|
10
|
+
connection.begin_db_transaction
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.handle_and_reraise_exception(e)
|
14
|
+
if e.message.include?('PG::ReadOnlySqlTransaction')
|
15
|
+
puts color_text('An operation could not be completed due to read-only mode.', RED) # rubocop:disable Rails/Output
|
16
|
+
else
|
17
|
+
rollback_and_begin_new_transaction
|
18
|
+
end
|
19
|
+
|
20
|
+
raise e
|
21
|
+
end
|
22
|
+
|
5
23
|
module ActiveRecord
|
6
24
|
module ConnectionAdapters
|
7
|
-
module
|
8
|
-
def
|
9
|
-
super
|
25
|
+
module PostgreSQLAdapter5
|
26
|
+
def execute_and_clear(sql, name, binds, prepare: false)
|
27
|
+
super
|
10
28
|
rescue => e
|
11
|
-
|
12
|
-
connection.rollback_db_transaction
|
13
|
-
connection.begin_db_transaction
|
14
|
-
raise e
|
29
|
+
SaferRailsConsole::Patches::Sandbox::AutoRollback.handle_and_reraise_exception(e)
|
15
30
|
end
|
16
31
|
end
|
17
32
|
end
|
@@ -21,4 +36,6 @@ module SaferRailsConsole
|
|
21
36
|
end
|
22
37
|
end
|
23
38
|
|
24
|
-
|
39
|
+
if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
40
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(SaferRailsConsole::Patches::Sandbox::AutoRollback::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter5)
|
41
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SaferRailsConsole
|
2
|
+
module Patches
|
3
|
+
module Sandbox
|
4
|
+
module TransactionReadOnly
|
5
|
+
module ActiveRecord
|
6
|
+
module ConnectionAdapters
|
7
|
+
module PostgreSQLAdapter
|
8
|
+
def begin_db_transaction
|
9
|
+
super
|
10
|
+
execute 'SET TRANSACTION READ ONLY'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
21
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(SaferRailsConsole::Patches::Sandbox::TransactionReadOnly::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
22
|
+
|
23
|
+
# Ensure transaction is read-only if it was began before this patch was loaded
|
24
|
+
connection = ::ActiveRecord::Base.connection
|
25
|
+
connection.execute 'SET TRANSACTION READ ONLY' if connection.open_transactions > 0
|
26
|
+
end
|
@@ -6,17 +6,7 @@ module SaferRailsConsole
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def supported?
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def four_one?
|
13
|
-
@is_four_one = Gem::Requirement.new('~> 4.1.0').satisfied_by?(SaferRailsConsole::RailsVersion::RAILS_VERSION) if @is_four_one.nil?
|
14
|
-
@is_four_one
|
15
|
-
end
|
16
|
-
|
17
|
-
def four_two?
|
18
|
-
@is_four_two = Gem::Requirement.new('~> 4.2.0').satisfied_by?(SaferRailsConsole::RailsVersion::RAILS_VERSION) if @is_four_two.nil?
|
19
|
-
@is_four_two
|
9
|
+
five_zero? || five_one? || five_two? || six_zero?
|
20
10
|
end
|
21
11
|
|
22
12
|
def five_zero?
|
@@ -28,6 +18,26 @@ module SaferRailsConsole
|
|
28
18
|
@is_five_one = Gem::Requirement.new('~> 5.1.0').satisfied_by?(SaferRailsConsole::RailsVersion::RAILS_VERSION) if @is_five_one.nil?
|
29
19
|
@is_five_one
|
30
20
|
end
|
21
|
+
|
22
|
+
def five_one_or_above?
|
23
|
+
@is_five_one_or_above = SaferRailsConsole::RailsVersion::RAILS_VERSION >= ::Gem::Version.new('5.1.0') if @is_five_one_or_above.nil?
|
24
|
+
@is_five_one_or_above
|
25
|
+
end
|
26
|
+
|
27
|
+
def five_two?
|
28
|
+
@is_five_two = Gem::Requirement.new('~> 5.2.0').satisfied_by?(SaferRailsConsole::RailsVersion::RAILS_VERSION) if @is_five_two.nil?
|
29
|
+
@is_five_two
|
30
|
+
end
|
31
|
+
|
32
|
+
def six_zero?
|
33
|
+
@is_six_zero = Gem::Requirement.new('~> 6.0.0').satisfied_by?(SaferRailsConsole::RailsVersion::RAILS_VERSION) if @is_six_zero.nil?
|
34
|
+
@is_six_zero
|
35
|
+
end
|
36
|
+
|
37
|
+
def six_or_above?
|
38
|
+
@is_six_or_above = SaferRailsConsole::RailsVersion::RAILS_VERSION >= ::Gem::Version.new('6.0.0') if @is_six_or_above.nil?
|
39
|
+
@is_six_or_above
|
40
|
+
end
|
31
41
|
end
|
32
42
|
end
|
33
43
|
end
|
data/safer_rails_console.gemspec
CHANGED
@@ -31,13 +31,14 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.require_paths = ['lib']
|
32
32
|
|
33
33
|
spec.add_development_dependency 'appraisal', '~> 2.2'
|
34
|
-
spec.add_development_dependency 'bundler', '~>
|
34
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
35
|
+
spec.add_development_dependency 'climate_control', '~> 0.2.0'
|
35
36
|
spec.add_development_dependency 'mixlib-shellout', '~> 2.2'
|
36
37
|
spec.add_development_dependency 'overcommit', '~> 0.39.0'
|
38
|
+
spec.add_development_dependency 'pg', '~> 1.1'
|
37
39
|
spec.add_development_dependency 'rake', '~> 12.0'
|
38
40
|
spec.add_development_dependency 'rspec', '~> 3.6'
|
39
41
|
spec.add_development_dependency 'salsify_rubocop', '~> 0.48.0'
|
40
|
-
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
41
42
|
spec.add_development_dependency 'wwtd', '~> 1.3'
|
42
|
-
spec.add_runtime_dependency 'rails', '>=
|
43
|
+
spec.add_runtime_dependency 'rails', '>= 5.0', '< 6.1'
|
43
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safer_rails_console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salsify, Inc
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -30,14 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: climate_control
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: mixlib-shellout
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,61 +81,61 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: 0.39.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: pg
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
89
|
+
version: '1.1'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
96
|
+
version: '1.1'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: rake
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
103
|
+
version: '12.0'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
110
|
+
version: '12.0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: rspec
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
117
|
+
version: '3.6'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
124
|
+
version: '3.6'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
126
|
+
name: salsify_rubocop
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
131
|
+
version: 0.48.0
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
138
|
+
version: 0.48.0
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: wwtd
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,20 +156,20 @@ dependencies:
|
|
142
156
|
requirements:
|
143
157
|
- - ">="
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
159
|
+
version: '5.0'
|
146
160
|
- - "<"
|
147
161
|
- !ruby/object:Gem::Version
|
148
|
-
version: '
|
162
|
+
version: '6.1'
|
149
163
|
type: :runtime
|
150
164
|
prerelease: false
|
151
165
|
version_requirements: !ruby/object:Gem::Requirement
|
152
166
|
requirements:
|
153
167
|
- - ">="
|
154
168
|
- !ruby/object:Gem::Version
|
155
|
-
version: '
|
169
|
+
version: '5.0'
|
156
170
|
- - "<"
|
157
171
|
- !ruby/object:Gem::Version
|
158
|
-
version: '
|
172
|
+
version: '6.1'
|
159
173
|
description: This gem makes Rails console sessions less dangerous in specified environments
|
160
174
|
by warning, color-coding, auto-sandboxing, and allowing read-only external connections
|
161
175
|
(disables job queueing, non-GET requests, etc.)
|
@@ -178,10 +192,10 @@ files:
|
|
178
192
|
- Rakefile
|
179
193
|
- bin/console
|
180
194
|
- bin/setup
|
181
|
-
- gemfiles/4.1.gemfile
|
182
|
-
- gemfiles/4.2.gemfile
|
183
195
|
- gemfiles/5.0.gemfile
|
184
196
|
- gemfiles/5.1.gemfile
|
197
|
+
- gemfiles/5.2.gemfile
|
198
|
+
- gemfiles/6.0.gemfile
|
185
199
|
- lib/safer_rails_console.rb
|
186
200
|
- lib/safer_rails_console/colors.rb
|
187
201
|
- lib/safer_rails_console/console.rb
|
@@ -192,6 +206,7 @@ files:
|
|
192
206
|
- lib/safer_rails_console/patches/railtie/sandbox.rb
|
193
207
|
- lib/safer_rails_console/patches/sandbox.rb
|
194
208
|
- lib/safer_rails_console/patches/sandbox/auto_rollback.rb
|
209
|
+
- lib/safer_rails_console/patches/sandbox/transaction_read_only.rb
|
195
210
|
- lib/safer_rails_console/rails_version.rb
|
196
211
|
- lib/safer_rails_console/railtie.rb
|
197
212
|
- lib/safer_rails_console/version.rb
|
@@ -201,7 +216,7 @@ licenses:
|
|
201
216
|
- MIT
|
202
217
|
metadata:
|
203
218
|
allowed_push_host: https://rubygems.org
|
204
|
-
post_install_message:
|
219
|
+
post_install_message:
|
205
220
|
rdoc_options: []
|
206
221
|
require_paths:
|
207
222
|
- lib
|
@@ -216,9 +231,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
231
|
- !ruby/object:Gem::Version
|
217
232
|
version: '0'
|
218
233
|
requirements: []
|
219
|
-
|
220
|
-
|
221
|
-
signing_key:
|
234
|
+
rubygems_version: 3.1.2
|
235
|
+
signing_key:
|
222
236
|
specification_version: 4
|
223
237
|
summary: Make rails console less dangerous!
|
224
238
|
test_files: []
|