Class: Omen::Narrowing
- Inherits:
-
Object
- Object
- Omen::Narrowing
- Defined in:
- lib/omen/narrowing.rb
Overview
What one audience of a reading may read: the role its statement runs as, the rows each table admits it, and the tables it reads whole because nothing in them is anybody's.
Constant Summary collapse
- EVERYBODY =
The policy every role holds, so that turning row level security on takes nothing away from whoever could already read -- a role made after this ran included. The narrowed role is held back by the restrictive policy beside it, which is ANDed with this one and applies to nobody else.
'omen_everybody'
Instance Attribute Summary collapse
-
#by ⇒ Symbol
readonly
The column of the reading that says whose rows these are.
-
#role ⇒ String
readonly
The Postgres role a reading of this audience runs as.
Instance Method Summary collapse
-
#initialize(role:, by:, own:, whole: [], except: nil) ⇒ Narrowing
constructor
A new instance of Narrowing.
-
#setting ⇒ String
The setting a policy reads to know whose rows it is looking at.
-
#statements(connection, members) ⇒ Array<Array<String>>
The statements, grouped: what arrives together is applied together, so no table is left with row level security on and no policy under it.
-
#widening(connection) ⇒ Array<Array<String>>
The statements that take it back off, table by table.
Constructor Details
#initialize(role:, by:, own:, whole: [], except: nil) ⇒ Narrowing
Returns a new instance of Narrowing.
24 25 26 27 28 29 30 |
# File 'lib/omen/narrowing.rb', line 24 def initialize(role:, by:, own:, whole: [], except: nil) @role = role @by = by @own = own.transform_keys(&:to_s) @whole = whole.map(&:to_s) @except = except end |
Instance Attribute Details
#by ⇒ Symbol (readonly)
Returns the column of the reading that says whose rows these are.
15 16 17 |
# File 'lib/omen/narrowing.rb', line 15 def by @by end |
#role ⇒ String (readonly)
Returns the Postgres role a reading of this audience runs as.
12 13 14 |
# File 'lib/omen/narrowing.rb', line 12 def role @role end |
Instance Method Details
#setting ⇒ String
Returns the setting a policy reads to know whose rows it is looking at.
33 |
# File 'lib/omen/narrowing.rb', line 33 def setting = "omen.#{@by}" |
#statements(connection, members) ⇒ Array<Array<String>>
Returns the statements, grouped: what arrives together is applied together, so no table is left with row level security on and no policy under it.
39 40 41 42 43 44 |
# File 'lib/omen/narrowing.rb', line 39 def statements(connection, members) [ Grants.made(connection, @role), Grants.narrowed(connection, @role, members), *@whole.map { |table| granted connection, table }, *@own.map { |table, own| narrowed connection, table, own }, ] end |
#widening(connection) ⇒ Array<Array<String>>
Returns the statements that take it back off, table by table.
48 49 50 |
# File 'lib/omen/narrowing.rb', line 48 def widening(connection) @own.keys.map { |table| widened connection, table } end |