Class: RightScale::LoginUser

Inherits:
Object
  • Object
show all
Includes:
Serializable
Defined in:
lib/right_agent/core_payload_types/login_user.rb

Overview

Authorized user for the Managed Login feature

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

included

Constructor Details

#initialize(*args) ⇒ LoginUser

Initialize fields from given arguments



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/right_agent/core_payload_types/login_user.rb', line 37

def initialize(*args)
  @uuid         = args[0]
  @username     = args[1]
  @public_key   = args[2]
  @common_name  = args[3] || ''
  @superuser    = args[4] || false
  @expires_at   = Time.at(args[5]) if args[5] && (args[5] != 0) # nil -> 0 because of expires_at.to_i below
  @public_keys  = args[6]
  @profile_data = args[7]
  @public_key_fingerprints = args[8]

  # We now expect an array of public_keys to be passed while supporting the
  # singular public_key as a legacy member. When serialized back from a
  # legacy LoginUser record, the singular value may be set while the plural
  # is nil.
  if @public_keys
    raise ArgumentError, "Expected public_keys (seventh argument) to be an array" unless @public_keys.is_a?(Array)
    @public_key = @public_keys.first
  else
    raise ArgumentError, "Expected public_key (third argument) to be a string" unless @public_key.is_a?(String)
    @public_keys = [@public_key]
  end

  # The number of fingerprints must match the number of public keys
  if @public_key_fingerprints && @public_key_fingerprints.size != @public_keys.size
    raise ArgumentError, "Expected public_keys (seventh argument) array length (#{@public_keys.size}) is not " +
                         "the same as the public_key_fingerprints (eighth argument) (#{@public_key_fingerprints.size})"
  end
end

Instance Attribute Details

#common_nameObject

Returns the value of attribute common_name.



33
34
35
# File 'lib/right_agent/core_payload_types/login_user.rb', line 33

def common_name
  @common_name
end

#expires_atObject

Returns the value of attribute expires_at.



33
34
35
# File 'lib/right_agent/core_payload_types/login_user.rb', line 33

def expires_at
  @expires_at
end

#profile_dataObject

Returns the value of attribute profile_data.



33
34
35
# File 'lib/right_agent/core_payload_types/login_user.rb', line 33

def profile_data
  @profile_data
end

#public_keyObject

Returns the value of attribute public_key.



33
34
35
# File 'lib/right_agent/core_payload_types/login_user.rb', line 33

def public_key
  @public_key
end

#public_key_fingerprintsObject

Returns the value of attribute public_key_fingerprints.



33
34
35
# File 'lib/right_agent/core_payload_types/login_user.rb', line 33

def public_key_fingerprints
  @public_key_fingerprints
end

#public_keysObject

Returns the value of attribute public_keys.



33
34
35
# File 'lib/right_agent/core_payload_types/login_user.rb', line 33

def public_keys
  @public_keys
end

#superuserObject

Returns the value of attribute superuser.



33
34
35
# File 'lib/right_agent/core_payload_types/login_user.rb', line 33

def superuser
  @superuser
end

#usernameObject

Returns the value of attribute username.



33
34
35
# File 'lib/right_agent/core_payload_types/login_user.rb', line 33

def username
  @username
end

#uuidObject

Returns the value of attribute uuid.



33
34
35
# File 'lib/right_agent/core_payload_types/login_user.rb', line 33

def uuid
  @uuid
end

Class Method Details

.fingerprint(public_key) ⇒ Object

Create fingerprint for public key



74
75
76
# File 'lib/right_agent/core_payload_types/login_user.rb', line 74

def self.fingerprint(public_key)
  Digest::SHA1.hexdigest(::Net::SSH::KeyFactory.load_data_public_key(public_key).to_der)
end

Instance Method Details

#serialized_membersObject

Array of serialized fields given to constructor



68
69
70
71
# File 'lib/right_agent/core_payload_types/login_user.rb', line 68

def serialized_members
  [ @uuid, @username, @public_key, @common_name, @superuser, @expires_at.to_i, @public_keys, @profile_data,
    @public_key_fingerprints ]
end