-require 'chef/mixin/command'
+require "chef/mixin/command"
class Chef
class PostgreSQL
TABLE_PRIVILEGES = [
:select, :insert, :update, :delete, :truncate, :references, :trigger
- ]
+ ].freeze
def initialize(cluster)
@cluster = cluster
end
end
+ def tablespaces
+ @tablespaces ||= query("SELECT spcname, usename FROM pg_tablespace AS t INNER JOIN pg_user AS u ON t.spcowner = u.usesysid").each_with_object({}) do |tablespace, tablespaces|
+ tablespaces[tablespace[:spcname]] = {
+ :owner => tablespace[:usename]
+ }
+ end
+ end
+
def tables(database)
@tables ||= {}
@tables[database] ||= query("SELECT n.nspname, c.relname, u.usename, c.relacl FROM pg_class AS c INNER JOIN pg_user AS u ON c.relowner = u.usesysid INNER JOIN pg_namespace AS n ON c.relnamespace = n.oid", :database => database).each_with_object({}) do |table, tables|
end
end
- private
+ private
def parse_acl(acl)
acl.sub(/^\{(.*)\}$/, "\\1").split(",").each_with_object({}) do |entry, permissions|
- entry = entry.sub(/^"(.*)"$/) { Regexp.last_match[1].gsub(/\\"/, '"') }.sub(/\/.*$/, "")
+ entry = entry.sub(/^"(.*)"$/) { Regexp.last_match[1].gsub(/\\"/, '"') }.sub(%r{/.*$}, "")
user, privileges = entry.split("=")
user = user.sub(/^"(.*)"$/, "\\1")
permissions[user] = {
"a" => :insert, "r" => :select, "w" => :update, "d" => :delete,
"D" => :truncate, "x" => :references, "t" => :trigger
- }.values_at(*(privileges.chars)).compact
+ }.values_at(*privileges.chars).compact
end
end
end