Module: Omen::Grants
- Defined in:
- lib/omen/grants.rb
Overview
Everything said to a database to make the role a statement runs as: what it may be, what it may read, and what it may not. Kept apart from the task that runs them, which is about a database it has to find and a refusal it has to survive rather than about privileges.
Class Method Summary collapse
-
.revoked(connection, role) ⇒ Array<String>
Intersected, so a bare db:create with no table yet to revoke on is not a failure.
-
.statements(connection, members) ⇒ Array<String>
DDL, which Active Record has no expression for, and not a query.
Class Method Details
.revoked(connection, role) ⇒ Array<String>
Intersected, so a bare db:create with no table yet to revoke on is not a failure.
34 35 36 37 38 |
# File 'lib/omen/grants.rb', line 34 def self.revoked(connection, role) (connection.tables & Omen.tables).map do |table| "REVOKE SELECT ON #{connection.quote_table_name table} FROM #{role}" end end |
.statements(connection, members) ⇒ Array<String>
DDL, which Active Record has no expression for, and not a query.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/omen/grants.rb', line 12 def self.statements(connection, members) role = connection.quote_table_name Omen.config.narrow_role [ 'DO $$ BEGIN IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = ' \ "#{connection.quote Omen.config.narrow_role}) THEN CREATE ROLE #{role} NOLOGIN; " \ 'END IF; END $$', "ALTER ROLE #{role} WITH #{Attributes::SETTABLE}", "GRANT USAGE ON SCHEMA public TO #{role}", "GRANT SELECT ON ALL TABLES IN SCHEMA public TO #{role}", "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO #{role}", *members.map { |member| "GRANT #{role} TO #{connection.quote_table_name member}" }, *revoked(connection, role), *Omen::Renamed.statements, *Omen::TimeZone.statements(connection), *Omen::Distance.statements(connection), ] end |