kbsecret 0.7.2 → 0.8.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f7ecf6f46bf93d8b097aff9017725676147e6a2
4
- data.tar.gz: 5e80a9ab48b57a1f2da0e560351230fafe46e9e0
3
+ metadata.gz: 8f9e6f8ce574fa59a334356df9e032d0a9eaf520
4
+ data.tar.gz: 58c8df01baa2fe0a7ace5703fd8d1c4a73caa29b
5
5
  SHA512:
6
- metadata.gz: ea1c32677807dd0c0fcd234087c4f092fb64d9814de5b912e2649b4dfe3f4914a0eb5554cecdfab3c03e7f2deae52b7ab3069d8df80e6be3062ae8fcb8211e31
7
- data.tar.gz: f04e0bb37a20cb9af814685bbe7193e638943e6f30f53aebe554506761639eca2ebf2f65170cf5a0d40819d2f97b9320c43a1a94b2da9f499ef9946c8f920e9a
6
+ metadata.gz: 91d6dbb411d5f653d35b5d094283a0654429ecad6d125ea461347749c06fe0b98c054a7edf0e58039261dd15406ce98ed8c24d1b6559ec8ef7bc5bc736efeb3d
7
+ data.tar.gz: c2360326474745633cffb71f4c6e02b21b58865d753657f1de3272a3c0b7d104ce6f005aefb46dc756c93562fe2b10e94a65442f7b505e73d8a6f78787720e9d
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- KBSsecret
1
+ KBSecret
2
2
  ========
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/kbsecret.svg)](https://badge.fury.io/rb/kbsecret)
data/bin/kbsecret CHANGED
@@ -5,6 +5,12 @@ require "kbsecret"
5
5
 
6
6
  BUILTIN_CMDS = %w[help version commands types conf].freeze
7
7
 
8
+ INTERNAL_CMD_PATH = File.expand_path("../lib/kbsecret/cli")
9
+
10
+ INTERNAL_PATHS = Dir[File.join(INTERNAL_CMD_PATH, "*")].freeze
11
+
12
+ INTERNAL_CMDS = INTERNAL_PATHS.map { |p| File.basename(p).sub!("kbsecret-", "") }
13
+
8
14
  EXT_PATHS = ENV["PATH"].split(File::PATH_SEPARATOR).map do |path|
9
15
  Dir[File.join(path, "kbsecret-*")]
10
16
  end.flatten.uniq.freeze
@@ -20,7 +26,7 @@ ALIASES = Hash.new { |_, k| k }.update(
20
26
  "-v" => "version"
21
27
  ).freeze
22
28
 
23
- ALL_CMDS = (ALIASES.keys + BUILTIN_CMDS + EXT_CMDS).freeze
29
+ ALL_CMDS = (ALIASES.keys + BUILTIN_CMDS + INTERNAL_CMDS + EXT_CMDS).freeze
24
30
 
25
31
  KBSECRET_HELP = <<~EOS
26
32
  Usage:
@@ -33,6 +39,10 @@ KBSECRET_HELP = <<~EOS
33
39
  kbsecret help <command>
34
40
  EOS
35
41
 
42
+ def internal?(cmd)
43
+ INTERNAL_CMDS.include?(cmd)
44
+ end
45
+
36
46
  def external?(cmd)
37
47
  EXT_CMDS.include?(cmd)
38
48
  end
@@ -51,7 +61,12 @@ end
51
61
 
52
62
  def expand(cmd)
53
63
  return cmd if alias?(cmd) || builtin?(cmd)
54
- "kbsecret-#{cmd}"
64
+
65
+ if internal? cmd
66
+ File.join(INTERNAL_CMD_PATH, "kbsecret-#{cmd}")
67
+ else
68
+ "kbsecret-#{cmd}"
69
+ end
55
70
  end
56
71
 
57
72
  def help(*args)
@@ -60,10 +75,10 @@ def help(*args)
60
75
  puts KBSECRET_HELP
61
76
  elsif builtin? command
62
77
  send "#{command}_help"
63
- elsif external? command
64
- # XXX: this probably doesn't make sense, since not every user command
65
- # will implement --help.
78
+ elsif internal? command
66
79
  exec expand(command), "--help"
80
+ elsif external? command
81
+ KBSecret::CLI.die "Help is not available for external commands."
67
82
  else
68
83
  KBSecret::CLI.die "Unknown command: '#{command}'."
69
84
  end
@@ -141,9 +156,9 @@ end
141
156
 
142
157
  command = normalize(ARGV.shift || "help")
143
158
 
144
- if builtin? command
159
+ if builtin?(command)
145
160
  send command, *ARGV
146
- elsif external? command
161
+ elsif external?(command) || internal?(command)
147
162
  exec expand(command), *ARGV
148
163
  else
149
164
  KBSecret::CLI.die "Unknown command: '#{command}'."
data/lib/kbsecret.rb CHANGED
@@ -10,7 +10,7 @@ require_relative "kbsecret/session"
10
10
  require_relative "kbsecret/generator"
11
11
  require_relative "kbsecret/cli"
12
12
 
13
- # The primary namespace for kbsecret.
13
+ # The primary namespace for {KBSecret}.
14
14
  module KBSecret
15
15
  # fail very early if the user doesn't have keybase and KBFS running
16
16
  raise Keybase::KeybaseNotRunningError unless Keybase.running?
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -19,12 +19,12 @@ module KBSecret
19
19
  CONFIG_FACETS = {
20
20
  session: {
21
21
  plural: :sessions,
22
- except: SessionUnknownError,
22
+ except: Exceptions::SessionUnknownError,
23
23
  },
24
24
 
25
25
  generator: {
26
26
  plural: :generators,
27
- except: GeneratorUnknownError,
27
+ except: Exceptions::GeneratorUnknownError,
28
28
  },
29
29
  }.freeze
30
30
 
@@ -65,44 +65,44 @@ module KBSecret
65
65
  @config[key]
66
66
  end
67
67
 
68
- # @!method session
68
+ # @!method session(label)
69
69
  # Retrieve a session's configuration.
70
70
  # @param label [String, Symbol] the session's label
71
71
  # @return [Hash] the session configuration
72
- # @raise [SessionUnknownError] if no such session exists
72
+ # @raise [Exceptions::SessionUnknownError] if no such session exists
73
73
  # @!method session_labels
74
74
  # @return [Array<Symbol>] all configured session labels
75
- # @!method session?
75
+ # @!method session?(label)
76
76
  # @param label [String, Symbol] the session label
77
77
  # @return [Boolean] whether or not the given session is configured
78
- # @!method configure_session
78
+ # @!method configure_session(label, hsh)
79
79
  # Configure a session.
80
80
  # @param label [String, Symbol] the session label
81
81
  # @param hsh [Hash] the session configuration
82
82
  # @return [void]
83
- # @!method deconfigure_session
83
+ # @!method deconfigure_session(label)
84
84
  # Deconfigure a session.
85
85
  # @param label [String, Symbol] the session label
86
86
  # @return [void]
87
87
  # @note This only removes the given session from the configuration, making
88
88
  # it "invisible" to `kbsecret`. To actually remove all files associated
89
89
  # with a session, see {KBSecret::Session#unlink!}.
90
- # @!method generator
90
+ # @!method generator(label)
91
91
  # Retrieve a generator's configuration.
92
- # @param gen [String, Symbol] the generator's label
92
+ # @param label [String, Symbol] the generator's label
93
93
  # @return [Hash] the generator configuration
94
- # @raise [GeneratorUnknownError] if no such generator exists
94
+ # @raise [Exceptions::GeneratorUnknownError] if no such generator exists
95
95
  # @!method generator_labels
96
96
  # @return [Array<Symbol>] all configured session labels
97
- # @!method generator?
98
- # @param gen [String, Symbol] the generator label
97
+ # @!method generator?(label)
98
+ # @param label [String, Symbol] the generator label
99
99
  # @return [Boolean] whether or not the given generator is configured
100
- # @!method configure_generator
100
+ # @!method configure_generator(label, hsh)
101
101
  # Configure a secret generator.
102
102
  # @param label [String, Symbol] the generator label (profile name)
103
103
  # @param hsh [Hash] the generator configuration
104
104
  # @return [void]
105
- # @!method deconfigure_generator
105
+ # @!method deconfigure_generator(label)
106
106
  # Deconfigure a generator.
107
107
  # @param label [String, Symbol] the generator label (profile name)
108
108
  # @return [void]
@@ -1,64 +1,67 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KBSecret
4
- # A generic error in kbsecret.
5
- class KBSecretError < RuntimeError
6
- end
4
+ # A namespace for all exceptions used by {KBSecret}.
5
+ module Exceptions
6
+ # A generic error in {KBSecret}.
7
+ class KBSecretError < RuntimeError
8
+ end
7
9
 
8
- # Raised during record loading if a particular file can't be loaded
9
- class RecordLoadError < KBSecretError
10
- def initialize(path)
11
- base = File.basename(path)
12
- super "Failed to load record in file: '#{base}'"
10
+ # Raised during record loading if a particular file can't be loaded
11
+ class RecordLoadError < KBSecretError
12
+ def initialize(path)
13
+ base = File.basename(path)
14
+ super "Failed to load record in file: '#{base}'"
15
+ end
13
16
  end
14
- end
15
17
 
16
- # Raised during record creation if an unknown record type is requested.
17
- class RecordTypeUnknownError < KBSecretError
18
- def initialize(type)
19
- super "Unknown record type: '#{type}'"
18
+ # Raised during record creation if an unknown record type is requested.
19
+ class RecordTypeUnknownError < KBSecretError
20
+ def initialize(type)
21
+ super "Unknown record type: '#{type}'"
22
+ end
20
23
  end
21
- end
22
24
 
23
- # Raised during record creation if too many/few arguments are given.
24
- class RecordCreationArityError < KBSecretError
25
- def initialize(exp, act)
26
- super "Needed #{exp} arguments for this record, got #{act}"
25
+ # Raised during record creation if too many/few arguments are given.
26
+ class RecordCreationArityError < KBSecretError
27
+ def initialize(exp, act)
28
+ super "Needed #{exp} arguments for this record, got #{act}"
29
+ end
27
30
  end
28
- end
29
31
 
30
- # Raised during session load if an error occurs.
31
- class SessionLoadError < KBSecretError
32
- def initialize(msg)
33
- super "Session loading failure: #{msg}"
32
+ # Raised during session load if an error occurs.
33
+ class SessionLoadError < KBSecretError
34
+ def initialize(msg)
35
+ super "Session loading failure: #{msg}"
36
+ end
34
37
  end
35
- end
36
38
 
37
- # Raised during session lookup if an unknown session is requested.
38
- class SessionUnknownError < KBSecretError
39
- def initialize(sess)
40
- super "Unknown session: '#{sess}'"
39
+ # Raised during session lookup if an unknown session is requested.
40
+ class SessionUnknownError < KBSecretError
41
+ def initialize(sess)
42
+ super "Unknown session: '#{sess}'"
43
+ end
41
44
  end
42
- end
43
45
 
44
- # Raised during generator lookup if an unknown profile is requested.
45
- class GeneratorUnknownError < KBSecretError
46
- def initialize(gen)
47
- super "Unknown generator profile: '#{gen}'"
46
+ # Raised during generator lookup if an unknown profile is requested.
47
+ class GeneratorUnknownError < KBSecretError
48
+ def initialize(gen)
49
+ super "Unknown generator profile: '#{gen}'"
50
+ end
48
51
  end
49
- end
50
52
 
51
- # Raised during generator creation if an unknown generator format is requested.
52
- class GeneratorFormatError < KBSecretError
53
- def initialize(fmt)
54
- super "Unknown generator format: '#{fmt}'"
53
+ # Raised during generator creation if an unknown generator format is requested.
54
+ class GeneratorFormatError < KBSecretError
55
+ def initialize(fmt)
56
+ super "Unknown generator format: '#{fmt}'"
57
+ end
55
58
  end
56
- end
57
59
 
58
- # Raised during generator creation if a non-positive generator length is requested.
59
- class GeneratorLengthError < KBSecretError
60
- def initialize(length)
61
- super "Bad secret generator length (#{length}, must be positive)"
60
+ # Raised during generator creation if a non-positive generator length is requested.
61
+ class GeneratorLengthError < KBSecretError
62
+ def initialize(length)
63
+ super "Bad secret generator length (#{length}, must be positive)"
64
+ end
62
65
  end
63
66
  end
64
67
  end
@@ -15,14 +15,14 @@ module KBSecret
15
15
  attr_reader :length
16
16
 
17
17
  # @param profile [Symbol, String] the label of the generator profile to use
18
- # @raise [GeneratorLengthError] if the profile has a non-positive length
19
- # @raise [GeneratorFormatError] if the profile has an unknown format
18
+ # @raise [Exceptions::GeneratorLengthError] if the profile has a non-positive length
19
+ # @raise [Exceptions::GeneratorFormatError] if the profile has an unknown format
20
20
  def initialize(profile = :default)
21
21
  @format = Config.generator(profile)[:format].to_sym
22
22
  @length = Config.generator(profile)[:length].to_i
23
23
 
24
- raise GeneratorLengthError, @length unless @length.positive?
25
- raise GeneratorFormatError, @format unless GENERATOR_TYPES.include?(@format)
24
+ raise Exceptions::GeneratorLengthError, @length unless @length.positive?
25
+ raise Exceptions::GeneratorFormatError, @format unless GENERATOR_TYPES.include?(@format)
26
26
  end
27
27
 
28
28
  # @return [String] a new secret based on the {format} and {length} of the {Generator}
@@ -24,10 +24,10 @@ module KBSecret
24
24
 
25
25
  # @param type [String, Symbol] the record type
26
26
  # @return [Class] the record class corresponding to the given type
27
- # @raise [RecordTypeUnknownError] if the requested type is unknown
27
+ # @raise [Exceptions::RecordTypeUnknownError] if the requested type is unknown
28
28
  def self.class_for(type)
29
29
  klass = record_classes.find { |c| c.type == type.to_sym }
30
- raise RecordTypeUnknownError, type unless klass
30
+ raise Exceptions::RecordTypeUnknownError, type unless klass
31
31
  klass
32
32
  end
33
33
 
@@ -42,14 +42,14 @@ module KBSecret
42
42
  # @param session [Session] the session to load into
43
43
  # @param path [String] the fully-qualified record path
44
44
  # @return [Record::AbstractRecord] the loaded record
45
- # @raise [RecordLoadError] if an error occurs during record loading
45
+ # @raise [Exceptions::RecordLoadError] if an error occurs during record loading
46
46
  # @api private
47
47
  def self.load_record!(session, path)
48
48
  hsh = JSON.parse(File.read(path), symbolize_names: true)
49
49
  klass = record_classes.find { |c| c.type == hsh[:type].to_sym }
50
50
  klass&.load!(session, hsh)
51
51
  rescue
52
- raise RecordLoadError, path
52
+ raise Exceptions::RecordLoadError, path
53
53
  end
54
54
  end
55
55
  end
@@ -17,7 +17,7 @@ module KBSecret
17
17
  attr_reader :directory
18
18
 
19
19
  # @param label [String, Symbol] the label of the session to initialize
20
- # @raise [SessionLoadError] if the session has no users or any invalid Keybase users
20
+ # @raise [Exceptions::SessionLoadError] if the session has no users or any invalid Keybase users
21
21
  # @note This does not *create* a new session, but loads one already
22
22
  # specified in {Config::CONFIG_FILE}. To *create* a new session,
23
23
  # see {Config.configure_session}.
@@ -25,10 +25,10 @@ module KBSecret
25
25
  @label = label.to_sym
26
26
  @config = Config.session(@label)
27
27
 
28
- raise SessionLoadError, "no users in session" if @config[:users].empty?
28
+ raise Exceptions::SessionLoadError, "no users in session" if @config[:users].empty?
29
29
 
30
30
  @config[:users].each do |user|
31
- raise SessionLoadError, "unknown Keybase user: '#{user}'" unless Keybase::API.user? user
31
+ raise Exceptions::SessionLoadError, "unknown user: '#{user}'" unless Keybase::API.user? user
32
32
  end
33
33
 
34
34
  @directory = rel_path mkdir: true
@@ -64,15 +64,15 @@ module KBSecret
64
64
  # @param label [String, Symbol] the new record's label
65
65
  # @param args [Array<String>] the record-type specific arguments
66
66
  # @return [void]
67
- # @raise [UnknownRecordTypeError] if the requested type does not exist
67
+ # @raise [Exceptions::UnknownRecordTypeError] if the requested type does not exist
68
68
  # in {Record.record_types}
69
- # @raise [RecordCreationArityError] if the number of specified record
69
+ # @raise [Exceptions::RecordCreationArityError] if the number of specified record
70
70
  # arguments does not match the record type's constructor
71
71
  def add_record(type, label, *args)
72
72
  klass = Record.class_for(type.to_sym)
73
73
  arity = klass.external_fields.length
74
74
 
75
- raise RecordCreationArityError.new(arity, args.size) unless arity == args.size
75
+ raise Exceptions::RecordCreationArityError.new(arity, args.size) unless arity == args.size
76
76
 
77
77
  body = klass.external_fields.zip(args).to_h
78
78
  record = klass.new(self, label.to_s, **body)
data/lib/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module KBSecret
4
4
  # kbsecret's current version
5
- VERSION = "0.7.2"
5
+ VERSION = "0.8.0.pre.1"
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: 0.7.2
4
+ version: 0.8.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-19 00:00:00.000000000 Z
11
+ date: 2017-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fpm
@@ -153,22 +153,7 @@ dependencies:
153
153
  description: Manages your passwords, environment, and more via KBFS.
154
154
  email: william@tuffbizz.com
155
155
  executables:
156
- - kbsecret-pass
157
156
  - kbsecret
158
- - kbsecret-rm
159
- - kbsecret-login
160
- - kbsecret-raw-edit
161
- - kbsecret-todo
162
- - kbsecret-generator
163
- - kbsecret-new
164
- - kbsecret-generators
165
- - kbsecret-dump-fields
166
- - kbsecret-stash-file
167
- - kbsecret-rm-session
168
- - kbsecret-env
169
- - kbsecret-new-session
170
- - kbsecret-list
171
- - kbsecret-sessions
172
157
  extensions: []
173
158
  extra_rdoc_files: []
174
159
  files:
@@ -176,23 +161,23 @@ files:
176
161
  - LICENSE
177
162
  - README.md
178
163
  - bin/kbsecret
179
- - bin/kbsecret-dump-fields
180
- - bin/kbsecret-env
181
- - bin/kbsecret-generator
182
- - bin/kbsecret-generators
183
- - bin/kbsecret-list
184
- - bin/kbsecret-login
185
- - bin/kbsecret-new
186
- - bin/kbsecret-new-session
187
- - bin/kbsecret-pass
188
- - bin/kbsecret-raw-edit
189
- - bin/kbsecret-rm
190
- - bin/kbsecret-rm-session
191
- - bin/kbsecret-sessions
192
- - bin/kbsecret-stash-file
193
- - bin/kbsecret-todo
194
164
  - lib/kbsecret.rb
195
165
  - lib/kbsecret/cli.rb
166
+ - lib/kbsecret/cli/kbsecret-dump-fields
167
+ - lib/kbsecret/cli/kbsecret-env
168
+ - lib/kbsecret/cli/kbsecret-generator
169
+ - lib/kbsecret/cli/kbsecret-generators
170
+ - lib/kbsecret/cli/kbsecret-list
171
+ - lib/kbsecret/cli/kbsecret-login
172
+ - lib/kbsecret/cli/kbsecret-new
173
+ - lib/kbsecret/cli/kbsecret-new-session
174
+ - lib/kbsecret/cli/kbsecret-pass
175
+ - lib/kbsecret/cli/kbsecret-raw-edit
176
+ - lib/kbsecret/cli/kbsecret-rm
177
+ - lib/kbsecret/cli/kbsecret-rm-session
178
+ - lib/kbsecret/cli/kbsecret-sessions
179
+ - lib/kbsecret/cli/kbsecret-stash-file
180
+ - lib/kbsecret/cli/kbsecret-todo
196
181
  - lib/kbsecret/config.rb
197
182
  - lib/kbsecret/exceptions.rb
198
183
  - lib/kbsecret/generator.rb
@@ -220,9 +205,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
205
  version: 2.3.0
221
206
  required_rubygems_version: !ruby/object:Gem::Requirement
222
207
  requirements:
223
- - - ">="
208
+ - - ">"
224
209
  - !ruby/object:Gem::Version
225
- version: '0'
210
+ version: 1.3.1
226
211
  requirements: []
227
212
  rubyforge_project:
228
213
  rubygems_version: 2.6.11