Class: LastpassCLI::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/lastpass-cli/agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAgent

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

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/lastpass-cli/agent.rb', line 3

def config
  @config
end

#logged_inObject (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

Returns:

  • (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

Returns:

  • (Boolean)


36
37
38
# File 'lib/lastpass-cli/agent.rb', line 36

def logged_out?
  !logged_in?
end

#loginObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/lastpass-cli/agent.rb', line 9

def 
  return true if logged_in?
  command = [config.executable]
  command += Command.new.(username: config.username)
  out, _, _ = Open3.capture2e(
    { 'LPASS_DISABLE_PINENTRY' => '1' },
    *command,
    stdin_data: "#{config.password}\n"
  )
  !!out.match('Success: Logged in')
end

#logoutObject



21
22
23
24
25
26
27
# File 'lib/lastpass-cli/agent.rb', line 21

def logout
  return true if logged_out?
  command = [config.executable]
  command += Command.new.logout
  out, _, _ = Open3.capture2e(*command)
  !!out.match('Log out: complete')
end