Class: Remotus::Auth::Credential
- Inherits:
-
Object
- Object
- Remotus::Auth::Credential
- Defined in:
- lib/remotus/auth/credential.rb
Overview
Authentication credential
Instance Attribute Summary collapse
-
#private_key ⇒ String
Gets or sets private key path.
-
#user ⇒ String
Gets or sets user.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Remotus::Auth::Credential
Generates a new credential from a hash.
Instance Method Summary collapse
-
#initialize(user, password = nil, **options) ⇒ Credential
constructor
Creates a new instance of a Remotus::Auth::Credential.
-
#inspect ⇒ String
Inspects credential.
-
#password ⇒ String?
Retrieved decrypted password.
-
#password=(password) ⇒ Object
Sets password.
-
#private_key_data ⇒ String?
Retrieves decrypted private key data.
-
#private_key_data=(private_key_data) ⇒ Object
Sets private key data.
-
#to_s ⇒ String
Converts credential to a string.
Constructor Details
#initialize(user, password = nil, **options) ⇒ Credential
Creates a new instance of a Remotus::Auth::Credential
44 45 46 47 48 49 50 |
# File 'lib/remotus/auth/credential.rb', line 44 def initialize(user, password = nil, **) @user = user @crypt_info = { password: {}, private_key_data: {} } @private_key = [:private_key] self.password = password self.private_key_data = [:private_key_data] end |
Instance Attribute Details
#private_key ⇒ String
Returns gets or sets private key path.
13 14 15 |
# File 'lib/remotus/auth/credential.rb', line 13 def private_key @private_key end |
#user ⇒ String
Returns gets or sets user.
10 11 12 |
# File 'lib/remotus/auth/credential.rb', line 10 def user @user end |
Class Method Details
.from_hash(hash) ⇒ Remotus::Auth::Credential
Generates a new credential from a hash
26 27 28 29 30 31 32 33 |
# File 'lib/remotus/auth/credential.rb', line 26 def self.from_hash(hash) Credential.new( hash[:user], hash[:password], private_key: hash[:private_key], private_key_data: hash[:private_key_data] ) end |
Instance Method Details
#inspect ⇒ String
Inspects credential
106 107 108 |
# File 'lib/remotus/auth/credential.rb', line 106 def inspect "#{self.class.name}: (#{self})" end |
#password ⇒ String?
Retrieved decrypted password
57 58 59 60 61 |
# File 'lib/remotus/auth/credential.rb', line 57 def password return unless @password decrypt(@password, :password) end |
#password=(password) ⇒ Object
Sets password
68 69 70 |
# File 'lib/remotus/auth/credential.rb', line 68 def password=(password) @password = password ? encrypt(password.to_s, :password) : nil end |
#private_key_data ⇒ String?
Retrieves decrypted private key data
77 78 79 80 81 |
# File 'lib/remotus/auth/credential.rb', line 77 def private_key_data return unless @private_key_data decrypt(@private_key_data, :private_key_data) end |
#private_key_data=(private_key_data) ⇒ Object
Sets private key data
88 89 90 |
# File 'lib/remotus/auth/credential.rb', line 88 def private_key_data=(private_key_data) @private_key_data = private_key_data ? encrypt(private_key_data.to_s, :private_key_data) : nil end |
#to_s ⇒ String
Converts credential to a string
97 98 99 |
# File 'lib/remotus/auth/credential.rb', line 97 def to_s "user: #{@user}" end |