Krikri::PluginHelpers::PostgresqlAcl
PostgresqlAcl - pure logic for parsing a PostgreSQL ACL array (the
relacl/nspacl/datacl columns of pg_class/pg_namespace/
pg_database, cast to ::text in the query so the driver hands
back a plain string rather than needing a native aclitem[]
codec) and mapping privilege names to their single-letter codes.
No I/O - postgresql_privs.cr does the actual GRANT/REVOKE and ACL
lookups.
Format verified against a real PostgreSQL 17 server, not assumed
from docs: {postgres=arwdDxtm/postgres,bob=rw/postgres,alice=r*/postgres}
- comma-separated
grantee=privs/grantorentries inside{}; an empty grantee (=r/postgres) means thePUBLICpseudo-role; a*immediately following a privilege letter means that specific privilege carriesWITH GRANT OPTION(not a whole-entry flag - two privileges on the same entry can differ, e.g.r*wis SELECT WITH GRANT OPTION plus a plain UPDATE).
Constants
"ALL"/"ALL PRIVILEGES" expands to every privilege real PostgreSQL
grants under GRANT ALL ON <type> ... for that object type -
deliberately excludes MAINTAIN for table/sequence even
though it's a real privilege letter above, matching real
PostgreSQL's own GRANT ALL behavior verified against a real
server (ALL does not imply MAINTAIN pre-17, and even on 17 the
module's own real-Ansible behavior this codebase matches doesn't
special-case it in ALL's expansion either).
A lookup table rather than a case/when chain, same reasoning as
PostgresqlPrivsPlugin::OBJECT_KINDS - keeps this well under
ameba's cyclomatic-complexity budget regardless of how many
object types get added.
Privilege name -> single-letter ACL code, per object type. Real
PostgreSQL's own privilege letters (see the GRANT/\dp docs),
verified against actual relacl/nspacl/datacl output rather
than assumed. MAINTAIN (PostgreSQL 17+) is included for
table/sequence since it's harmless to recognize even on an
older server (a request for it there would just fail with the
server's own "unrecognized privilege" error, same as any other
server-version-specific privilege).
Class methods
Parses a relacl/nspacl/datacl ::text value into
{grantee_name => {letter => grant_option}}. PUBLIC's entry (an
empty grantee before the =) is keyed under the literal string
"PUBLIC" for callers' convenience, not "". nil/empty input (a
SQL NULL ACL column, meaning no explicit grants exist yet beyond
the object's implicit owner/PUBLIC defaults) parses to an empty
hash - every privilege then reads as "not granted", which is the
correct default for GRANT idempotency purposes here even though
it doesn't reflect PostgreSQL's own implicit-default grants
(documented simplification, matching how postgresql_user.cr
already doesn't compare against inherited role membership either).