14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/mimas/plugins/postgresql/commands/create_role.rb', line 14
def call(server_name:, role_name:, **options)
server = Config.current.servers[server_name.to_sym]
sudo_user = options[:user]
password = options[:password] || SecureRandom.alphanumeric(64)
ssh(server, user: sudo_user) do |session|
session.run "sudo -u postgres psql -c \"CREATE ROLE #{role_name} WITH LOGIN PASSWORD \'#{password}\';\"", capture: true
end
say ""
say "Created a new role #{role_name.dup.bold.magenta} with password: #{password.bold.white}"
say "Ensure you save this password as it cannot be displayed again."
end
|