Class: Lastpass::Cli Private
- Inherits:
-
Object
- Object
- Lastpass::Cli
- Defined in:
- lib/lastpass-api/cli.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Low-level interaction with LastPass CLI
Constant Summary collapse
- UPLOAD_QUEUE_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
TODO:Make this configurable? Or at least smarter?
'~/.lpass/upload-queue'
Class Method Summary collapse
- .add(name, username: nil, password: nil, url: nil, notes: nil, group: nil) ⇒ Object private
- .add_group(name) ⇒ Object private
- .duplicate ⇒ Object private
- .edit(id, name: nil, username: nil, password: nil, url: nil, notes: nil, group: nil) ⇒ Object private
- .edit_group(id, name:) ⇒ Object private
- .export ⇒ Object private
- .generate ⇒ Object private
- .import(csv_filename) ⇒ Object private
-
.login(username, password:, trust: false, plaintext_key: false, force: false) ⇒ Object
private
Login to LastPass, opening up a global session.
- .logout(force: false) ⇒ Object private
- .ls(group = nil, long: false, m: false, u: false) ⇒ Object private
- .mv ⇒ Object private
- .passwd ⇒ Object private
- .rm(id) ⇒ Object private
- .share ⇒ Object private
- .show(account, clip: false, expand_multi: false, all: false, basic_regexp: false, id: false) ⇒ Object private
- .status(quiet: false) ⇒ Object private
- .sync ⇒ Object private
- .version ⇒ Object private
Class Method Details
.add(name, username: nil, password: nil, url: nil, notes: nil, group: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass add [–sync=auto|now|no] [–non-interactive] [–color=auto|never|always] {–username|–password|–url|–notes|–field=FIELD|–note-type=NOTETYPE} NAME
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/lastpass-api/cli.rb', line 91 def self.add( name, username: nil, password: nil, url: nil, notes: nil, group: nil ) data = {} data[:Username] = escape( username, double: true ) if username data[:Password] = escape( password, double: true ) if password data[:URL] = escape( url, double: true ) if url data[:Notes] = '\n' << escape( notes, double: true ) if notes command = 'printf "' command << data.map { |d| d.join( ': ' ) }.join( '\n' ) command << '" | lpass add --non-interactive --sync=no \'' command << "#{escape( group )}/" if group command << "#{escape( name )}'" response = Utils.cmd command sync response end |
.add_group(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass add [–sync=auto|now|no] [–non-interactive] [–color=auto|never|always] {–username|–password|–url|–notes|–field=FIELD|–note-type=NOTETYPE} NAME
109 110 111 112 113 |
# File 'lib/lastpass-api/cli.rb', line 109 def self.add_group( name ) response = Utils.cmd "printf 'URL: http://group' | lpass add --non-interactive --sync=no '#{escape( name )}/'" sync response end |
.duplicate ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Not yet implemented
lpass duplicate [–sync=auto|now|no] [–color=auto|never|always] {UNIQUENAME|UNIQUEID}
162 163 164 |
# File 'lib/lastpass-api/cli.rb', line 162 def self.duplicate not_implemented! end |
.edit(id, name: nil, username: nil, password: nil, url: nil, notes: nil, group: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass edit [–sync=auto|now|no] [–non-interactive] [–color=auto|never|always] {–name|–username|–password|–url|–notes|–field=FIELD} {NAME|UNIQUEID}
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/lastpass-api/cli.rb', line 116 def self.edit( id, name: nil, username: nil, password: nil, url: nil, notes: nil, group: nil ) data = {} name_with_group = '' name_with_group << "#{group}/" if group name_with_group << name if name data[:Name] = escape( name_with_group, double: true ) unless name_with_group == '' data[:Username] = escape( username, double: true ) if username data[:Password] = escape( password, double: true ) if password data[:URL] = escape( url, double: true ) if url data[:Notes] = '\n' << escape( notes, double: true ) if notes command = 'printf "' command << data.map { |d| d.join( ': ' ) }.join( '\n' ) command << '" | lpass edit --non-interactive --sync=no ' command << id response = Utils.cmd command sync response end |
.edit_group(id, name:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass edit [–sync=auto|now|no] [–non-interactive] [–color=auto|never|always] {–name|–username|–password|–url|–notes|–field=FIELD} {NAME|UNIQUEID}
This does actually rename the project even though it looks like it creates a new group in Lastpass. This is because the original creds that were under this project have the group name in the name of the creds (yay for Lastpass awesomeness). So, after a project rename, newly created creds will go under the new group name. Old creds will rename in the old pseudo name.
144 145 146 147 148 149 150 151 152 |
# File 'lib/lastpass-api/cli.rb', line 144 def self.edit_group( id, name: ) command = 'printf "' command << "Name: #{escape( name, double: true )}/" command << '" | lpass edit --non-interactive --sync=no ' command << id response = Utils.cmd command sync response end |
.export ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass export [–sync=auto|now|no] [–color=auto|never|always]
189 190 191 |
# File 'lib/lastpass-api/cli.rb', line 189 def self.export Utils.cmd 'lpass export' end |
.generate ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Not yet implemented
lpass generate [–sync=auto|now|no] [–clip, -c] [–username=USERNAME] [–url=URL] [–no-symbols] {NAME|UNIQUEID} LENGTH
156 157 158 |
# File 'lib/lastpass-api/cli.rb', line 156 def self.generate not_implemented! end |
.import(csv_filename) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass import [CSV_FILENAME]
194 195 196 |
# File 'lib/lastpass-api/cli.rb', line 194 def self.import( csv_filename ) Utils.cmd "lpass import '#{escape( csv_filename )}'" end |
.login(username, password:, trust: false, plaintext_key: false, force: false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass login [–trust] [–plaintext-key [–force, -f]] [–color=auto|never|always] USERNAME
Login to LastPass, opening up a global session
30 31 32 33 34 35 36 37 |
# File 'lib/lastpass-api/cli.rb', line 30 def self.login( username, password:, trust: false, plaintext_key: false, force: false ) command = "echo '#{password}' | LPASS_DISABLE_PINENTRY=1 lpass login" command << ' --trust' if trust command << ' --plaintext-key' if plaintext_key command << ' --force' if force command << " '#{escape( username )}'" Utils.cmd command end |
.logout(force: false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass logout [–force, -f] [–color=auto|never|always]
40 41 42 43 44 |
# File 'lib/lastpass-api/cli.rb', line 40 def self.logout( force: false ) command = 'echo "Y" | lpass logout' command << ' --force' if force Utils.cmd command end |
.ls(group = nil, long: false, m: false, u: false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass ls [–sync=auto|now|no] [–long, -l] [-m] [-u] [–color=auto|never|always] [GROUP]
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/lastpass-api/cli.rb', line 70 def self.ls( group = nil, long: false, m: false, u: false ) sync # Ensure everything is synced up before running! command = 'lpass ls' command << ' --long' if long command << ' -m' if m command << ' -u' if u command << " '#{escape( group )}'" if group response = Utils.cmd command # Don't let LastPass know the accounts were accessed as it clogs up the sync! # So clear out sync files if a lot of accounts were accessed at the same time. remove_sync_files if response.length > 400 response end |
.mv ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Not yet implemented
lpass mv [–color=auto|never|always] {UNIQUENAME|UNIQUEID} GROUP
86 87 88 |
# File 'lib/lastpass-api/cli.rb', line 86 def self.mv not_implemented! end |
.passwd ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Not yet implemented
lpass passwd
48 49 50 |
# File 'lib/lastpass-api/cli.rb', line 48 def self.passwd not_implemented! end |
.rm(id) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass rm [–sync=auto|now|no] [–color=auto|never|always] {UNIQUENAME|UNIQUEID}
167 168 169 170 171 |
# File 'lib/lastpass-api/cli.rb', line 167 def self.rm( id ) response = Utils.cmd "lpass rm --sync=no #{id}" sync response end |
.share ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Not yet implemented
lpass share subcommand sharename …
200 201 202 |
# File 'lib/lastpass-api/cli.rb', line 200 def self.share not_implemented! end |
.show(account, clip: false, expand_multi: false, all: false, basic_regexp: false, id: false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass show [–sync=auto|now|no] [–clip, -c] [–expand-multi, -x] [–all|–username|–password|–url|–notes|–field=FIELD|–id|–name|–attach=ATTACHID] [–basic-regexp, -G|–fixed-strings, -F] [–color=auto|never|always] {UNIQUENAME|UNIQUEID}
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/lastpass-api/cli.rb', line 53 def self.show( account, clip: false, expand_multi: false, all: false, basic_regexp: false, id: false ) sync # Ensure everything is synced up before running! command = 'lpass show' command << ' --clip' if clip command << ' --expand-multi' if command << ' --all' if all command << ' --basic-regexp' if basic_regexp command << ' --id' if id command << " '#{escape( account )}'" response = Utils.cmd command # Don't let LastPass know the accounts were accessed as it clogs up the sync! # So clear out sync files if a lot of accounts were accessed at the same time. remove_sync_files if response.length > 400 response end |
.status(quiet: false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
lpass status [–quiet, -q] [–color=auto|never|always]
174 175 176 177 178 |
# File 'lib/lastpass-api/cli.rb', line 174 def self.status( quiet: false ) command = 'lpass status' command << ' --quiet' if quiet Utils.cmd command end |
.sync ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This is a buggy function of the lpass executable. May not be super reliable.
lpass sync [–background, -b] [–color=auto|never|always]
182 183 184 185 186 |
# File 'lib/lastpass-api/cli.rb', line 182 def self.sync sleep 1 # Allow file IO before attempting sync Utils.cmd 'lpass sync' sleep 1 # Allow sync to finish end |