Sha256: 74e745645e8de2077b1fc8d3af3c81432c7295cf35aa056805b7fd9456db134a

Contents?: true

Size: 928 Bytes

Versions: 1

Compression:

Stored size: 928 Bytes

Contents

module LastpassCLI
  class Agent
    attr_reader :logged_in, :config

    def initialize
      @config = LastpassCLI.configuration
    end

    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

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

    def logged_in?
      command = [config.executable]
      command += Command.new.status
      out, _, _ = Open3.capture2e(*command)
      !!out.match('Logged in as')
    end

    def logged_out?
      !logged_in?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lastpass-cli-0.1.1 lib/lastpass-cli/agent.rb