Module: Bitferry::Rclone

Extended by:
Logging
Includes:
Logging
Defined in:
lib/bitferry.rb

Defined Under Namespace

Classes: Copy, Decrypt, Encrypt, Encryption, Equalize, Synchronize, Task, Update

Constant Summary collapse

SECRET =
"\x9c\x93\x5b\x48\x73\x0a\x55\x4d\x6b\xfd\x7c\x63\xc8\x86\xa9\x2b\xd3\x90\x19\x8e\xb8\x12\x8a\xfb\xf4\xde\x16\x2b\x8b\x95\xf6\x38"
ROUTE =
{
  encrypt: Encrypt,
  decrypt: Decrypt
}

Class Method Summary collapse

Methods included from Logging

log, log, log=

Class Method Details

.exec(*args) ⇒ Object



677
678
679
680
681
682
683
684
685
686
687
# File 'lib/bitferry.rb', line 677

def self.exec(*args)
  cmd = [executable] + args
  log.debug(cmd.collect(&:shellescape).join(' '))
  stdout, status = Open3.capture2e(*cmd)
  unless status.success?
    msg = "rclone exit code #{status.exitstatus}"
    log.error(msg)
    raise RuntimeError, msg
  end
  stdout.strip
end

.executableObject



674
# File 'lib/bitferry.rb', line 674

def self.executable = @executable ||= (rclone = ENV['RCLONE']).nil? ? 'rclone' : rclone

.obscure(plain) ⇒ Object



694
695
696
697
698
699
# File 'lib/bitferry.rb', line 694

def self.obscure(plain)
  cipher = OpenSSL::Cipher.new('AES-256-CTR')
  cipher.encrypt
  cipher.key = SECRET
  Base64.urlsafe_encode64(cipher.random_iv + cipher.update(plain) + cipher.final, padding: false)
end

.reveal(token) ⇒ Object



702
703
704
705
706
707
708
709
# File 'lib/bitferry.rb', line 702

def self.reveal(token)
  data = Base64.urlsafe_decode64(token)
  cipher = OpenSSL::Cipher.new('AES-256-CTR')
  cipher.decrypt
  cipher.key = SECRET
  cipher.iv = data[0...cipher.iv_len]
  cipher.update(data[cipher.iv_len..-1]) + cipher.final
end