onetime 0.5.1 → 0.6.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.
data/lib/onetime.rb ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "onetime/version"
4
+ require_relative "onetime/errors"
5
+ require_relative "onetime/configuration"
6
+ require_relative "onetime/response"
7
+ require_relative "onetime/transport"
8
+ require_relative "onetime/client"
9
+
10
+ # Onetime is the official Ruby client for the OnetimeSecret API.
11
+ #
12
+ # It supports the v1 and v2 APIs over a zero-dependency, stdlib-only
13
+ # transport. See Onetime::Client for the primary interface.
14
+ #
15
+ # require "onetime"
16
+ #
17
+ # client = Onetime::Client.new(
18
+ # base_url: "https://ca.onetimesecret.com",
19
+ # customer: "ur1abc23def",
20
+ # api_token: ENV["ONETIME_API_TOKEN"],
21
+ # api_version: :v2,
22
+ # )
23
+ # res = client.secrets.conceal(secret: "hunter2", ttl: 3600)
24
+ # res.dig("record", "secret", "secret_value")
25
+ module Onetime
26
+ # Convenience constructor mirroring Onetime::Client.new.
27
+ #
28
+ # Onetime.client(base_url: "https://ca.onetimesecret.com",
29
+ # customer: "ur1abc23def", api_token: "...")
30
+ def self.client(**options)
31
+ Client.new(**options)
32
+ end
33
+ end
metadata CHANGED
@@ -1,132 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onetime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
5
- prerelease:
4
+ version: 0.6.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Delano Mandelbaum
9
- autorequire:
10
8
  bindir: bin
11
- cert_chain:
12
- - !binary |-
13
- LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUROakNDQWg2Z0F3SUJB
14
- Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREJCTVE4d0RRWURWUVFEREFaa1pX
15
- eGgKYm04eEdUQVhCZ29Ka2lhSmsvSXNaQUVaR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haUhZZ0YvOS9va3k3WloKUjlxMC90Sm5ldWhBZW5aZGlRa1g3b2k0TzN2
33
- OXdSUzZZSG9XQnhNUEZLVlJMTlR6dlZKc2JtZnBDQWxwNS81ZwpwczR3UUZ5
34
- NW1pYkVsR1ZsT29iZi9naHFaMjVIUzlKNmtkMC9DL3J5MEFVdFRvZ3NMN1R4
35
- R3dUNGtiQ3g2M3ViCjN2eXdFRWhzSlV6ZmQ5N0dDQUJtdFFmUlRsZFgvajdG
36
- MXovNXdkOHAraGZkb3gxaWliZHM5WnRmYVpBM0t6S24Ka2NoV045QjZ6Zzly
37
- MVhNUThCTTJKejBYb1BhblBlMzU0K2xXd2pwa1JLYkZvdy9aYlFIY0NMQ3Ey
38
- NCtONmI2ZwpkZ0tmTkR6d2lEcHFDQT09Ci0tLS0tRU5EIENFUlRJRklDQVRF
39
- LS0tLS0K
40
- date: 2013-02-12 00:00:00.000000000 Z
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
41
11
  dependencies:
42
12
  - !ruby/object:Gem::Dependency
43
- name: drydock
13
+ name: minitest
44
14
  requirement: !ruby/object:Gem::Requirement
45
- none: false
46
15
  requirements:
47
- - - ! '>='
16
+ - - "~>"
48
17
  - !ruby/object:Gem::Version
49
- version: 0.6.9
50
- type: :runtime
18
+ version: '5.0'
19
+ type: :development
51
20
  prerelease: false
52
21
  version_requirements: !ruby/object:Gem::Requirement
53
- none: false
54
22
  requirements:
55
- - - ! '>='
23
+ - - "~>"
56
24
  - !ruby/object:Gem::Version
57
- version: 0.6.9
25
+ version: '5.0'
58
26
  - !ruby/object:Gem::Dependency
59
- name: httparty
27
+ name: rake
60
28
  requirement: !ruby/object:Gem::Requirement
61
- none: false
62
29
  requirements:
63
- - - ! '>='
30
+ - - "~>"
64
31
  - !ruby/object:Gem::Version
65
- version: 0.7.7
66
- type: :runtime
32
+ version: '13.0'
33
+ type: :development
67
34
  prerelease: false
68
35
  version_requirements: !ruby/object:Gem::Requirement
69
- none: false
70
36
  requirements:
71
- - - ! '>='
37
+ - - "~>"
72
38
  - !ruby/object:Gem::Version
73
- version: 0.7.7
74
- - !ruby/object:Gem::Dependency
75
- name: json
76
- requirement: !ruby/object:Gem::Requirement
77
- none: false
78
- requirements:
79
- - - ! '>='
80
- - !ruby/object:Gem::Version
81
- version: 1.6.8
82
- type: :runtime
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ! '>='
88
- - !ruby/object:Gem::Version
89
- version: 1.6.8
90
- description: Command-line tool and library for onetimesecret.com API
91
- email: delano@onetimesecret.com
92
- executables:
93
- - onetime
39
+ version: '13.0'
40
+ description: A dependency-free Ruby client for the OnetimeSecret API, supporting the
41
+ v1 and v2 API versions.
42
+ email:
43
+ - gems@onetimesecret.com
44
+ executables: []
94
45
  extensions: []
95
- extra_rdoc_files:
96
- - LICENSE.txt
97
- - README.md
46
+ extra_rdoc_files: []
98
47
  files:
99
48
  - CHANGES.txt
100
49
  - LICENSE.txt
101
50
  - README.md
102
- - Rakefile
103
- - VERSION
104
- - bin/onetime
105
- - gem-public_cert.pem
106
- - lib/onetime/api.rb
107
- - onetime.gemspec
51
+ - lib/onetime.rb
52
+ - lib/onetime/client.rb
53
+ - lib/onetime/configuration.rb
54
+ - lib/onetime/errors.rb
55
+ - lib/onetime/resources/receipts.rb
56
+ - lib/onetime/resources/secrets.rb
57
+ - lib/onetime/response.rb
58
+ - lib/onetime/transport.rb
59
+ - lib/onetime/version.rb
108
60
  homepage: https://github.com/onetimesecret/onetime-ruby
109
- licenses: []
110
- post_install_message:
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ source_code_uri: https://github.com/onetimesecret/onetime-ruby
65
+ bug_tracker_uri: https://github.com/onetimesecret/onetime-ruby/issues
66
+ documentation_uri: https://docs.onetimesecret.com/
67
+ changelog_uri: https://github.com/onetimesecret/onetime-ruby/blob/main/CHANGES.txt
68
+ rubygems_mfa_required: 'true'
111
69
  rdoc_options: []
112
70
  require_paths:
113
71
  - lib
114
72
  required_ruby_version: !ruby/object:Gem::Requirement
115
- none: false
116
73
  requirements:
117
- - - ! '>='
74
+ - - ">="
118
75
  - !ruby/object:Gem::Version
119
- version: '0'
76
+ version: '3.1'
120
77
  required_rubygems_version: !ruby/object:Gem::Requirement
121
- none: false
122
78
  requirements:
123
- - - ! '>='
79
+ - - ">="
124
80
  - !ruby/object:Gem::Version
125
81
  version: '0'
126
82
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 1.8.25
129
- signing_key:
130
- specification_version: 3
131
- summary: Command-line tool and library for onetimesecret.com API
83
+ rubygems_version: 3.6.9
84
+ specification_version: 4
85
+ summary: Official Ruby client for the OnetimeSecret API
132
86
  test_files: []
data/Rakefile DELETED
@@ -1,50 +0,0 @@
1
- require "rubygems"
2
- require "rake"
3
- require "rake/clean"
4
- require "rdoc/task"
5
-
6
- task :default => ["build"]
7
- CLEAN.include [ 'pkg', 'rdoc' ]
8
- name = "onetime/api"
9
-
10
- $:.unshift File.join(File.dirname(__FILE__), 'lib')
11
- require name
12
- version = Onetime::API::VERSION.to_s
13
-
14
- begin
15
- require "jeweler"
16
- Jeweler::Tasks.new do |s|
17
- s.version = version
18
- s.name = "onetime"
19
- s.executables = ['onetime']
20
- s.summary = "Command-line tool and library for onetimesecret.com API"
21
- s.description = "Command-line tool and library for onetimesecret.com API"
22
- s.email = "delano@onetimesecret.com"
23
- s.homepage = "https://github.com/onetimesecret/onetime-ruby"
24
- s.authors = ["Delano Mandelbaum"]
25
- s.add_dependency('drydock', '>= 0.6.9')
26
- s.add_dependency('httparty', '>= 0.7.7')
27
- s.add_dependency('json', '>= 1.6.8')
28
-
29
- s.signing_key = File.join('/mnt/gem/', 'gem-private_key.pem')
30
- s.cert_chain = ['gem-public_cert.pem']
31
- end
32
- Jeweler::GemcutterTasks.new
33
- rescue LoadError
34
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
35
- end
36
-
37
- RDoc::Task.new do |rdoc|
38
- rdoc.rdoc_dir = "rdoc"
39
- rdoc.title = "#{name} #{version}"
40
- rdoc.generator = 'hanna'
41
- rdoc.main = 'README.rdoc'
42
- rdoc.rdoc_files.include("README*")
43
- rdoc.rdoc_files.include("LICENSE.txt")
44
- rdoc.rdoc_files.include("VERSION")
45
- rdoc.rdoc_files.include("bin/*.rb")
46
- rdoc.rdoc_files.include("lib/**/*.rb")
47
- end
48
-
49
-
50
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.5.1
data/bin/onetime DELETED
@@ -1,228 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- base_path = File.expand_path File.join(File.dirname(__FILE__), '..')
4
- $:.unshift File.join(base_path, 'lib')
5
-
6
- require 'uri'
7
- require 'onetime/api'
8
- require 'drydock'
9
-
10
- class Onetime::CLI
11
- class Definition
12
- extend Drydock
13
-
14
- default :share
15
-
16
- global :H, String, "Base URI (e.g. https://onetimesecret.com/api)"
17
- global :c, :custid, String, "Customer ID (e.g. you@yourcompany.com)"
18
- global :k, :apikey, String, "API key (e.g. 4eb33c6340006d6607c813fc7e707a32f8bf5342)"
19
-
20
- global :r, :recipient, Array, "Email address to deliver the secret link"
21
-
22
- global :f, :format, String, "Output format (json or yaml)"
23
- global :j, :json, "Shorthand for -f json"
24
- global :y, :yaml, "Shorthand for -f yaml"
25
- global :s, :string, "Shorthand for -f string (default)"
26
-
27
- global :D, :debug do
28
- OT::API.debug_output STDERR
29
- end
30
-
31
- global :V, :version do
32
- puts OT::API::VERSION
33
- exit 0
34
- end
35
-
36
- before do |obj|
37
- OT::API.base_uri obj.global.H if obj.global.H
38
- @api = OT::API.new obj.global.custid, obj.global.apikey
39
- obj.global.format = 'yaml' if obj.global.yaml
40
- obj.global.format = 'json' if obj.global.json
41
- obj.global.format = 'string' if obj.global.string
42
- obj.global.format = nil if obj.global.format == 'string'
43
- if obj.global.format && !['json', 'yaml', 'csv'].member?(obj.global.format)
44
- raise RuntimeError, "Unsupported format: #{obj.global.format}"
45
- end
46
- end
47
-
48
- usage "onetime status"
49
- command :status do |obj|
50
- @res = @api.get '/status'
51
- if @res.nil?
52
- raise RuntimeError, 'Could not complete request'
53
- elsif @api.response.code != 200
54
- raise RuntimeError, @res['message']
55
- end
56
- case obj.global.format
57
- when 'json'
58
- puts @res.to_json
59
- when 'yaml'
60
- puts @res.to_yaml
61
- else
62
- msg = @api.anonymous ? 'Anonymous' : @api.custid
63
- STDERR.puts '# Host: %s' % OT::API.base_uri
64
- STDERR.puts '# Account: %s' % msg
65
- puts 'Service Status: %s' % @res[:status]
66
- end
67
- end
68
-
69
- argv :key
70
- usage "onetime metadata <KEY>"
71
- command :metadata do |obj|
72
- raise RuntimeError, "csv not supported" if obj.global.format == 'csv'
73
- raise RuntimeError, "Usage: #{$0} metadata <KEY>" unless obj.argv.key
74
- @res = @api.post '/metadata/%s' % obj.argv.key
75
- if @res.nil?
76
- raise RuntimeError, 'Could not complete request'
77
- elsif @api.response.code != 200
78
- raise RuntimeError, @res['message']
79
- end
80
- case obj.global.format
81
- when 'json'
82
- puts @res.to_json
83
- when 'yaml'
84
- puts @res.to_yaml
85
- else
86
- puts @res.to_yaml
87
- end
88
- end
89
-
90
- option :p, :passphrase, String, "Passphrase to decrypt the secret (only required if one was provided to you)"
91
- argv :key
92
- usage "onetime secret <KEY>"
93
- usage "onetime secret [-p PASSPHRASE] <KEY>"
94
- command :secret do |obj|
95
- raise RuntimeError, "csv not supported" if obj.global.format == 'csv'
96
- raise RuntimeError, "Usage: #{$0} secret <KEY>" unless obj.argv.key
97
- opts = {}
98
- opts[:passphrase] = obj.option.passphrase if obj.option.passphrase
99
- base_uri = URI.parse Onetime::API.base_uri
100
- if obj.argv.key =~ /#{base_uri.hostname}\/secret\/([a-zA-Z0-9]+)/
101
- obj.argv.key = $1
102
- end
103
- @res = @api.post '/secret/%s' % [obj.argv.key], opts
104
- if @res.nil?
105
- raise RuntimeError, 'Could not complete request'
106
- elsif @api.response.code != 200
107
- raise RuntimeError, @res['message']
108
- end
109
- case obj.global.format
110
- when 'json'
111
- puts @res.to_json
112
- when 'yaml'
113
- puts @res.to_yaml
114
- else
115
- puts @res[:value] if @res
116
- end
117
- end
118
- command_alias :secret, :get
119
-
120
- usage "onetime share"
121
- usage "onetime share [-t 3600] [-p PASSPHRASE]"
122
- usage "echo 'your secret' | onetime share"
123
- usage "<path/2/file onetime share"
124
- option :t, :ttl, Integer, "Time-to-live in seconds"
125
- option :p, :passphrase, String, "Passphrase to encrypt the secret (something only you and recipient know)"
126
- option :r, :recipient, Array, "Email address to deliver the secret link"
127
- command :share do |obj|
128
- recipients = [obj.option.recipient, obj.global.recipient].flatten.compact.uniq
129
- begin
130
- if Kernel.select [$stdin], nil, nil, 0
131
- secret_value = STDIN.read
132
- else
133
- STDERR.puts "Paste message here (hit control-D to continue):"
134
- secret_value = ARGF.read
135
- STDERR.puts # new line to let the person know we got it.
136
- end
137
- rescue Interrupt => ex
138
- puts "Exiting..."
139
- exit 0
140
- end
141
- raise RuntimeError, "No secret provided" if secret_value.chomp.empty?
142
- opts = { :secret => secret_value, :ttl => obj.option.ttl, :recipient => recipients }
143
- opts[:passphrase] = obj.option.passphrase if obj.option.passphrase
144
- @res = @api.post '/share', opts
145
- if @res.nil?
146
- raise RuntimeError, 'Could not complete request'
147
- elsif @api.response.code != 200
148
- raise RuntimeError, @res['message']
149
- end
150
- uri = OT::API.web_uri('secret', @res[:secret_key])
151
- case obj.global.format
152
- when 'json'
153
- puts @res.to_json
154
- when 'yaml'
155
- puts @res.to_yaml
156
- else
157
- if @res[:recipient] && !@res[:recipient].compact.empty?
158
- STDERR.puts '# Secret link sent to: %s' % @res[:recipient].join(',')
159
- else
160
- puts uri
161
- end
162
- end
163
- end
164
-
165
- usage "onetime generate"
166
- usage "onetime generate [-t 3600] [-p PASSPHRASE]"
167
- option :t, :ttl, Integer, "Time-to-live in seconds"
168
- option :p, :passphrase, String, "Passphrase to encrypt the secret (something only you and recipient know)"
169
- option :r, :recipient, Array, "Email address to deliver the secret link"
170
- command :generate do |obj|
171
- recipients = [obj.option.recipient, obj.global.recipient].flatten.compact.uniq
172
- opts = { :ttl => obj.option.ttl, :recipient => recipients }
173
- opts[:passphrase] = obj.option.passphrase if obj.option.passphrase
174
- @res = @api.post '/generate', opts
175
- if @res.nil?
176
- raise RuntimeError, 'Could not complete request'
177
- elsif @api.response.code != 200
178
- raise RuntimeError, @res['message']
179
- end
180
- uri, secret_value = OT::API.web_uri('secret', @res[:secret_key]), @res[:value]
181
- case obj.global.format
182
- when 'json'
183
- puts @res.to_json
184
- when 'yaml'
185
- puts @res.to_yaml
186
- when 'csv'
187
- puts [secret_value,uri].join ','
188
- else
189
- msg = 'Your secret (hit return to continue): %s' % secret_value
190
- if @res[:recipient] && !@res[:recipient].compact.empty?
191
- uri = "\e[K\r# Secret link sent to: %s" % [@res[:recipient].join(',').ljust(40, ' ')]
192
- end
193
- eraser = "\e[K\r%s" % [uri] # \e[K\r
194
- print msg
195
- # Check for tty b/c if we're receiving data via STDIN, even if
196
- # we're ignoring it, the stty commands return "stdin isn't a terminal"
197
- if STDIN.tty?
198
- begin
199
- old_stty = `stty -g` # store tty settings
200
- system "stty -echo"
201
- STDIN.getc
202
- rescue Interrupt
203
- ensure
204
- system "stty echo"
205
- system "stty #{old_stty}" # restore stty settings
206
- print eraser
207
- end
208
- else
209
- puts
210
- print uri
211
- end
212
- puts
213
- end
214
- end
215
-
216
- end
217
- end
218
-
219
- begin
220
- Drydock.run! ARGV, STDIN
221
- rescue RuntimeError => ex
222
- STDERR.puts ex.message
223
- exit 1
224
- rescue => ex
225
- puts ex.message
226
- puts ex.backtrace
227
- exit 1
228
- end
data/gem-public_cert.pem DELETED
@@ -1,20 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMQ8wDQYDVQQDDAZkZWxh
3
- bm8xGTAXBgoJkiaJk/IsZAEZFglzb2x1dGlvdXMxEzARBgo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CA==
20
- -----END CERTIFICATE-----
data/lib/onetime/api.rb DELETED
@@ -1,136 +0,0 @@
1
-
2
-
3
- require 'httparty'
4
- require 'uri'
5
-
6
- begin
7
- require 'yajl-ruby'
8
- rescue LoadError => ex
9
- require 'json'
10
- end
11
-
12
- begin
13
- require 'yaml'
14
- rescue LoadError => ex
15
- end
16
-
17
-
18
- # Onetime::API - v0.3
19
- #
20
- # A basic client library for the onetimesecret.com API.
21
- #
22
- # Usage:
23
- #
24
- # api = OT::API.new 'delano@onetimesecret.com', '4eb33c6340006d6607c813fc7e707a32f8bf5342'
25
- #
26
- # api.get '/status'
27
- # # => {'status' => 'nominal'}
28
- #
29
- # api.post '/generate', :passphrase => 'yourspecialpassphrase'
30
- # # => {'value' => '3Rg8R2sfD3?a', 'metadata_key' => '...', 'secret_key' => '...'}
31
- #
32
- module Onetime
33
- class API
34
- unless defined?(Onetime::API::HOME)
35
- HOME = File.expand_path File.join(File.dirname(__FILE__), '..', '..')
36
- end
37
- module VERSION
38
- @path = File.join(Onetime::API::HOME, 'VERSION')
39
- class << self
40
- attr_reader :version, :path
41
- def version
42
- @version || read_version
43
- end
44
- def read_version
45
- return if @version
46
- @version = File.read(path).strip!
47
- end
48
- def prerelease?() false end
49
- def to_a() version.split('.') end
50
- def to_s() version end
51
- def inspect() version end
52
- end
53
- end
54
- end
55
- class API
56
- include HTTParty
57
- base_uri 'https://onetimesecret.com/api'
58
- format :json
59
- headers 'X-Onetime-Client' => 'ruby: %s/%s' % [RUBY_VERSION, Onetime::API::VERSION.to_s]
60
- attr_reader :opts, :response, :custid, :key, :default_params, :anonymous
61
- attr_accessor :apiversion
62
- def initialize custid=nil, key=nil, opts={}
63
- unless ENV['ONETIME_HOST'].to_s.empty?
64
- self.class.base_uri ENV['ONETIME_HOST']
65
- end
66
- @apiversion = opts.delete(:apiversion) || opts.delete('apiversion') || 1
67
- @opts = opts
68
- @default_params = {}
69
- @custid = custid || ENV['ONETIME_CUSTID']
70
- @key = key || ENV['ONETIME_APIKEY']
71
- if @custid.to_s.empty? && @key.to_s.empty?
72
- @anonymous = true
73
- elsif @custid.to_s.empty? || @key.to_s.empty?
74
- raise RuntimeError, "You provided a custid without an apikey" if @key.to_s.empty?
75
- raise RuntimeError, "You provided an apikey without a custid" if @custid.to_s.empty?
76
- else
77
- @anonymous = false
78
- opts[:basic_auth] ||= { :username => @custid, :password => @key }
79
- end
80
- end
81
- def get path, params=nil
82
- opts = self.opts.clone
83
- opts[:query] = (params || {}).merge default_params
84
- execute_request :get, path, opts
85
- end
86
- def post path, params=nil
87
- opts = self.opts.clone
88
- opts[:body] = (params || {}).merge default_params
89
- execute_request :post, path, opts
90
- end
91
- def api_path *args
92
- args.unshift ['', "v#{apiversion}"] # force leading slash and version
93
- path = args.flatten.join('/')
94
- path.gsub '//', '/'
95
- end
96
- private
97
- def execute_request meth, path, opts
98
- path = api_path [path]
99
- @response = self.class.send meth, path, opts
100
- self.class.indifferent_params @response.parsed_response
101
- end
102
- class << self
103
- def web_uri *args
104
- uri = URI.parse(OT::API.base_uri)
105
- uri.path = web_path *args
106
- uri
107
- end
108
- def web_path *args
109
- args.unshift [''] # force leading slash
110
- path = args.flatten.join('/')
111
- path.gsub '//', '/'
112
- end
113
- def indifferent_params(params)
114
- if params.is_a?(Hash)
115
- params = indifferent_hash.merge(params)
116
- params.each do |key, value|
117
- next unless value.is_a?(Hash) || value.is_a?(Array)
118
- params[key] = indifferent_params(value)
119
- end
120
- elsif params.is_a?(Array)
121
- params.collect! do |value|
122
- if value.is_a?(Hash) || value.is_a?(Array)
123
- indifferent_params(value)
124
- else
125
- value
126
- end
127
- end
128
- end
129
- end
130
- def indifferent_hash
131
- Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
132
- end
133
- end
134
- end
135
- end
136
- OT = Onetime unless defined?(OT)