opr 0.2.0 → 0.3.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/README.adoc +19 -10
- data/lib/rubyists::opr/cli.rb +14 -0
- data/lib/rubyists::opr/commands/gen.rb +2 -1
- data/lib/rubyists::opr/commands/get.rb +1 -1
- data/lib/rubyists::opr/commands/rm.rb +34 -0
- data/lib/rubyists::opr/commands/templates/gen/login.erb +19 -0
- data/lib/rubyists::opr/model/item.rb +27 -3
- data/lib/rubyists::opr/model/vault.rb +11 -7
- data/lib/rubyists::opr/templates/rm/.gitkeep +1 -0
- data/lib/rubyists::opr/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60b9ea300b10f0bfe13e5b0920a77858e1368d6c5f03e3611867fc09e9d5d151
|
4
|
+
data.tar.gz: b2f3ade43eecbfab25e0bf21d2f21bbf99e7935b3f60a1ad3d1f10bc8ddd7d47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59469077a64f27f07802049b2a1213b9ea32856230cd74a11c3d8673d60ef5c6ab920fb10d3af457ee28f169df52eab120bd792fe5492130304fc5df1da53cb4
|
7
|
+
data.tar.gz: ac4b903311d32d13afa1c14957e2ca0f19419dfddca70e61da4a9b55552ac0c2ccb120b1a94832159f8e59ef9e8deac7905765f000893db1bcb6984fe9d45a02
|
data/README.adoc
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# Opr
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This gem supplies the `opr` binary, which wraps the 1password `op` cli from https://1password.com/downloads/command-line/.
|
4
|
+
The goal of opr is to be as compatible as possible with the `pass` cli from https://www.passwordstore.org/.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
9
8
|
Add this line to your application's Gemfile:
|
10
9
|
|
11
10
|
```ruby
|
12
|
-
gem '
|
11
|
+
gem 'opr'
|
13
12
|
```
|
14
13
|
|
15
14
|
And then execute:
|
@@ -18,11 +17,21 @@ And then execute:
|
|
18
17
|
|
19
18
|
Or install it yourself as:
|
20
19
|
|
21
|
-
$ gem install
|
20
|
+
$ gem install opr
|
22
21
|
|
23
22
|
## Usage
|
24
23
|
|
25
|
-
|
24
|
+
- `opr --help`
|
25
|
+
- `opr list vaults` List all vaults
|
26
|
+
- `opr list items --vault=SomeVault` List all items in SomeVault
|
27
|
+
- `opr get SomeVault/SomeItem` Get the password from SomeVault named SomeItem. This should be piped to xclip/pbcopy.
|
28
|
+
- `opr gen` Generate a new password (8-16 characters)
|
29
|
+
- `echo "\#@%!" | opr gen` Generate a new password, using only "#@%!" as "special" characters.
|
30
|
+
- `opr gen -s15` Generate a new password, 15 chars long
|
31
|
+
- `opr gen -s15 NewItem` Generate a new password, 15 chars long, save as "NewItem" in vault "Private"
|
32
|
+
- `opr gen -m15 -M20 NewItem --vault=MyVault` Generate a new password, 15-20 chars long, save as "NewItem" in vault "MyVault"
|
33
|
+
- `opr rm NewItem --vault=MyVault` Remove the item 'NewItem' from vault 'MyVault'
|
34
|
+
- `opr rm NewItem` Remove the item 'NewItem' from vault 'Private'
|
26
35
|
|
27
36
|
## Development
|
28
37
|
|
@@ -32,13 +41,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
41
|
|
33
42
|
## Contributing
|
34
43
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[rubyists]/opr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[rubyists]/opr/blob/master/CODE_OF_CONDUCT.md).
|
36
45
|
|
37
46
|
|
38
47
|
## Code of Conduct
|
39
48
|
|
40
|
-
Everyone interacting in the Rubyists::Opr project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[
|
49
|
+
Everyone interacting in the Rubyists::Opr project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[rubyists]/opr/blob/master/CODE_OF_CONDUCT.md).
|
41
50
|
|
42
51
|
## Copyright
|
43
52
|
|
44
|
-
Copyright (c) 2019 Tj (bougyman) Vanderpoel. See [MIT License](LICENSE.txt) for further details.
|
53
|
+
Copyright (c) 2019 Tj (bougyman) Vanderpoel. See [MIT License](LICENSE.txt) for further details.
|
data/lib/rubyists::opr/cli.rb
CHANGED
@@ -24,6 +24,20 @@ module Rubyists
|
|
24
24
|
end
|
25
25
|
map %w[--version -v] => :version
|
26
26
|
|
27
|
+
desc 'rm ITEM', 'Remove an item from a vault'
|
28
|
+
method_option :vault, aliases: '-v', type: :string,
|
29
|
+
desc: 'The vault to look for ITEM'
|
30
|
+
method_option :help, aliases: '-h', type: :boolean,
|
31
|
+
desc: 'Display usage information'
|
32
|
+
def rm(item)
|
33
|
+
if options[:help]
|
34
|
+
invoke :help, ['rm']
|
35
|
+
else
|
36
|
+
require_relative 'commands/rm'
|
37
|
+
Rubyists::Opr::Commands::Rm.new(item, options).execute
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
27
41
|
desc 'get ITEM', 'Get the contents of an item'
|
28
42
|
method_option :vault, aliases: '-v', type: :string, desc: 'Which vault the item is in'
|
29
43
|
method_option :help, aliases: '-h', type: :boolean,
|
@@ -40,7 +40,8 @@ module Rubyists
|
|
40
40
|
parsed = parse_path
|
41
41
|
Opr.with_login do
|
42
42
|
vault = Vault.find_by_name(parsed.vault)
|
43
|
-
vault.insert(
|
43
|
+
vault.insert(title: parsed.name, type: :login, password: pass,
|
44
|
+
username: options[:username], notes: options[:notes])
|
44
45
|
end
|
45
46
|
output.puts "#{parsed.name} saved in #{parsed.vault}"
|
46
47
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
|
5
|
+
module Rubyists
|
6
|
+
module Opr
|
7
|
+
# Commands namespace
|
8
|
+
module Commands
|
9
|
+
# the rm command
|
10
|
+
class Rm < Rubyists::Opr::Command
|
11
|
+
def initialize(item, options)
|
12
|
+
@item = item
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute(input: $stdin, output: $stdout) # rubocop:disable Lint/UnusedMethodArgument
|
17
|
+
vault_name = if options[:vault]
|
18
|
+
options[:vault]
|
19
|
+
else
|
20
|
+
warn 'No vault given, using "Private"'
|
21
|
+
'Private'
|
22
|
+
end
|
23
|
+
Opr.with_login do
|
24
|
+
found = Item.find(@item, vault: vault_name)
|
25
|
+
return(output.puts("No item '#{@item}' found in vault '#{vault_name}'")) if found.nil?
|
26
|
+
|
27
|
+
found.delete!
|
28
|
+
output.puts "Removed '#{@item}' from '#{vault_name}'"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"notesPlain": "<%= notes %>",
|
3
|
+
"sections": [],
|
4
|
+
"passwordHistory": [],
|
5
|
+
"fields": [
|
6
|
+
{
|
7
|
+
"value": "<%= username %>",
|
8
|
+
"name": "username",
|
9
|
+
"type": "T",
|
10
|
+
"designation": "username"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"value": "<%= password %>",
|
14
|
+
"name": "password",
|
15
|
+
"type": "P",
|
16
|
+
"designation": "password"
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}
|
@@ -10,13 +10,26 @@ module Rubyists
|
|
10
10
|
new uuid: hash['uuid'], name: hash['overview']['title'], raw: hash
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.create(hash, title, vault = 'Private', type: :login)
|
14
|
+
cmd = TTY::Command.new pty: true, printer: :null
|
15
|
+
|
16
|
+
Opr.with_login do
|
17
|
+
cmd.run "#{Opr.opbin} create item '#{type.capitalize}' '#{hash}' --vault='#{vault}' --title='#{title}'"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
13
21
|
def self.find(item, vault:)
|
14
22
|
cmd = TTY::Command.new pty: true, printer: :null
|
15
|
-
out, err =
|
23
|
+
out, err = Opr.with_login do
|
24
|
+
cmd.run "#{Opr.opbin} get item '#{item}' --vault='#{vault}'"
|
25
|
+
end
|
16
26
|
raise Error, err unless err.empty?
|
17
27
|
|
18
|
-
|
19
|
-
|
28
|
+
from_output out
|
29
|
+
rescue TTY::Command::ExitError => e
|
30
|
+
return nil if e.to_s.match? /item with query "#{Regexp.escape(item)}" not found/
|
31
|
+
|
32
|
+
raise
|
20
33
|
end
|
21
34
|
|
22
35
|
attr_reader :name, :uuid, :raw
|
@@ -26,6 +39,17 @@ module Rubyists
|
|
26
39
|
@raw = raw
|
27
40
|
end
|
28
41
|
|
42
|
+
def vault_uuid
|
43
|
+
@vault_uuid ||= raw['vaultUuid']
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete!
|
47
|
+
Opr.with_login do
|
48
|
+
cmd = TTY::Command.new pty: true, printer: :null
|
49
|
+
cmd.run "#{Opr.opbin} delete item '#{name}' --vault='#{vault_uuid}'"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
29
53
|
def password
|
30
54
|
pass_field = @raw['details']['fields'].detect { |f| f['designation'] == 'password' }
|
31
55
|
pass_field['value']
|
@@ -13,7 +13,9 @@ module Rubyists
|
|
13
13
|
|
14
14
|
def self.all
|
15
15
|
cmd = TTY::Command.new pty: true, printer: :null
|
16
|
-
out, err = cmd.run Opr.opbin, 'list', 'vaults'
|
16
|
+
out, err = Opr.with_login { cmd.run Opr.opbin, 'list', 'vaults' }
|
17
|
+
raise "Error #{err}" unless err.nil? || err.empty?
|
18
|
+
|
17
19
|
vaults = JSON.parse out
|
18
20
|
vaults.map { |v| from_hash v }
|
19
21
|
end
|
@@ -28,21 +30,23 @@ module Rubyists
|
|
28
30
|
@uuid = uuid
|
29
31
|
end
|
30
32
|
|
31
|
-
def insert(
|
32
|
-
current = Item.find(
|
33
|
-
raise "There is already an item named #{
|
33
|
+
def insert(title:, password:, type: 'login', username: nil, notes: nil)
|
34
|
+
current = Item.find(title, vault: name)
|
35
|
+
raise "There is already an item named #{title} in the #{name} vault" if current
|
34
36
|
|
35
37
|
tpl = Opr::LIBDIR.join("commands/templates/gen/#{type}.erb")
|
36
38
|
erb = ERB.new(tpl.read)
|
37
|
-
|
38
|
-
Item.create
|
39
|
+
json = erb.result(binding)
|
40
|
+
Item.create(json, title, name, type: :login)
|
39
41
|
end
|
40
42
|
|
41
43
|
def items
|
42
44
|
return @items if @items
|
43
45
|
|
44
46
|
cmd = TTY::Command.new pty: true, printer: :null
|
45
|
-
out, err = cmd.run "#{Opr.opbin} list items --vault='#{name}'"
|
47
|
+
out, err = Opr.with_login { cmd.run "#{Opr.opbin} list items --vault='#{name}'" }
|
48
|
+
raise "Error #{err}" unless err.nil? || err.empty?
|
49
|
+
|
46
50
|
array = JSON.parse out
|
47
51
|
@items = array.map { |h| Item.from_hash h }
|
48
52
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tj (bougyman) Vanderpoel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -180,6 +180,8 @@ files:
|
|
180
180
|
- lib/rubyists::opr/commands/list.rb
|
181
181
|
- lib/rubyists::opr/commands/list/items.rb
|
182
182
|
- lib/rubyists::opr/commands/list/vaults.rb
|
183
|
+
- lib/rubyists::opr/commands/rm.rb
|
184
|
+
- lib/rubyists::opr/commands/templates/gen/login.erb
|
183
185
|
- lib/rubyists::opr/model/item.rb
|
184
186
|
- lib/rubyists::opr/model/vault.rb
|
185
187
|
- lib/rubyists::opr/templates/.gitkeep
|
@@ -188,6 +190,7 @@ files:
|
|
188
190
|
- lib/rubyists::opr/templates/get/.gitkeep
|
189
191
|
- lib/rubyists::opr/templates/list/items/.gitkeep
|
190
192
|
- lib/rubyists::opr/templates/list/vaults/.gitkeep
|
193
|
+
- lib/rubyists::opr/templates/rm/.gitkeep
|
191
194
|
- lib/rubyists::opr/utils.rb
|
192
195
|
- lib/rubyists::opr/version.rb
|
193
196
|
- rubyists::opr.gemspec
|