semian 0.21.1 → 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: 582286749e5f1d41b7ba0241f7296a28edb9eedfceb06c60abb49c56c2cc7548
4
- data.tar.gz: 44d76f2a1f2116e638dd5360de8900e8cee73e0efb82501746d35213dc3d0df0
3
+ metadata.gz: f07497a8f77d5309e042951ac2c15d6a8e420abcafea896890a103e78fe05118
4
+ data.tar.gz: bfbd847f058a7bd3b7a947f3f610037fb4aa5e83fa9bfcc62c45ffee9a65c84e
5
5
  SHA512:
6
- metadata.gz: cb3fddb047e11477d1413a8d33faea222458c15360170242e565bf661090b8afa8b625424b8734801737f68d8e23edafcc1ffdd8fcb35ea2c2e1ea761e7d690a
7
- data.tar.gz: 2d11aea9d0f390b127e1b05df0dbde3d9817e336f8a15e8d8010efa78afd46d45ef8e935b96f2da5e5fbca13c3f8a084c7b78d8b3159d32919b2af87fa370110
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Semian
4
- VERSION = "0.21.1"
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.1
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: 2024-01-10 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