lastpass-cli 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5a4dc2da94a48fdd5613b4fda4fffb0307f39eeb
4
+ data.tar.gz: db2b116fc2ae63db6320eef6a4ec9cfc2cfd99c8
5
+ SHA512:
6
+ metadata.gz: e546282f422ee7a70c2a066beb479a296f1de96ad22aa8d8ae37f16ab1acbc8836b319bea7f43545741789cdb1ff991bb4da20e004df12b72539c9cec87bb302
7
+ data.tar.gz: b458d529ff4edd7a6d139ab1560d0d9764c5a354d95e6d6a3ef6b956a2a97cca8700f115000e25f25014f792e4187bfad5071050d3c8c89a3d9e3f053e609781
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ before_install: gem install bundler -v 1.13.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lastpass-cli.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Quantifi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,93 @@
1
+ # LastPassCLI-Ruby
2
+
3
+ LastPassCLI-Ruby uses the [LastPass Command Line Interface](https://github.com/lastpass/lastpass-cli) to add passwords, notes, and other secure items to the LastPass password management service, and to read those same items.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lastpass-cli'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install lastpass-cli
20
+
21
+ Add your LastPass credentials to environment variables named `LASTPASS_EMAIL` and `LASTPASS_PASSWORD`. For development and test environments, consider using something like [dotenv](https://github.com/bkeepers/dotenv).
22
+
23
+ For use with Ruby on Rails, create the initializer with the following command:
24
+
25
+ ```
26
+ rails generate lastpass_cli
27
+ ```
28
+
29
+ If you're not using Rails, configure the gem like this:
30
+
31
+ ```rb
32
+ LastpassCLI.configure do |config|
33
+ config.username = ENV['LASTPASS_EMAIL']
34
+ config.password = ENV['LASTPASS_PASSWORD']
35
+ end
36
+ ```
37
+
38
+ Since LastPassCLI-Ruby is a wrapper for [lastpass-cli](https://github.com/lastpass/lastpass-cli), you'll need to install that too.
39
+
40
+ For Linux, FreeBSD, or Cygwin, see the [installation instructions in the README](https://github.com/lastpass/lastpass-cli#installing-on-linux).
41
+
42
+ For macOS or OS X, you can install `lastpass-cli` with [Homebrew](http://brew.sh/) (`brew install lastpass-cli --with-pinentry`) or [MacPorts](https://www.macports.org/) (`sudo port install lastpass-cli`).
43
+
44
+ ## Usage
45
+
46
+ ### Reading items from LastPass
47
+
48
+ Look up items by Unique ID or name (with optional folder).
49
+
50
+ ```rb
51
+ LastpassCLI.show("SOME_UNIQUE_ID") # by Unique ID
52
+ LastpassCLI.show("github") # by name
53
+ LastpassCLI.show("social/linkedin") # by name with folder
54
+ LastpassCLI.show("ssn") # works with non-password items as well
55
+ ```
56
+
57
+ ### Adding items to LastPass
58
+
59
+ ```rb
60
+ LastpassCLI.add_password(
61
+ "social/twitter",
62
+ username: "someone",
63
+ password: "$0m3thing-$3cr3t!",
64
+ url: "https://twitter.com",
65
+ notes: "Use it wisely."
66
+ )
67
+ ```
68
+
69
+ You can also check out the [usage instructions for `lastpass-cli` itself](https://lastpass.github.io/lastpass-cli/lpass.1.html).
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ For convenience, you may want to add your LastPass credentials to `bin/console`, but remember not to commit them to the repository! For example, just above `Pry.start` in `bin/console`:
76
+
77
+ ```rb
78
+ LastpassCLI.configure do |config|
79
+ config.username = "myLastpassUsername"
80
+ config.password = "My LastPass passw0rd!"
81
+ end
82
+ ```
83
+
84
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
85
+
86
+ ## Contributing
87
+
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/QuantifiAi/lastpass-cli.
89
+
90
+
91
+ ## License
92
+
93
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lastpass-cli"
5
+ require "pry"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+ # initializer
10
+
11
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ class LastpassCliGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ m.file 'lastpass_cli.rb', 'config/initializers/lastpass_cli.rb'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ # LastPass CLI Global Configuration
2
+ #
3
+ # Use this to set up shared configuration options for your entire application.
4
+ #
5
+ # To learn more, check out the README:
6
+ #
7
+ # https://github.com/QuantifiAi/lastpass-cli-ruby/blob/master/README.md
8
+
9
+ LastpassCLI.configure do |config|
10
+ # Credentials of the LastPass account to sync with
11
+ # Stored in an environment variable, by default
12
+ config.username = ENV['LASTPASS_EMAIL']
13
+ config.password = ENV['LASTPASS_PASSWORD']
14
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lastpass-cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lastpass-cli"
8
+ spec.version = LastpassCLI::VERSION
9
+ spec.authors = ["David Jones", "Dave Strus"]
10
+ spec.email = ["unixmonkey1@gmail.com", "dave@getfretless.com"]
11
+
12
+ spec.summary = %q{A Ruby wrapper for the LastPass CLI}
13
+ spec.description = %q{A Ruby wrapper for the LastPass CLI}
14
+ spec.homepage = "https://github.com/QuantifiAi/lastpass-cli-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ spec.add_development_dependency "pry", "~> 0.11"
28
+ end
@@ -0,0 +1,11 @@
1
+ if defined?(Rails) && Rails::VERSION::MAJOR != 2
2
+
3
+ # Rails3 generator invoked with 'rails generate lastpass_cli'
4
+ class LastpassCliGenerator < Rails::Generators::Base
5
+ source_root(File.expand_path(File.dirname(__FILE__) + '/../../generators/lastpass_cli/templates'))
6
+ def copy_initializer
7
+ copy_file 'lastpass_cli.rb', 'config/initializers/lastpass_cli.rb'
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,66 @@
1
+ require "lastpass-cli/version"
2
+ require "lastpass-cli/configuration"
3
+ require "lastpass-cli/agent"
4
+ require "lastpass-cli/command"
5
+ require "lastpass-cli/item"
6
+
7
+ module LastpassCLI
8
+ def self.configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def self.reset_configuration!
13
+ @configuration = Configuration.new
14
+ end
15
+
16
+ def self.configure
17
+ yield(configuration)
18
+ end
19
+
20
+ def self.items
21
+ items = []
22
+ out = Command.run(Command.new.ls)
23
+ if !out.nil? && out != ""
24
+ out.each_line do |line|
25
+ match_data = line.match(/(?<modified_at>\d{4}-\d{2}-\d{2} \d{2}:\d{2}) (?<folder>.+)\/(?<name>.+) \[id: (?<id>.*)\] \[username:\s?(?<username>.+)\]/)
26
+ attributes = Hash[match_data.names.zip(match_data.captures)]
27
+ items << Item.new(attributes)
28
+ end
29
+ end
30
+ items
31
+ end
32
+
33
+ def self.show(name)
34
+ items = []
35
+ out = Command.run(Command.new.show(name: name))
36
+ if !out.nil? && out != "" && !out.start_with?("Error: ")
37
+ out.each_line do |line|
38
+ id_match = line.match(/^((?<folder>.*)\/)?(?<name>.*) \[id: (?<id>.*)\]/)
39
+ if id_match
40
+ items << Item.new(id: id_match[:id], folder: id_match[:folder], name: id_match[:name])
41
+ else
42
+ match_data = line.match(/^(?<key>.*): (?<value>.*)$/)
43
+ items.last.set(match_data[:key].downcase, match_data[:value])
44
+ end
45
+ end
46
+ end
47
+ items
48
+ end
49
+
50
+ def self.add_password(name, username:, password:, notes: nil, url: nil)
51
+ stdin_data = "Username:#{username}\nPassword:#{password}\n"
52
+ stdin_data << "URL:#{url}\n" if url
53
+ stdin_data << "Notes:\n#{notes}\n" if notes
54
+ Command.run(Command.new.add(name: name), stdin_data: stdin_data)
55
+ show(name)
56
+ end
57
+
58
+ def self.add_note(name, note_type: nil, notes: nil, data: {})
59
+ stdin_data = ""
60
+ data.each do |field, value|
61
+ stdin_data << "#{field.capitalize}:#{value}\n"
62
+ end
63
+ stdin_data << "Notes:\n#{notes}\n"
64
+ Command.run(Command.new.add(name: name, note_type: note_type), stdin_data: stdin_data)
65
+ end
66
+ end
@@ -0,0 +1,40 @@
1
+ module LastpassCLI
2
+ class Agent
3
+ attr_reader :logged_in, :config
4
+
5
+ def initialize
6
+ @config = LastpassCLI.configuration
7
+ end
8
+
9
+ def login
10
+ return true if logged_in?
11
+ command = [config.executable]
12
+ command += Command.new.login(username: config.username)
13
+ out, _, _ = Open3.capture2e(
14
+ { 'LPASS_DISABLE_PINENTRY' => '1' },
15
+ *command,
16
+ stdin_data: "#{config.password}\n"
17
+ )
18
+ !!out.match('Success: Logged in')
19
+ end
20
+
21
+ def logout
22
+ return true if logged_out?
23
+ command = [config.executable]
24
+ command += Command.new.logout
25
+ out, _, _ = Open3.capture2e(*command)
26
+ !!out.match('Log out: complete')
27
+ end
28
+
29
+ def logged_in?
30
+ command = [config.executable]
31
+ command += Command.new.status
32
+ out, _, _ = Open3.capture2e(*command)
33
+ !!out.match('Logged in as')
34
+ end
35
+
36
+ def logged_out?
37
+ !logged_in?
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,58 @@
1
+ require 'open3'
2
+
3
+ module LastpassCLI
4
+ class Command
5
+ def self.run(args, stdin_data: nil)
6
+ raise unless Agent.new.login
7
+ command = [LastpassCLI.configuration.executable]
8
+ command += args
9
+ out, _, _ = Open3.capture2e(*command, stdin_data: stdin_data)
10
+ out
11
+ rescue StandardError => e
12
+ raise "Failed to execute:\n#{command}\nError: #{e}"
13
+ end
14
+
15
+ def login(username:, trust: false, plaintext_key: false, force: false)
16
+ args = ['login', username]
17
+ args << '--plaintext-key' if plaintext_key
18
+ args << '--force' if force
19
+ args
20
+ end
21
+
22
+ def logout(force: true)
23
+ args = ['logout']
24
+ args << '--force' if force
25
+ args
26
+ end
27
+
28
+ def ls(sync: 'now')
29
+ raise unless %w[auto now no].include?(sync)
30
+ args = ['ls', '--long']
31
+ args << "--sync=#{sync}"
32
+ args
33
+ end
34
+
35
+ def status(quiet: false)
36
+ args = ['status']
37
+ args << '--quiet' if quiet
38
+ args
39
+ end
40
+
41
+ def show(name:, sync: 'now', expand_multi: true)
42
+ raise unless %w[auto now no].include?(sync)
43
+ args = ['show', '--all']
44
+ args << "--sync=#{sync}"
45
+ args << '--expand-multi' if expand_multi
46
+ args << name
47
+ args
48
+ end
49
+
50
+ def add(name:, sync: 'now', note_type: nil)
51
+ raise unless %w[auto now no].include?(sync)
52
+ args = ['add', '--non-interactive']
53
+ args << "--sync=#{sync}"
54
+ args << "--note-type=#{note_type}" if note_type
55
+ args << name
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,9 @@
1
+ module LastpassCLI
2
+ class Configuration
3
+ attr_accessor :username, :password, :executable
4
+
5
+ def initialize
6
+ @executable = 'lpass'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ module LastpassCLI
2
+ class Item
3
+ def self.attributes
4
+ %w[id name folder username modified_at password notes number url]
5
+ end
6
+
7
+ attr_accessor *attributes
8
+
9
+ def initialize(attrs)
10
+ attrs.each do |k, v|
11
+ set(k.to_s, v)
12
+ end
13
+ end
14
+
15
+ def set(attribute, value)
16
+ if self.class.attributes.include?(attribute)
17
+ send("#{attribute}=", value)
18
+ end
19
+ end
20
+
21
+ def to_h
22
+ self.class.attributes.each_with_object({}) do |attr, hsh|
23
+ hsh[attr] = send(attr)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module LastpassCLI
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lastpass-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - David Jones
8
+ - Dave Strus
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-12-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.13'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.13'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '5.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '5.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.11'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.11'
70
+ description: A Ruby wrapper for the LastPass CLI
71
+ email:
72
+ - unixmonkey1@gmail.com
73
+ - dave@getfretless.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - generators/lastpass_cli/lastpass_cli_generator.rb
87
+ - generators/lastpass_cli/templates/lastpass_cli.rb
88
+ - lastpass-cli.gemspec
89
+ - lib/generators/lastpass_cli_generator.rb
90
+ - lib/lastpass-cli.rb
91
+ - lib/lastpass-cli/agent.rb
92
+ - lib/lastpass-cli/command.rb
93
+ - lib/lastpass-cli/configuration.rb
94
+ - lib/lastpass-cli/item.rb
95
+ - lib/lastpass-cli/version.rb
96
+ homepage: https://github.com/QuantifiAi/lastpass-cli-ruby
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.6.14
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: A Ruby wrapper for the LastPass CLI
120
+ test_files: []