semian 0.21.0 → 0.21.2

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: 81f8b86816bb4e9de0850867f80de644ff8ce7f7fcfa6798d28ad772a83ea25f
4
- data.tar.gz: 153aa759abfa028a208893c328aa525d514caa6901cf2fa9ad6b4f0e86987b63
3
+ metadata.gz: f07497a8f77d5309e042951ac2c15d6a8e420abcafea896890a103e78fe05118
4
+ data.tar.gz: bfbd847f058a7bd3b7a947f3f610037fb4aa5e83fa9bfcc62c45ffee9a65c84e
5
5
  SHA512:
6
- metadata.gz: e73bcfd0fd395b7b1f2acf729a769e73e77c9329508a2290fe3f0f175fa0ee779a1d8c2a40ad5131322a2823898230cc71e9043eb29bc064d22f6f894a8e7fc9
7
- data.tar.gz: 9d80a9be09e0afc14d21bcf26dcdae7de60a0c0e9abe766fc6a17c13f0ae3eb9b5cede85ac47d482c6520d700ec0fca4e33ece4b0bed100f61aa03a3f61a20af
6
+ metadata.gz: 706b48ac696d80d501186e6547ccfeb27580557d7b329f2fc91c9ad61312d459b0c46c7feedf3309cd60c858a76bf9b226f5928021edd427473df9b1d63a2111
7
+ data.tar.gz: 9765572757897eedc79532ecf8c80b9286e14c18f2c5239b459ce20f6de8f2522931404fbd6d613a8a63f9302350e16b178d0d4887aa028a18970ef6a19bbc65
@@ -29,6 +29,39 @@ module Semian
29
29
  ResourceBusyError = ::ActiveRecord::ConnectionAdapters::TrilogyAdapter::ResourceBusyError
30
30
  CircuitOpenError = ::ActiveRecord::ConnectionAdapters::TrilogyAdapter::CircuitOpenError
31
31
 
32
+ QUERY_ALLOWLIST = %r{\A(?:/\*.*?\*/)?\s*(ROLLBACK|COMMIT|RELEASE\s+SAVEPOINT)}i
33
+
34
+ # The common case here is NOT to have transaction management statements, therefore
35
+ # we are exploiting the fact that Active Record will use COMMIT/ROLLBACK as
36
+ # the suffix of the command string and
37
+ # name savepoints by level of nesting as `active_record_1` ... n.
38
+ #
39
+ # Since looking at the last characters in a string using `end_with?` is a LOT cheaper than
40
+ # running a regex, we are returning early if the last characters of
41
+ # the SQL statements are NOT the last characters of the known transaction
42
+ # control statements.
43
+ class << self
44
+ def query_allowlisted?(sql, *)
45
+ # COMMIT, ROLLBACK
46
+ tx_command_statement = sql.end_with?("T") || sql.end_with?("K")
47
+
48
+ # RELEASE SAVEPOINT. Nesting past _3 levels won't get bypassed.
49
+ # Active Record does not send trailing spaces or `;`, so we are in the realm of hand crafted queries here.
50
+ savepoint_statement = sql.end_with?("_1") || sql.end_with?("_2")
51
+ unclear = sql.end_with?(" ") || sql.end_with?(";")
52
+
53
+ if !tx_command_statement && !savepoint_statement && !unclear
54
+ false
55
+ else
56
+ QUERY_ALLOWLIST.match?(sql)
57
+ end
58
+ rescue ArgumentError
59
+ return false unless sql.valid_encoding?
60
+
61
+ raise
62
+ end
63
+ end
64
+
32
65
  attr_reader :raw_semian_options, :semian_identifier
33
66
 
34
67
  def initialize(*options)
@@ -48,7 +81,7 @@ module Semian
48
81
  end
49
82
 
50
83
  def raw_execute(sql, *)
51
- if query_allowlisted?(sql)
84
+ if Semian::ActiveRecordTrilogyAdapter.query_allowlisted?(sql)
52
85
  super
53
86
  else
54
87
  acquire_semian_resource(adapter: :trilogy_adapter, scope: :query) do
@@ -90,17 +123,6 @@ module Semian
90
123
  ]
91
124
  end
92
125
 
93
- # TODO: share this with Mysql2
94
- QUERY_ALLOWLIST = %r{\A(?:/\*.*?\*/)?\s*(ROLLBACK|COMMIT|RELEASE\s+SAVEPOINT)}i
95
-
96
- def query_allowlisted?(sql, *)
97
- QUERY_ALLOWLIST.match?(sql)
98
- rescue ArgumentError
99
- return false unless sql.valid_encoding?
100
-
101
- raise
102
- end
103
-
104
126
  def connect(*args)
105
127
  acquire_semian_resource(adapter: :trilogy_adapter, scope: :connection) do
106
128
  super
data/lib/semian/rails.rb CHANGED
@@ -39,7 +39,7 @@ module Semian
39
39
  # - @raw_connection is for 7.0.x
40
40
  # - @connection is for versions below 6.1.x and below
41
41
  def client_connection
42
- if respond_to?(:valid_raw_connection)
42
+ if respond_to?(:valid_raw_connection, true)
43
43
  valid_raw_connection
44
44
  elsif instance_variable_defined?(:@raw_connection)
45
45
  @raw_connection
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Semian
4
- VERSION = "0.21.0"
4
+ VERSION = "0.21.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.21.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Francis
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-12-07 00:00:00.000000000 Z
13
+ date: 2024-01-17 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: |2
16
16
  A Ruby C extention that is used to control access to shared resources
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.4.22
82
+ rubygems_version: 3.5.4
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Bulkheading for Ruby with SysV semaphores