Module: PgDrive

Defined in:
lib/pg_drive.rb,
lib/pg_drive/dump.rb,
lib/pg_drive/version.rb,
lib/pg_drive/uploader.rb

Defined Under Namespace

Modules: Dump, Uploader

Constant Summary collapse

InvalidEnvironment =
Class.new(StandardError)
BackupFailed =
Class.new(StandardError)
OOB_URI =
"urn:ietf:wg:oauth:2.0:oob".freeze
DEFAULT_BACKUP_TIMEOUT_SECONDS =

5 minutes

60 * 5
MISSING_CRED_WARNING =
"Please use the run #{self}.setup_credentials"\
" from console to set up credentials".freeze
CREDENTIALS_INTRO =
"Please open your browser and go to the following url:"\
"Login with the user you wish to use as target for backup".freeze
CREDENTIALS_ENV_INSTRUCTIONS =
"Please set the following line as the value of "\
'"PG_DRIVE_CREDENTIALS" key the environment:'.freeze
BACKUP_CMD =
"pg_dump -Fc -c -C -b".freeze
PG_ENV_MAP =
{
  "PGPASSWORD" => "password",
  "PGDATABASE" => "database",
  "PGHOST" => "host",
  "PGPORT" => "port",
  "PGUSER" => "username",
}.freeze
BINARY_MIME_TYPE =
"application/octet-stream".freeze
VERSION =
"0.2.0".freeze

Class Method Summary collapse

Class Method Details

.performObject



32
33
34
35
36
# File 'lib/pg_drive.rb', line 32

def perform
  Dump.call do |pipe|
    Uploader.call(pipe)
  end
end

.refresh_token_from_code(code) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/pg_drive.rb', line 47

def refresh_token_from_code(code)
  Uploader.authorizer.get_credentials_from_code(
    user_id: :owner,
    code: code,
    base_url: OOB_URI
  ).refresh_token
end

.setup_credentialsObject



38
39
40
41
42
43
44
45
# File 'lib/pg_drive.rb', line 38

def setup_credentials
  puts CREDENTIALS_INTRO
  puts Uploader.authorizer.get_authorization_url(base_url: OOB_URI)
  puts "Please enter the token you receive for further instructions"
  code = gets
  puts CREDENTIALS_ENV_INSTRUCTIONS
  puts refresh_token_from_code(code)
end