Class: U3dCore::Credentials
- Inherits:
-
Object
- Object
- U3dCore::Credentials
- Defined in:
- lib/u3d_core/credentials.rb
Constant Summary collapse
- MAC_U3D_SERVER =
'u3d'
Instance Method Summary collapse
- #forget_credentials(force: false) ⇒ Object
-
#initialize(user: nil, password: nil) ⇒ Credentials
constructor
A new instance of Credentials.
- #login ⇒ Object
- #password ⇒ Object
- #remember_credentials ⇒ Object
- #server_name ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(user: nil, password: nil) ⇒ Credentials
Returns a new instance of Credentials.
32 33 34 35 36 |
# File 'lib/u3d_core/credentials.rb', line 32 def initialize(user: nil, password: nil) @user = user @password = password @use_keychain = U3dCore::Globals.use_keychain? end |
Instance Method Details
#forget_credentials(force: false) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/u3d_core/credentials.rb', line 102 def forget_credentials(force: false) @password = nil ENV['U3D_PASSWORD'] = nil if force || UI.interactive? if Helper.mac? && @use_keychain && (force || UI.confirm('Remove credentials from the keychain?')) UI. 'Deleting credentials from the keychain' Security::InternetPassword.delete(server: server_name) end elsif Helper.mac? UI.verbose 'Keychain may store invalid credentials for u3d' end end |
#login ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/u3d_core/credentials.rb', line 72 def login UI.verbose 'Attempting to login' raise CredentialsError, 'No username specified' unless user while @password.nil? UI.verbose 'Password does not exist' raise CredentialsError, 'Password missing and context is not interactive. Please make sure it is correct' unless UI.interactive? @password = UI.password "Password for #{user}:" end if remember_credentials UI.success 'Credentials have been stored' else UI.important 'No credentials storage available' end end |
#password ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/u3d_core/credentials.rb', line 51 def password @password ||= ENV['U3D_PASSWORD'] if Helper.mac? && @use_keychain && !@password UI. 'Fetching password from keychain' password_holder = Security::InternetPassword.find(server: server_name) @password = password_holder.password unless password_holder.nil? end if @password.nil? UI.verbose 'Could not retrieve password' if U3dCore::Globals.do_not_login? UI.verbose 'Login disabled' else login end end return @password end |
#remember_credentials ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/u3d_core/credentials.rb', line 91 def remember_credentials ENV['U3D_USER'] = @user ENV['U3D_PASSWORD'] = @password if Helper.mac? && @use_keychain UI. 'Storing credentials to the keychain' return Security::InternetPassword.add(server_name, user, password) end return false end |
#server_name ⇒ Object
115 116 117 |
# File 'lib/u3d_core/credentials.rb', line 115 def server_name MAC_U3D_SERVER end |
#user ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/u3d_core/credentials.rb', line 38 def user @user ||= ENV['U3D_USER'] while @user.to_s.empty? UI.verbose 'Username does not exist or is empty' raise CredentialsError, 'Username missing and context is not interactive. Please check that the environment variable is correct' unless UI.interactive? @user = UI.input 'Username for u3d:' end return @user end |