pg_rls 0.0.2.6.11 → 0.0.2.6.12
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 +4 -4
- data/.rubocop.yml +1 -1
- data/lib/generators/templates/pg_rls.rb.tt +13 -13
- data/lib/pg_rls/middleware/set_reset_connection.rb +48 -3
- data/lib/pg_rls/version.rb +1 -1
- data/lib/pg_rls.rb +0 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f20b589d7f7ad97bcbf75f1e0ff592e7fc27abe088f14f63ef2bf85316330bb5
|
4
|
+
data.tar.gz: 927b254ebe42c9d93cd444a178f17d7b60b3cb5f47937123f5d3c1c7b037af18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e8f8fa951cf0e544515423ff63379e13741ee777cf189725e7bbd3e75b6df091bf895e6f879f97c058f8ee7845b98178b3fd4121cdc86ef7322db94054c5fe6
|
7
|
+
data.tar.gz: b94f0eae566441c7e694bff41a4b3100bdfc7f2476bd5a5a6ddedfb3c793a8cd35ca805e6f36e722dace5410649d7d897425c0702392b69a077abda857d91795
|
data/.rubocop.yml
CHANGED
@@ -27,18 +27,18 @@ PgRls.setup do |config|
|
|
27
27
|
## which is autopopulated on each request
|
28
28
|
# config.solo_mode = true
|
29
29
|
|
30
|
+
## ------------------------------ Middleware SetResetConnection -----------------------------
|
31
|
+
## Uncomment this lines if you're using SetResetConnection Middleware
|
32
|
+
#
|
33
|
+
# config.session_store_server = Rails.application.config_for(:redis).session
|
34
|
+
#
|
35
|
+
## Uncomment this line if you're not using warden as your authentication system or if you
|
36
|
+
## changed the default warden key. Devise, uses warden authentication.
|
37
|
+
# config.session_store_default_warden_key = '2'
|
38
|
+
#
|
39
|
+
## Uncomment this line if you're setting a diferent session key than stablished under your
|
40
|
+
## redis server configuration
|
41
|
+
# config.session_key_prefix = '_hub_session'
|
30
42
|
##
|
31
|
-
##
|
32
|
-
## middleware to your Rails application to secure all database connections using Row Level Security.
|
33
|
-
## To add the middleware using the `middleware.use` method, add the following
|
34
|
-
## lines to your `config/application.rb` file:
|
35
|
-
## require 'pg_rls/middleware/set_reset_connection'
|
36
|
-
## config.middleware.use PgRls::Middleware::SetResetConnection
|
37
|
-
## Note: Be sure to add the `PgRls::Middleware::SetResetConnection` middleware after any
|
38
|
-
## middleware that sets up the Rails session, since the RLS middleware depends
|
39
|
-
## on the presence of the session to work correctly.
|
40
|
-
## Additionally, you will need to manually require the `PgRls::Middleware::SetResetConnection`
|
41
|
-
## file in your application, as shown in the first line of the code snippet above.
|
42
|
-
# config.session_key = '_hub_sessions'
|
43
|
-
# config.session_prefix = '_session_id:2::'
|
43
|
+
## ------------------------------ Middleware SetResetConnection -----------------------------
|
44
44
|
end
|
@@ -1,5 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module PgRls
|
4
|
+
class FrozenConfiguration < StandardError; end
|
5
|
+
|
6
|
+
def self.sessions
|
7
|
+
@sessions ||= Redis.new(@session_store_server)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.session_prefix
|
11
|
+
@session_prefix ||= begin
|
12
|
+
store_default_warden_key = @session_store_default_warden_key || '2'
|
13
|
+
|
14
|
+
"#{session_key_prefix}:#{store_default_warden_key}::"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.session_store_server=(opts = {})
|
19
|
+
raise Errors::FrozenConfiguration unless @sessions.nil?
|
20
|
+
|
21
|
+
@session_store_server = opts.deep_symbolize_keys
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.session_store_default_warden_key=(val)
|
25
|
+
raise Errors::FrozenConfiguration unless @sessions.nil?
|
26
|
+
|
27
|
+
@session_store_default_warden_key = val
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.session_key_prefix
|
31
|
+
@session_key_prefix ||= @session_key_prefix || @session_store_server[:key_prefix]
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.session_key_prefix=(val)
|
35
|
+
raise Errors::FrozenConfiguration unless @sessions.nil?
|
36
|
+
|
37
|
+
@session_key_prefix = val
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
3
41
|
module PgRls
|
4
42
|
module Middleware
|
5
43
|
# Set RLS if sessions present.
|
@@ -26,7 +64,7 @@ module PgRls
|
|
26
64
|
cookie_string = env['HTTP_COOKIE']
|
27
65
|
return if cookie_string.nil?
|
28
66
|
|
29
|
-
cookie_regex = /#{PgRls.
|
67
|
+
cookie_regex = /#{PgRls.session_key_prefix}=([^;]+)/
|
30
68
|
match = cookie_regex.match(cookie_string)
|
31
69
|
match[1] if match
|
32
70
|
end
|
@@ -36,8 +74,15 @@ module PgRls
|
|
36
74
|
|
37
75
|
return if cookie.blank?
|
38
76
|
|
39
|
-
|
40
|
-
|
77
|
+
redis_session_key = "#{PgRls.session_prefix}#{Digest::SHA256.hexdigest(cookie)}"
|
78
|
+
tenant_session = Marshal.load(PgRls.sessions.get(redis_session_key))
|
79
|
+
|
80
|
+
return if tenant_session.blank?
|
81
|
+
return if tenant_session['_tenant'].blank?
|
82
|
+
|
83
|
+
tenant_session['_tenant'] if tenant_session.present?
|
84
|
+
rescue TypeError
|
85
|
+
nil
|
41
86
|
end
|
42
87
|
|
43
88
|
def rails_active_storage_request?(env)
|
data/lib/pg_rls/version.rb
CHANGED
data/lib/pg_rls.rb
CHANGED
@@ -148,12 +148,6 @@ module PgRls
|
|
148
148
|
mattr_accessor :test_inline_tenant
|
149
149
|
@@test_inline_tenant = false
|
150
150
|
|
151
|
-
mattr_accessor :session_key
|
152
|
-
@@session_key = '_hub_sessions'
|
153
|
-
|
154
|
-
mattr_accessor :session_prefix
|
155
|
-
@@session_prefix = '_session_id:2::'
|
156
|
-
|
157
151
|
mattr_accessor :search_methods
|
158
152
|
@@search_methods = %i[subdomain id tenant_id]
|
159
153
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_rls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2.6.
|
4
|
+
version: 0.0.2.6.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Laloush
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|