one_pass 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.markdown +1 -1
- data/lib/OnePass/application.rb +34 -13
- data/lib/OnePass/cli.rb +6 -5
- data/lib/OnePass/password.rb +10 -10
- data/lib/OnePass/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f2bcb52f001a05838904a9be14b38bae3dd1838
|
4
|
+
data.tar.gz: 1f656e5330fb00832e47aed98a89d17071374317
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22e33d577ee5caa98095f025de437a5d38dfea09e44eb3e0fbb08ac655477e2426fe1f03d115530eb94be018d89d38745bf566a8efcaecbf93eb1efea61753ad
|
7
|
+
data.tar.gz: 76e0424fd775a338e2665db91edb45ac23ca86f149065ad38d1f669c4eca191e50dbe3550fcb622f2b7e991b1cd43add78c9e6f7d7dec364642293b8c7554674
|
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -16,7 +16,7 @@ gem install one_pass
|
|
16
16
|
|
17
17
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
18
18
|
|
19
|
-
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).
|
19
|
+
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`, commit, 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).
|
20
20
|
|
21
21
|
## Contributing
|
22
22
|
|
data/lib/OnePass/application.rb
CHANGED
@@ -1,28 +1,41 @@
|
|
1
|
+
require "English"
|
2
|
+
|
1
3
|
module OnePass
|
2
4
|
# OnePass Application
|
3
5
|
class Application
|
4
|
-
CONFIG_PATH='~/.one_pass'
|
6
|
+
CONFIG_PATH = '~/.one_pass'.freeze
|
5
7
|
|
6
8
|
def initialize(vault_path = nil)
|
7
9
|
@vault_path = get_vault vault_path
|
8
10
|
@vault = OpVault.new @vault_path
|
9
11
|
|
10
|
-
|
12
|
+
check_for_dependencies
|
11
13
|
prompter = OnePass::Password.new(vault_path: @vault_path)
|
14
|
+
password_loop prompter
|
15
|
+
ensure
|
16
|
+
prompter && prompter.done
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_for_dependencies
|
20
|
+
unless installed? 'pinentry --version'
|
21
|
+
puts 'Please install the `pinentry` program.'
|
22
|
+
puts ' on macOS, we recommend using Homebrew: `brew install pinentry`.'
|
23
|
+
exit 127
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def password_loop(prompter)
|
28
|
+
error_message = nil
|
12
29
|
loop do
|
13
30
|
password = prompter.prompt error_message
|
14
31
|
exit if password.nil? # cancelled
|
15
32
|
begin
|
16
|
-
@vault.unlock password
|
17
|
-
@vault.load_items
|
33
|
+
@vault.unlock password && @vault.load_items
|
18
34
|
break
|
19
35
|
rescue => error
|
20
36
|
error_message = error.message
|
21
|
-
next
|
22
37
|
end
|
23
38
|
end
|
24
|
-
ensure
|
25
|
-
prompter.done
|
26
39
|
end
|
27
40
|
|
28
41
|
def get_vault(vault_path = nil)
|
@@ -39,11 +52,11 @@ module OnePass
|
|
39
52
|
item = @vault.find(/#{query}/i).first
|
40
53
|
data = @vault.item_overview item
|
41
54
|
unless %i( uuid url title ).include? reply_type
|
42
|
-
|
55
|
+
data.merge!(@vault.item_detail(item))
|
43
56
|
end
|
44
57
|
|
45
58
|
case reply_type
|
46
|
-
when
|
59
|
+
when %i( uuid url title )
|
47
60
|
data[reply_type.to_s]
|
48
61
|
when :username
|
49
62
|
data['fields'].find({}) { |field| field['designation'] == 'username' }['value']
|
@@ -56,19 +69,27 @@ module OnePass
|
|
56
69
|
|
57
70
|
def search(query)
|
58
71
|
@vault.find(/#{query}/i).collect do |item|
|
59
|
-
data = (@vault.item_overview item).merge(@vault.item_detail
|
72
|
+
data = (@vault.item_overview item).merge(@vault.item_detail(item))
|
60
73
|
{
|
61
74
|
uuid: data['uuid'],
|
62
75
|
title: data['title'],
|
63
|
-
username: data['fields'].find({})
|
76
|
+
username: data['fields'].find({}) do |field|
|
77
|
+
field['designation'] == 'username'
|
78
|
+
end['value']
|
64
79
|
}
|
65
80
|
end
|
66
81
|
end
|
67
82
|
|
83
|
+
def installed?(program)
|
84
|
+
`#{program}`
|
85
|
+
result = $CHILD_STATUS
|
86
|
+
result.exitstatus != 127
|
87
|
+
end
|
88
|
+
|
68
89
|
def self.save(vault_path = nil)
|
69
|
-
|
90
|
+
new vault_path # if succeeds, path & pw is good
|
70
91
|
path = File.expand_path CONFIG_PATH
|
71
|
-
File.open path, File::CREAT|File::TRUNC|File::RDWR do |file|
|
92
|
+
File.open path, File::CREAT | File::TRUNC | File::RDWR do |file|
|
72
93
|
file.write "path=#{File.expand_path vault_path}\n"
|
73
94
|
end
|
74
95
|
end
|
data/lib/OnePass/cli.rb
CHANGED
@@ -7,12 +7,12 @@ require 'OnePass/password'
|
|
7
7
|
module OnePass
|
8
8
|
# OnePass CLI
|
9
9
|
class CLI < Thor
|
10
|
-
SHOW_OPTIONS = %w( all username password url uuid title )
|
10
|
+
SHOW_OPTIONS = %w( all username password url uuid title ).freeze
|
11
11
|
|
12
|
-
map %w
|
13
|
-
desc
|
12
|
+
map %w(--version -v) => :__version
|
13
|
+
desc '--version, -v', 'Print the current version'
|
14
14
|
def __version
|
15
|
-
puts "#{File.basename $
|
15
|
+
puts "#{File.basename $PROGRAM_NAME} version #{OnePass::VERSION}"
|
16
16
|
end
|
17
17
|
|
18
18
|
desc 'login', 'Save a 1Password vault and verify password'
|
@@ -31,6 +31,7 @@ module OnePass
|
|
31
31
|
SHOW_OPTIONS.each do |switch|
|
32
32
|
option switch.to_sym, type: :boolean
|
33
33
|
end
|
34
|
+
|
34
35
|
def show(name)
|
35
36
|
# Check for multiple mutex args
|
36
37
|
type = SHOW_OPTIONS.each_with_object(Hash.new) do |k, hash|
|
@@ -57,7 +58,7 @@ module OnePass
|
|
57
58
|
desc 'search QUERY', 'Perform fuzzy search for items in your vault, shows uuid, title and username'
|
58
59
|
def search(query)
|
59
60
|
app = OnePass::Application.new
|
60
|
-
puts JSON.pretty_generate(app.search
|
61
|
+
puts JSON.pretty_generate(app.search(query))
|
61
62
|
end
|
62
63
|
|
63
64
|
map ls: :list
|
data/lib/OnePass/password.rb
CHANGED
@@ -3,15 +3,17 @@ require 'ttyname'
|
|
3
3
|
module OnePass
|
4
4
|
# Fork out to `pinentry` for password
|
5
5
|
class Password
|
6
|
-
DESCRIPTION = 'Please enter your 1Password master password for the following vault:'
|
6
|
+
DESCRIPTION = 'Please enter your 1Password master password for the following vault:'.freeze
|
7
7
|
DEFAULT = {
|
8
8
|
title: '1Password CLI',
|
9
9
|
prompt: 'Master Password: '
|
10
|
-
}
|
10
|
+
}.freeze
|
11
11
|
|
12
12
|
def initialize(opts = {})
|
13
13
|
@config = OpenStruct.new DEFAULT.merge(opts)
|
14
|
-
|
14
|
+
if @config.vault_path
|
15
|
+
@config.description ||= "#{DESCRIPTION}%0a#{@config.vault_path}"
|
16
|
+
end
|
15
17
|
end
|
16
18
|
|
17
19
|
def prompt(error_message = nil)
|
@@ -19,7 +21,7 @@ module OnePass
|
|
19
21
|
@pipe = IO.popen 'pinentry', 'r+'
|
20
22
|
check
|
21
23
|
send_settings
|
22
|
-
|
24
|
+
fetch_password
|
23
25
|
@password
|
24
26
|
end
|
25
27
|
|
@@ -41,15 +43,13 @@ module OnePass
|
|
41
43
|
option 'display', ENV['DISPLAY']
|
42
44
|
end
|
43
45
|
|
44
|
-
def
|
46
|
+
def fetch_password
|
45
47
|
@password = ''
|
46
48
|
send 'GETPIN'
|
47
|
-
|
49
|
+
loop do
|
48
50
|
case response = @pipe.gets
|
49
|
-
when /^D .*/
|
50
|
-
|
51
|
-
when /^OK/
|
52
|
-
break
|
51
|
+
when /^D .*/ then @password = response[2..-1].chomp
|
52
|
+
when /^OK/ then break
|
53
53
|
else
|
54
54
|
@password = nil
|
55
55
|
break
|
data/lib/OnePass/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: one_pass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Voltz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04
|
11
|
+
date: 2016-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|