Sha256: 650ffafca19f15f30341949c077e51e84118c7f680d87bb66067c65d76fe0dbc

Contents?: true

Size: 837 Bytes

Versions: 1

Compression:

Stored size: 837 Bytes

Contents

class PgPass

  class FileMissing < ApplicationDatabase::ConfigurationError
    def initialize
      message = "#{File.expand_path("~/.pgpass")} file not found, cannot dump database contents"
      super(message)
    end
  end

  class FilePermissionsError < ApplicationDatabase::ConfigurationError
    def initialize
      message = "password file #{File.expand_path("~/.pgpass")} has group or world access; permissions should be u=rw (0600)"
      super(message)
    end
  end

  def self.ensure
    # TODO missing file and permissions errors are recoverable
    # create or chmod the file instead of triggering an exception
    password_file = File.expand_path("~/.pgpass")
    raise FileMissing unless File.exists?(password_file)
    raise FilePermissionsError unless sprintf("%o", File.stat(password_file).mode) =~ /600$/
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glacier_on_rails-1.0.0 app/models/pg_pass.rb