kbsecret 1.7.2 → 1.7.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df49a867fa247712bc62cae7be000a45302ba12b5b3c02a9af9949132f11fa0f
4
- data.tar.gz: 6f6d4682d773569f6bfe46506d6417d365408c6ad570e485b97a5163f0d743e0
3
+ metadata.gz: eba1afed2a8a01e07aeac416b3b8f77f135bbfe8250b9ecb38e8893ae07c0d5d
4
+ data.tar.gz: 8903e8beb923fc77b84b0fad9dab5361bcdba341b799018cf202d93b0dbc6138
5
5
  SHA512:
6
- metadata.gz: 2cc8247df39a5d07118ed074f0f1126aaa321964379dfe27c88bededc409a66a725453a41c3ce232fb8b9d9c28e35db009e48b0beee894fa7b1b6d331ef5f60e
7
- data.tar.gz: 6a1c30cf85e0e46a594c2e7dda3c15f33a0b68a98f3d9f645d528fc303300d7f6b4f7a1d27c5362225406c023022e7afbb13f06eaa64639b39d21ef45b08e2b8
6
+ metadata.gz: '04807954fe29c7ebc99f95db0498695ddde596d64df8a6c72513481b74b9bd6351be43b217722717aa12ac9746fd4b3eb82a12ba3ebffac84081a3ebafef8632'
7
+ data.tar.gz: d31d80ab7145bc7b8d26dae8a215efe2ad008d21e16962d23c200bc3022bb09fcff29222a5a8ec3275174be878072b6d197ae5f2ebd7103855ccae91ba0638f7
@@ -7,14 +7,17 @@ require "dreck"
7
7
  require "abbrev"
8
8
  require "pastel"
9
9
  require "io/console"
10
+ require "forwardable"
10
11
 
11
12
  module KBSecret
12
13
  # An encapsulation of useful methods for kbsecret's CLI.
13
14
  # Most methods in this class assume that they are being called from the context of
14
15
  # a command-line utility.
15
16
  class CLI
17
+ extend Forwardable
18
+
16
19
  # Abbreviations for record types (e.g., `env` for `environment`).
17
- TYPE_ALIASES = Hash.new { |_, k| k }.update(Abbrev.abbrev(Record.record_types)).freeze
20
+ TYPE_ALIASES = Abbrev.abbrev Record.record_types
18
21
 
19
22
  # ANSI color objects for prettifying output.
20
23
  GREEN, YELLOW, RED = ->(p) { [p.green, p.yellow, p.red].map(&:detach) }.call(Pastel.new)
@@ -31,6 +34,54 @@ module KBSecret
31
34
  # via {#ensure_session!}
32
35
  attr_reader :session
33
36
 
37
+ class << self
38
+ # Print an error message and terminate.
39
+ # @param msg [String] the message to print
40
+ # @return [void]
41
+ # @note This method does not return!
42
+ def die(msg)
43
+ fatal = ENV["NO_COLOR"] ? "Fatal" : RED["Fatal"]
44
+ abort "#{fatal}: #{msg}"
45
+ end
46
+
47
+ # Finds a reasonable default field separator by checking the environment first
48
+ # and then falling back to ":".
49
+ # @return [String] the field separator
50
+ def ifs
51
+ ENV["IFS"] || ":"
52
+ end
53
+
54
+ # @return [IO] the IO object corresponding to the current standard input
55
+ # @note Internal `kbsecret` commands should use this, and not `STDIN`.
56
+ def stdin
57
+ $stdin
58
+ end
59
+
60
+ # @return [IO] the IO object corresponding to the current standard output
61
+ # @note Internal `kbsecret` commands should use this, and not `STDOUT`.
62
+ def stdout
63
+ $stdout
64
+ end
65
+
66
+ # @return [IO] the IO object corresponding to the current standard error
67
+ # @note Internal `kbsecret` commands should use this, and not `STDERR`.
68
+ def stderr
69
+ $stderr
70
+ end
71
+
72
+ # Searches for an executable on the user's `$PATH`.
73
+ # @param util [String] the name of the executable to search for.
74
+ # @return [Boolean] whether or not `util` is available on the `$PATH`.
75
+ # @example
76
+ # CLI.installed? "foo" # => false
77
+ # CLI.installed? "gcc" # => true
78
+ def installed?(util)
79
+ ENV["PATH"].split(File::PATH_SEPARATOR).any? do |path|
80
+ File.executable?(File.join(path, util))
81
+ end
82
+ end
83
+ end
84
+
34
85
  # Encapsulate both the options and trailing arguments passed to a `kbsecret` command.
35
86
  # @yield [CLI] the {CLI} instance to specify
36
87
  # @return [CLI] the command's initial state
@@ -61,6 +112,8 @@ module KBSecret
61
112
  guard { yield self }
62
113
  end
63
114
 
115
+ def_delegators :"self.class", :die, :ifs, :stdin, :stdout, :stderr, :installed?
116
+
64
117
  # Parse options for a `kbsecret` command, adding some default options for
65
118
  # introspection, verbosity, and help output.
66
119
  # @param cmds [Array<String>] additional commands to print in `--introspect-flags`
@@ -152,7 +205,7 @@ module KBSecret
152
205
  def guard
153
206
  yield
154
207
  rescue => e
155
- self.class.stderr.puts e.backtrace if @opts&.debug?
208
+ stderr.puts e.backtrace if @opts&.debug?
156
209
  die "#{e.to_s.capitalize}."
157
210
  end
158
211
 
@@ -161,11 +214,11 @@ module KBSecret
161
214
  # @param echo [Boolean] whether or not to echo the user's input
162
215
  # @return [String] the user's response, with trailing newline removed
163
216
  def prompt(question, echo: true)
164
- if !echo && self.class.stdin.tty?
165
- self.class.stdin.getpass("#{question} ")
217
+ if !echo && stdin.tty?
218
+ stdin.getpass("#{question} ")
166
219
  else
167
- self.class.stdout.print "#{question} "
168
- self.class.stdin.gets.chomp
220
+ stdout.print "#{question} "
221
+ stdin.gets.chomp
169
222
  end
170
223
  end
171
224
 
@@ -174,7 +227,7 @@ module KBSecret
174
227
  # @return [void]
175
228
  def info(msg)
176
229
  info = ENV["NO_COLOR"] ? "Info" : GREEN["Info"]
177
- self.class.stderr.puts "#{info}: #{msg}"
230
+ stderr.puts "#{info}: #{msg}"
178
231
  end
179
232
 
180
233
  # Print an information message, but only if verbose output has been enabled.
@@ -200,62 +253,7 @@ module KBSecret
200
253
  def warn(msg)
201
254
  return if @opts.no_warn?
202
255
  warning = ENV["NO_COLOR"] ? "Warning" : YELLOW["Warning"]
203
- self.class.stderr.puts "#{warning}: #{msg}"
204
- end
205
-
206
- # Print an error message and terminate.
207
- # @param msg [String] the message to print
208
- # @return [void]
209
- # @note This method does not return!
210
- def die(msg)
211
- fatal = ENV["NO_COLOR"] ? "Fatal" : RED["Fatal"]
212
- abort "#{fatal}: #{msg}"
213
- end
214
-
215
- # Print an error message and terminate.
216
- # @param msg [String] the message to print
217
- # @return [void]
218
- # @note This method does not return!
219
- def self.die(msg)
220
- fatal = ENV["NO_COLOR"] ? "Fatal" : RED["Fatal"]
221
- abort "#{fatal}: #{msg}"
222
- end
223
-
224
- # Finds a reasonable default field separator by checking the environment first
225
- # and then falling back to ":".
226
- # @return [String] the field separator
227
- def self.ifs
228
- ENV["IFS"] || ":"
229
- end
230
-
231
- # @return [IO] the IO object corresponding to the current standard input
232
- # @note Internal `kbsecret` commands should use this, and not `STDIN`.
233
- def self.stdin
234
- $stdin
235
- end
236
-
237
- # @return [IO] the IO object corresponding to the current standard output
238
- # @note Internal `kbsecret` commands should use this, and not `STDOUT`.
239
- def self.stdout
240
- $stdout
241
- end
242
-
243
- # @return [IO] the IO object corresponding to the current standard error
244
- # @note Internal `kbsecret` commands should use this, and not `STDERR`.
245
- def self.stderr
246
- $stderr
247
- end
248
-
249
- # Searches for an executable on the user's `$PATH`.
250
- # @param util [String] the name of the executable to search for.
251
- # @return [Boolean] whether or not `util` is available on the `$PATH`.
252
- # @example
253
- # CLI.installed? "foo" # => false
254
- # CLI.installed? "gcc" # => true
255
- def self.installed?(util)
256
- ENV["PATH"].split(File::PATH_SEPARATOR).any? do |path|
257
- File.executable?(File.join(path, util))
258
- end
256
+ stderr.puts "#{warning}: #{msg}"
259
257
  end
260
258
  end
261
259
  end
@@ -15,7 +15,7 @@ module KBSecret
15
15
 
16
16
  o.string "-s", "--session", "the session to search in", default: :default
17
17
  o.bool "-x", "--terse", "output in field<sep>value format"
18
- o.string "-i", "--ifs", "separate terse pairs with this string", default: CLI.ifs
18
+ o.string "-i", "--ifs", "separate terse pairs with this string", default: cli.ifs
19
19
  end
20
20
 
21
21
  cli.dreck do
@@ -17,7 +17,7 @@ module KBSecret
17
17
  o.bool "-a", "--all", "retrieve all login records, not just listed ones"
18
18
  o.bool "-u", "--username-only", "print only usernames, not passwords"
19
19
  o.bool "-x", "--terse", "output in label<sep>username<sep>password format"
20
- o.string "-i", "--ifs", "separate terse fields with this string", default: CLI.ifs
20
+ o.string "-i", "--ifs", "separate terse fields with this string", default: cli.ifs
21
21
  end
22
22
 
23
23
  unless cli.opts.all?
@@ -24,7 +24,7 @@ module KBSecret
24
24
  o.string "-g", "--generator", "the generator to use for secret fields",
25
25
  default: :default
26
26
  o.bool "-x", "--terse", "read fields from input in a terse format"
27
- o.string "-i", "--ifs", "separate terse fields with this string", default: CLI.ifs
27
+ o.string "-i", "--ifs", "separate terse fields with this string", default: cli.ifs
28
28
  end
29
29
 
30
30
  cli.dreck do
@@ -58,7 +58,7 @@ module KBSecret
58
58
  generator = KBSecret::Generator.new(cli.opts[:generator]) if cli.opts.generate?
59
59
 
60
60
  fields = if cli.opts.terse?
61
- CLI.stdin.read.chomp.split cli.opts[:ifs]
61
+ cli.stdin.read.chomp.split cli.opts[:ifs]
62
62
  else
63
63
  klass = Record.class_for(@type)
64
64
  klass.external_fields.map do |field|
@@ -50,7 +50,7 @@ module KBSecret
50
50
  # @see Command::Abstract#run!
51
51
  def run!
52
52
  contents = if cli.opts.stdin?
53
- KBSecret::CLI.stdin.read
53
+ cli.stdin.read
54
54
  else
55
55
  File.read(@filename)
56
56
  end
@@ -57,7 +57,7 @@ module KBSecret
57
57
  # configuration defaults
58
58
  # @api private
59
59
  DEFAULT_CONFIG = {
60
- mount: "/keybase",
60
+ mount: Keybase::Local::Config::KBFS_MOUNT,
61
61
  sessions: DEFAULT_SESSION.dup,
62
62
  generators: DEFAULT_GENERATOR.dup,
63
63
  }.freeze
@@ -2,5 +2,5 @@
2
2
 
3
3
  module KBSecret
4
4
  # kbsecret's current version
5
- VERSION = "1.7.2"
5
+ VERSION = "1.7.3"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kbsecret
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-11 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -142,20 +142,20 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '1.1'
145
+ version: '2.0'
146
146
  - - ">="
147
147
  - !ruby/object:Gem::Version
148
- version: 1.1.1
148
+ version: 2.0.1
149
149
  type: :runtime
150
150
  prerelease: false
151
151
  version_requirements: !ruby/object:Gem::Requirement
152
152
  requirements:
153
153
  - - "~>"
154
154
  - !ruby/object:Gem::Version
155
- version: '1.1'
155
+ version: '2.0'
156
156
  - - ">="
157
157
  - !ruby/object:Gem::Version
158
- version: 1.1.1
158
+ version: 2.0.1
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: pastel
161
161
  requirement: !ruby/object:Gem::Requirement