safer_rails_console 0.8.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddf2baf69a61f2f36895b978b679d3a09b31fa4729ababd4d0dc05d367ee59e9
4
- data.tar.gz: 7238b5a777c0d58b3b97a9cd21c99e18dd781cae0c40e7e6694bb0c2d079afb5
3
+ metadata.gz: 7e01eee1304d4e5158bd4e8b8e2be33f5959a31ae76cd644dc59c317b6c93215
4
+ data.tar.gz: d2a649b163a108192a09217d4c304aec465fc889f40708fc61f40e6ecc6bbb9e
5
5
  SHA512:
6
- metadata.gz: 29dde7221f4bdca3da031c93037cf445432dcadbcc06515e76ef83ad5a3a5e52e6687b3c4571c154d2d61588fb4ea1401f0d3de23053ca535346c914497742a5
7
- data.tar.gz: 609e1dace181f8fde1542d01ef7899467587a4e7b38a457589e8b1db8383165f2e82a4d1d5aea08e2fa475e233a474037d3a8135281bc219aab081e5bb0e6555
6
+ metadata.gz: 8ee6fd8693d76f321dea94000557460ad5397ad7043d232b3f31faaadbb5a1feb89da29c212f2d9a49dd3bf2deab13c275c607818ccf7802bb39cd8abc13ef50
7
+ data.tar.gz: eeb1f37f6eee21057501de3607a6bc35bc6c9b9b19897eafcb30400caab1d827d10e2fc81eb79d6c7ace8a0dcf662116f74cd339da97a3a82779c00c95a9f33c
data/.circleci/config.yml CHANGED
@@ -2,14 +2,14 @@ version: 2.1
2
2
  jobs:
3
3
  lint:
4
4
  docker:
5
- - image: cimg/ruby:3.0.6
5
+ - image: cimg/ruby:3.1.5
6
6
  working_directory: ~/safer_rails_console
7
7
  steps:
8
8
  - checkout
9
9
  - restore_cache:
10
10
  keys:
11
- - v2-gems-ruby-3.0.6-{{ checksum "safer_rails_console.gemspec" }}-{{ checksum "Gemfile" }}
12
- - v2-gems-ruby-3.0.6-
11
+ - v2-gems-ruby-3.1.5-{{ checksum "safer_rails_console.gemspec" }}-{{ checksum "Gemfile" }}
12
+ - v2-gems-ruby-3.1.5-
13
13
  - run:
14
14
  name: Install Gems
15
15
  command: |
@@ -18,7 +18,7 @@ jobs:
18
18
  bundle clean
19
19
  fi
20
20
  - save_cache:
21
- key: v2-gems-ruby-3.0.6-{{ checksum "safer_rails_console.gemspec" }}-{{ checksum "Gemfile" }}
21
+ key: v2-gems-ruby-3.1.5-{{ checksum "safer_rails_console.gemspec" }}-{{ checksum "Gemfile" }}
22
22
  paths:
23
23
  - "vendor/bundle"
24
24
  - "gemfiles/vendor/bundle"
@@ -41,6 +41,11 @@ jobs:
41
41
  POSTGRES_USER: "circleci"
42
42
  POSTGRES_DB: "safer_rails_console_test"
43
43
  POSTGRES_HOST_AUTH_METHOD: "trust"
44
+ - image: cimg/mysql:8.0
45
+ environment:
46
+ MYSQL_DATABASE: "safer_rails_console_test"
47
+ MYSQL_ROOT_HOST: "%"
48
+ MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
44
49
  working_directory: ~/safer_rails_console
45
50
  steps:
46
51
  - checkout
@@ -60,6 +65,9 @@ jobs:
60
65
  paths:
61
66
  - "vendor/bundle"
62
67
  - "gemfiles/vendor/bundle"
68
+ - run:
69
+ name: Wait for Mysql
70
+ command: dockerize -wait tcp://localhost:3306 -timeout 1m
63
71
  - run:
64
72
  name: Run Tests
65
73
  command: |
@@ -74,7 +82,6 @@ workflows:
74
82
  matrix:
75
83
  parameters:
76
84
  ruby_version:
77
- - 3.0.6
78
85
  - 3.1.4
79
86
  - 3.2.2
80
87
  - 3.3.0
@@ -82,3 +89,4 @@ workflows:
82
89
  - gemfiles/6.1.gemfile
83
90
  - gemfiles/7.0.gemfile
84
91
  - gemfiles/7.1.gemfile
92
+ - gemfiles/7.2.gemfile
data/.gitignore CHANGED
@@ -15,3 +15,5 @@
15
15
  /gemfiles/*.gemfile.lock
16
16
  out
17
17
  *.sqlite3
18
+
19
+ .idea
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ inherit_gem:
2
2
  salsify_rubocop: conf/rubocop_rails.yml
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 3.0
5
+ TargetRubyVersion: 3.1
6
6
  Exclude:
7
7
  - 'vendor/**/*'
8
8
  - 'gemfiles/**/*'
data/Appraisals CHANGED
@@ -11,3 +11,7 @@ end
11
11
  appraise '7.1' do
12
12
  gem 'rails', '~> 7.1.2'
13
13
  end
14
+
15
+ appraise '7.2' do
16
+ gem 'rails', '~> 7.2.0'
17
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.10.0
4
+ - Drop support for Ruby 3.0.
5
+ - Add support for Rails 7.2. **Thanks [@kwent](https://github.com/kwent)**
6
+
7
+ ## v0.9.0
8
+ - Add MySql support
9
+
3
10
  ## v0.8.0
4
11
  - Drop support for Ruby 2.7.
5
12
  - Drop support for Rails 6.0.
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build Status](https://circleci.com/gh/salsify/safer_rails_console.svg?style=svg)](https://circleci.com/gh/salsify/safer_rails_console)
4
4
  [![Gem Version](https://badge.fury.io/rb/safer_rails_console.svg)](https://badge.fury.io/rb/safer_rails_console)
5
5
 
6
- This gem makes Rails console sessions less dangerous in specified environments by warning, color-coding, and auto-sandboxing PostgreSQL connections. In the future we'd like to extend this to make other external connections read-only too (e.g. disable job queueing, non-GET HTTP requests, etc.)
6
+ This gem makes Rails console sessions less dangerous in specified environments by warning, color-coding, and auto-sandboxing PostgreSQL and MySQL connections. In the future we'd like to extend this to make other external connections read-only too (e.g. disable job queueing, non-GET HTTP requests, etc.)
7
7
 
8
8
  ## Installation
9
9
 
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 7.2.0"
6
+
7
+ gemspec path: "../"
@@ -11,8 +11,8 @@ module SaferRailsConsole
11
11
  connection.begin_db_transaction
12
12
  end
13
13
 
14
- def self.handle_and_reraise_exception(error)
15
- if error.message.include?('PG::ReadOnlySqlTransaction')
14
+ def self.handle_and_reraise_exception(error, message = 'PG::ReadOnlySqlTransaction')
15
+ if error.message.include?(message)
16
16
  puts SaferRailsConsole::Colors.color_text( # rubocop:disable Rails/Output
17
17
  'An operation could not be completed due to read-only mode.',
18
18
  SaferRailsConsole::Colors::RED
@@ -28,13 +28,27 @@ module SaferRailsConsole
28
28
  def execute_and_clear(...)
29
29
  super
30
30
  rescue StandardError => e
31
- SaferRailsConsole::Patches::Sandbox::AutoRollback.handle_and_reraise_exception(e)
31
+ # rubocop:disable Layout/LineLength
32
+ SaferRailsConsole::Patches::Sandbox::AutoRollback.handle_and_reraise_exception(e, 'PG::ReadOnlySqlTransaction')
33
+ # rubocop:enable Layout/LineLength
32
34
  end
33
35
  end
34
36
 
35
37
  if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
36
38
  ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(PostgreSQLAdapterPatch)
37
39
  end
40
+
41
+ module MySQLPatch
42
+ def execute_and_free(...)
43
+ super
44
+ rescue StandardError => e
45
+ SaferRailsConsole::Patches::Sandbox::AutoRollback.handle_and_reraise_exception(e, 'READ ONLY transaction')
46
+ end
47
+ end
48
+
49
+ if defined?(::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter)
50
+ ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(MySQLPatch)
51
+ end
38
52
  end
39
53
  end
40
54
  end
@@ -11,6 +11,13 @@ module SaferRailsConsole
11
11
  end
12
12
  end
13
13
 
14
+ module MySQLPatch
15
+ def begin_db_transaction
16
+ execute 'SET TRANSACTION READ ONLY'
17
+ super
18
+ end
19
+ end
20
+
14
21
  if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
15
22
  ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(PostgreSQLAdapterPatch)
16
23
 
@@ -18,6 +25,13 @@ module SaferRailsConsole
18
25
  connection = ::ActiveRecord::Base.connection
19
26
  connection.execute 'SET TRANSACTION READ ONLY' if connection.open_transactions > 0
20
27
  end
28
+
29
+ if defined?(::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter)
30
+ ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(MySQLPatch)
31
+
32
+ # Not possible to change a running transaction to read-only in MySQL
33
+ # https://dev.mysql.com/doc/refman/8.4/en/set-transaction.html
34
+ end
21
35
  end
22
36
  end
23
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SaferRailsConsole
4
- VERSION = '0.8.0'
4
+ VERSION = '0.10.0'
5
5
  end
@@ -33,12 +33,13 @@ Gem::Specification.new do |spec|
33
33
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
34
  spec.require_paths = ['lib']
35
35
 
36
- spec.required_ruby_version = '>= 3.0'
36
+ spec.required_ruby_version = '>= 3.1'
37
37
 
38
38
  spec.add_development_dependency 'appraisal', '~> 2.2'
39
39
  spec.add_development_dependency 'bundler', '~> 2.0'
40
40
  spec.add_development_dependency 'climate_control', '~> 0.2.0'
41
41
  spec.add_development_dependency 'mixlib-shellout', '~> 2.2'
42
+ spec.add_development_dependency 'mysql2', '~> 0.5'
42
43
  spec.add_development_dependency 'overcommit', '~> 0.39.0'
43
44
  spec.add_development_dependency 'pg', '~> 1.1'
44
45
  spec.add_development_dependency 'rake', '~> 12.0'
@@ -46,5 +47,5 @@ Gem::Specification.new do |spec|
46
47
  spec.add_development_dependency 'rspec_junit_formatter'
47
48
  spec.add_development_dependency 'salsify_rubocop', '~> 1.27.0'
48
49
 
49
- spec.add_runtime_dependency 'rails', '>= 6.1', '< 7.2'
50
+ spec.add_runtime_dependency 'rails', '>= 6.1', '< 7.3'
50
51
  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.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salsify, Inc
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-05 00:00:00.000000000 Z
11
+ date: 2024-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mysql2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.5'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: overcommit
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +173,7 @@ dependencies:
159
173
  version: '6.1'
160
174
  - - "<"
161
175
  - !ruby/object:Gem::Version
162
- version: '7.2'
176
+ version: '7.3'
163
177
  type: :runtime
164
178
  prerelease: false
165
179
  version_requirements: !ruby/object:Gem::Requirement
@@ -169,7 +183,7 @@ dependencies:
169
183
  version: '6.1'
170
184
  - - "<"
171
185
  - !ruby/object:Gem::Version
172
- version: '7.2'
186
+ version: '7.3'
173
187
  description: This gem makes Rails console sessions less dangerous in specified environments
174
188
  by warning, color-coding, auto-sandboxing, and allowing read-only external connections
175
189
  (disables job queueing, non-GET requests, etc.)
@@ -196,6 +210,7 @@ files:
196
210
  - gemfiles/6.1.gemfile
197
211
  - gemfiles/7.0.gemfile
198
212
  - gemfiles/7.1.gemfile
213
+ - gemfiles/7.2.gemfile
199
214
  - lib/safer_rails_console.rb
200
215
  - lib/safer_rails_console/colors.rb
201
216
  - lib/safer_rails_console/console.rb
@@ -225,7 +240,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
240
  requirements:
226
241
  - - ">="
227
242
  - !ruby/object:Gem::Version
228
- version: '3.0'
243
+ version: '3.1'
229
244
  required_rubygems_version: !ruby/object:Gem::Requirement
230
245
  requirements:
231
246
  - - ">="