Class: LastpassCLI::Agent
- Inherits:
-
Object
- Object
- LastpassCLI::Agent
- Defined in:
- lib/lastpass-cli/agent.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logged_in ⇒ Object
readonly
Returns the value of attribute logged_in.
Instance Method Summary collapse
-
#initialize ⇒ Agent
constructor
A new instance of Agent.
- #logged_in? ⇒ Boolean
- #logged_out? ⇒ Boolean
- #login ⇒ Object
- #logout ⇒ Object
Constructor Details
#initialize ⇒ Agent
Returns a new instance of Agent.
5 6 7 |
# File 'lib/lastpass-cli/agent.rb', line 5 def initialize @config = LastpassCLI.configuration end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/lastpass-cli/agent.rb', line 3 def config @config end |
#logged_in ⇒ Object (readonly)
Returns the value of attribute logged_in.
3 4 5 |
# File 'lib/lastpass-cli/agent.rb', line 3 def logged_in @logged_in end |
Instance Method Details
#logged_in? ⇒ Boolean
29 30 31 32 33 34 |
# File 'lib/lastpass-cli/agent.rb', line 29 def logged_in? command = [config.executable] command += Command.new.status out, _, _ = Open3.capture2e(*command) !!out.match('Logged in as') end |
#logged_out? ⇒ Boolean
36 37 38 |
# File 'lib/lastpass-cli/agent.rb', line 36 def logged_out? !logged_in? end |
#login ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/lastpass-cli/agent.rb', line 9 def login return true if logged_in? command = [config.executable] command += Command.new.login(username: config.username) out, _, _ = Open3.capture2e( { 'LPASS_DISABLE_PINENTRY' => '1' }, *command, stdin_data: "#{config.password}\n" ) !!out.match('Success: Logged in') end |