Sha256: befa66930e614a819efc4635a9b196e8bf3d5617a01edcdba679c6f4d78113eb

Contents?: true

Size: 781 Bytes

Versions: 6

Compression:

Stored size: 781 Bytes

Contents

class UserCredentials < ActiveRecord::Base

  class MissingCredentials < RuntimeError; end
  class InsufficientPermissions < RuntimeError; end
  class InvalidCredentials < RuntimeError; end
  class AccountLocked < RuntimeError; end

  encrypt_with_public_key :password, key_pair: Houston.config.keypair

  validate :test_connection
  validates :service, inclusion: { in: Houston.user_credentials_support_services }

  belongs_to :user

  def self.for(service)
    credentials = where(service: service).first || (raise MissingCredentials)
    [credentials.login, credentials.password.decrypt(Houston.config.passphrase)]
  rescue OpenSSL::PKey::RSAError
    credentials.delete
    raise MissingCredentials
  end

  def test_connection
    Houston.test_connection_to(self)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
houston-core-0.8.4 app/models/user_credentials.rb
houston-core-0.8.3 app/models/user_credentials.rb
houston-core-0.8.2 app/models/user_credentials.rb
houston-core-0.8.1 app/models/user_credentials.rb
houston-core-0.8.0 app/models/user_credentials.rb
houston-core-0.8.0.pre2 app/models/user_credentials.rb