opr21 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +20 -0
- data/README.md +30 -0
- data/bin/set_env +8 -0
- data/change_log.md +5 -0
- data/opr21.gemspec +14 -0
- data/opr21.rb +76 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3c2512cc5e2ff8f6ea5e209ffdc0ffdceabe01b3f6b1e5c7faed83b2f81d5f5f
|
4
|
+
data.tar.gz: dffba41888e93b3728fa9542da76b049fc6e21a27b8d0d84d33f5a126740a272
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 365577f30ad6f02b41bc722bd6022a040c85825283491569dd100057597de6928486bd561b6b1a5191ef6e83936ea63ef22ab37df8ec580841610be0a9048d99
|
7
|
+
data.tar.gz: aac1787be2c47f878bf07f440455e523403a356ee84ad6e83987dcc56c7bad8f373ab9cc3d65351883654af0f237b77a3e3fec39ff4948c9cf20d19e4b50c41e
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2021 Oliver Gaida - MediaBEAM GmbH
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
# yet another onepassword wrapper in 2021
|
3
|
+
|
4
|
+
get your items from 1password in ruby.
|
5
|
+
|
6
|
+
# synopsis
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
unless ENV.has_key?"ONEPASSWORD"
|
10
|
+
puts "env-var ONEPASSWORD is missing"
|
11
|
+
else
|
12
|
+
load "opr21.rb"
|
13
|
+
op = Opr21.new(ENV["ONEPASSWORD"], {:domain => "your-domain", :email => "your-email", :secret => "your-secret"})
|
14
|
+
opv = op.getItem "your-item-title"
|
15
|
+
puts opv["website"]
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
# installation
|
20
|
+
|
21
|
+
just install the gem:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
gem install opr21
|
25
|
+
```
|
26
|
+
|
27
|
+
# external tools / requirements
|
28
|
+
|
29
|
+
Download the op commandlinetool for 1password.
|
30
|
+
|
data/bin/set_env
ADDED
data/opr21.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'opr21'
|
3
|
+
spec.version = '0.1'
|
4
|
+
spec.date = '2021-04-14'
|
5
|
+
spec.summary = "yet another onepassword wrapper in 2021"
|
6
|
+
spec.description = "get your items from 1password"
|
7
|
+
spec.authors = ["Oliver Gaida"]
|
8
|
+
spec.email = 'oliver.gaida@mediabeam.com'
|
9
|
+
spec.files = `git ls-files`.split($/)
|
10
|
+
spec.homepage = 'https://github.com/ogaida/opr21'
|
11
|
+
#spec.executables = %w(rusdc)
|
12
|
+
spec.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
end
|
data/opr21.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
class Opr21
|
7
|
+
|
8
|
+
# set initial credentials if required...
|
9
|
+
CREDENTIALS={
|
10
|
+
:domain => "mydom.1password.eu",
|
11
|
+
:email => "myuser@mydom.com",
|
12
|
+
:secret => "12-123456-123456-123456-123456-123456-123456"
|
13
|
+
}
|
14
|
+
|
15
|
+
attr_reader :expiration_date, :tempfile, :password
|
16
|
+
attr_writer :debug
|
17
|
+
|
18
|
+
def initialize(password, hash={})
|
19
|
+
@password = password
|
20
|
+
@debug = false
|
21
|
+
@tempfile = Tempfile.new('op')
|
22
|
+
check_creds(hash)
|
23
|
+
end
|
24
|
+
|
25
|
+
def op(*args)
|
26
|
+
check_creds()
|
27
|
+
cmd = %(. #{tempfile.path} ; op "#{args.join('" "')}")
|
28
|
+
puts cmd if @debug
|
29
|
+
output = `#{cmd}`
|
30
|
+
puts output if @debug
|
31
|
+
JSON.parse(output)
|
32
|
+
end
|
33
|
+
|
34
|
+
# gibt die Werte des ersten Elementes mit entsprechenden Namen
|
35
|
+
def getItem(name, fields = "website,username,title,password", vault = "Private")
|
36
|
+
all = self.op "list", "items", "--vault", vault
|
37
|
+
arr = all.select{|i| i["overview"]["title"] =~ /#{name}/i}
|
38
|
+
if arr.class == Array
|
39
|
+
self.op "get", "item", arr[0]["uuid"], "--fields", fields
|
40
|
+
else
|
41
|
+
{}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# gibt eine Liste von item.titles aus die matchen
|
46
|
+
def getItemList(regex, vault = "Private")
|
47
|
+
all = self.op "list", "items", "--vault", vault
|
48
|
+
arr = all.select{|i| i["overview"]["title"] =~ /#{regex}/i}
|
49
|
+
return_arr = []
|
50
|
+
if arr.class == Array
|
51
|
+
arr.each do |item|
|
52
|
+
return_arr << item["overview"]["title"]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
return_arr
|
56
|
+
end
|
57
|
+
|
58
|
+
def debug= (debug)
|
59
|
+
@debug = debug
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def check_creds(hash={})
|
65
|
+
hash = CREDENTIALS.update hash
|
66
|
+
if system(". #{tempfile.path} ;op get account > /dev/null 2>&1")
|
67
|
+
# noch ok
|
68
|
+
@expiration_date = Time.at(Time.now.to_i + 30*60)
|
69
|
+
else
|
70
|
+
# neu einloggen
|
71
|
+
system("echo '#{password}' | op signin #{CREDENTIALS[:domain]} #{CREDENTIALS[:email]} #{CREDENTIALS[:secret]} > #{@tempfile.path}")
|
72
|
+
puts "session saved in #{tempfile.path}" if @debug
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opr21
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oliver Gaida
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.1.0
|
33
|
+
description: get your items from 1password
|
34
|
+
email: oliver.gaida@mediabeam.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- LICENSE.md
|
40
|
+
- README.md
|
41
|
+
- bin/set_env
|
42
|
+
- change_log.md
|
43
|
+
- opr21.gemspec
|
44
|
+
- opr21.rb
|
45
|
+
homepage: https://github.com/ogaida/opr21
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.1.2
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: yet another onepassword wrapper in 2021
|
68
|
+
test_files: []
|