Sha256: a9854788b3a79a1f97b7e6cbd898b65d204ba28d52dea151fcd2b616ba16ba02

Contents?: true

Size: 1.41 KB

Versions: 13

Compression:

Stored size: 1.41 KB

Contents

module Seira
  class Db
    class AlterProxyuserRoles
      include Seira::Commands

      attr_reader :name, :root_password

      def initialize(app:, action:, args:, context:)
        if args.length != 2
          puts 'Specify db name and root password as the positional arguments'
          exit(1)
        end

        @name = args[0]
        @root_password = args[1]
      end

      def run
        # Connect to the instance and remove some of the default group memberships and permissions
        # from proxyuser, leaving it with only what it needs to be able to do
        expect_script = <<~BASH
          set timeout 90
          spawn gcloud sql connect #{name}
          expect "Password for user postgres:"
          send "#{root_password}\\r"
          expect "postgres=>"
          send "ALTER ROLE proxyuser NOCREATEDB NOCREATEROLE;\\r"
          expect "postgres=>"
        BASH
        if system("expect <<EOF\n#{expect_script}EOF")
          puts "Successfully removed unnecessary permissions from proxyuser"
        else
          puts "Failed to remove unnecessary permissions from proxyuser."
          puts "You may need to whitelist the correct IP in the gcloud UI."
          puts "You can get the correct IP from https://www.whatismyip.com/"
          puts "Make sure to remove it from the whitelist after successfully running db alter-proxyuser-roles"
          exit(1)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
seira-0.6.6 lib/seira/db/alter_proxyuser_roles.rb
seira-0.6.5 lib/seira/db/alter_proxyuser_roles.rb
seira-0.6.4 lib/seira/db/alter_proxyuser_roles.rb
seira-0.6.3 lib/seira/db/alter_proxyuser_roles.rb
seira-0.6.2 lib/seira/db/alter_proxyuser_roles.rb
seira-0.6.1 lib/seira/db/alter_proxyuser_roles.rb
seira-0.6.0 lib/seira/db/alter_proxyuser_roles.rb
seira-0.5.9 lib/seira/db/alter_proxyuser_roles.rb
seira-0.5.7 lib/seira/db/alter_proxyuser_roles.rb
seira-0.5.6 lib/seira/db/alter_proxyuser_roles.rb
seira-0.5.5 lib/seira/db/alter_proxyuser_roles.rb
seira-0.5.3 lib/seira/db/alter_proxyuser_roles.rb
seira-0.5.2 lib/seira/db/alter_proxyuser_roles.rb