kbsecret 0.0.2 → 0.0.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
  SHA1:
3
- metadata.gz: f468bb679d062bf75ce1d379e4cd76c4544c090f
4
- data.tar.gz: d862b1c03920b88de8942fac32ad6f7b4fb89bd2
3
+ metadata.gz: a3a2b28b3170e4863d44f11502981d3089d632d9
4
+ data.tar.gz: fd5336473ba16c325225a4b91d66e59b3716d8a4
5
5
  SHA512:
6
- metadata.gz: a9de681a6224e5f577deb31e8a72cafe288fa9d48c7de5e7438616c8887408a3705e813bd588fdfc328b84683e0f5b51540f58911163c81494cde918851306a4
7
- data.tar.gz: 0fbe3224bc94a6a39eea6e1e0c578ab01fcd4755e92e827cd08441151086bd1cc2c65d00c2de8cfbefca0a32847001d53d7fc5496058de45bdf937cc7e3e64b7
6
+ metadata.gz: 6f3a41f94c383af499a7d5271c16ed24a3f2dda3e3ef12b7520766860015191acb9aad6765f3349b09518ce0187a9a67762f026a4c8ad487b791d46909900f87
7
+ data.tar.gz: 228a9ef975f89767c5addf46204387a9f51c2a5f1fa5c1d6464c36d4cd33fc6308b8b86bb961a6570a0caa6cbd25badc5d673a3e70fa8a92601c7da1c30d2f76
data/README.md CHANGED
@@ -31,6 +31,8 @@ $ git clone git@github.com:woodruffw/kbsecret.git && cd kbsecret
31
31
  $ RUBYLIB=./lib PATH=./bin:${PATH} ./bin/kbsecret help
32
32
  ```
33
33
 
34
+ Documentation is available on [RubyDoc](http://www.rubydoc.info/gems/kbsecret/).
35
+
34
36
  ### Usage
35
37
 
36
38
  ```bash
data/bin/kbsecret-new CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  require "kbsecret"
4
4
  require "slop"
5
+ require "abbrev"
6
+ require "tty-prompt"
7
+
8
+ # allows for abbreviated types (e.g., `kbsecret new env ...`)
9
+ TYPE_ALIASES = Abbrev.abbrev(KBSecret::Record.record_types).freeze
5
10
 
6
11
  opts = Slop.parse suppress_errors: true do |o|
7
12
  o.banner = <<~EOS
@@ -9,14 +14,18 @@ opts = Slop.parse suppress_errors: true do |o|
9
14
 
10
15
  Usage:
11
16
  kbsecret new [--session <name>] [--force] <type> <label> <args ...>
17
+ kbsecret new [--session <name>] [--force] [--interactive] <type> <label>
12
18
 
13
19
  Examples:
14
20
  kbsecret new login gmail "foo@bar.com" "mytopsecretpassword"
15
21
  kbsecret new environment API_KEY "abcdef-0123456789"
22
+ kbsecret new --interactive login netflix
16
23
  EOS
17
24
 
18
25
  o.string "-s", "--session", "the session name", default: :default
19
26
  o.bool "-f", "--force", "force creation (ignore overwrites, etc.)"
27
+ o.bool "-i", "--interactive", "input record fields interactively"
28
+ o.bool "-e", "--echo", "echo input to tty (only effects --interactive)"
20
29
 
21
30
  o.on "-h", "--help" do
22
31
  puts o
@@ -35,6 +44,8 @@ abort "Fatal: Not enough arguments." if opts.args.size < 2
35
44
  session = KBSecret::Session.new label: sess_name
36
45
  type, label = opts.args.shift 2
37
46
 
47
+ type = TYPE_ALIASES[type]
48
+
38
49
  if session.record?(label) && !opts.force?
39
50
  abort "Fatal: Refusing to overwrite an existing record without --force."
40
51
  end
@@ -46,8 +57,21 @@ unless KBSecret::Record.type?(type)
46
57
  EOS
47
58
  end
48
59
 
60
+ fields = []
61
+
62
+ if opts.interactive?
63
+ prompt = TTY::Prompt.new
64
+ klass = KBSecret::Record.class_for(type)
65
+ klass.data_fields.each do |field|
66
+ fields << prompt.ask("#{field.capitalize}?", echo: opts.echo?)
67
+ end
68
+ else
69
+ fields = opts.args
70
+ end
71
+
72
+
49
73
  begin
50
- session.add_record(type, label, *opts.args)
74
+ session.add_record(type, label, *fields)
51
75
  rescue => e
52
76
  abort "Fatal: #{e.to_s}."
53
77
  end
@@ -37,4 +37,4 @@ session_hash = {
37
37
  root: opts[:root],
38
38
  }
39
39
 
40
- KBSecret::Config.add_session(session_label, session_hash)
40
+ KBSecret::Config.configure_session(session_label, session_hash)
data/bin/kbsecret-rm CHANGED
@@ -11,7 +11,7 @@ opts = Slop.parse suppress_errors: true do |o|
11
11
  Delete a record.
12
12
 
13
13
  Usage:
14
- kbsecret rm [--session <name>] <label>
14
+ kbsecret rm [--session <name>] [--interactive] <label>
15
15
  EOS
16
16
 
17
17
  o.string "-s", "--session", "the session name", default: :default
@@ -20,7 +20,7 @@ opts = Slop.parse suppress_errors: true do |o|
20
20
  end
21
21
  end
22
22
 
23
- KBSecret::Config.session_names.each do |sess_name|
23
+ KBSecret::Config.session_labels.each do |sess_name|
24
24
  session_hash = KBSecret::Config.session(sess_name)
25
25
  session = KBSecret::Session.new label: sess_name
26
26
  line = "#{sess_name}\n"
@@ -40,22 +40,20 @@ module KBSecret
40
40
  end
41
41
 
42
42
  # @return [Array<Symbol>] all configured session labels
43
- # @todo This should be session_labels.
44
- def self.session_names
43
+ def self.session_labels
45
44
  @@config[:sessions].keys
46
45
  end
47
46
 
48
47
  # @param sess [Symbol] the session label
49
48
  # @return [Boolean] whether or not the given session is configured
50
49
  def self.session?(sess)
51
- session_names.include?(sess.to_sym)
50
+ session_labels.include?(sess.to_sym)
52
51
  end
53
52
 
54
53
  # Configure a session.
55
54
  # @param label [Symbol] the session label
56
55
  # @param hsh [Hash] the session configuration
57
- # @todo This should be configure_session.
58
- def self.add_session(label, hsh)
56
+ def self.configure_session(label, hsh)
59
57
  @@config[:sessions][label.to_sym] = hsh
60
58
  File.open(CONFIG_FILE, "w") { |io| io.write @@config.to_yaml }
61
59
  end
@@ -12,24 +12,46 @@ module KBSecret
12
12
  attr_reader :type
13
13
  attr_reader :data
14
14
 
15
- # @return [String] the record's type
16
- # @example
17
- # KBSecret::Record::Abstract.type # => "abstract"
18
- def self.type
19
- name.split("::").last.downcase
20
- end
15
+ class << self
16
+ def data_field(field)
17
+ @fields ||= []
18
+ @fields << field
21
19
 
22
- # Load the given hash-representation into a record.
23
- # @param session [Session] the session to associate with
24
- # @param hsh [Hash] the record's hash-representation
25
- # @return [Record::AbstractRecord] the created record
26
- # @api private
27
- def self.load!(session, hsh)
28
- instance = allocate
29
- instance.session = session
30
- instance.initialize_from_hash(hsh)
20
+ class_eval %[
21
+ def #{field}
22
+ @data[self.class.type.to_sym]["#{field}".to_sym]
23
+ end
24
+
25
+ def #{field}=(val)
26
+ @data[self.class.type.to_sym]["#{field}".to_sym] = val
27
+ sync!
28
+ end
29
+ ]
30
+ end
31
+
32
+ def data_fields
33
+ @fields
34
+ end
35
+
36
+ # @return [String] the record's type
37
+ # @example
38
+ # KBSecret::Record::Abstract.type # => "abstract"
39
+ def type
40
+ name.split("::").last.downcase
41
+ end
42
+
43
+ # Load the given hash-representation into a record.
44
+ # @param session [Session] the session to associate with
45
+ # @param hsh [Hash] the record's hash-representation
46
+ # @return [Record::AbstractRecord] the created record
47
+ # @api private
48
+ def load!(session, hsh)
49
+ instance = allocate
50
+ instance.session = session
51
+ instance.initialize_from_hash(hsh)
31
52
 
32
- instance
53
+ instance
54
+ end
33
55
  end
34
56
 
35
57
  # Create a brand new record, associated with a session.
@@ -4,6 +4,9 @@ module KBSecret
4
4
  module Record
5
5
  # Represents a record containing an environment variable and value.
6
6
  class Environment < Abstract
7
+ data_field :variable
8
+ data_field :value
9
+
7
10
  # @param session [Session] the session to associate with
8
11
  # @param label [Symbol] the new record's label
9
12
  # @param variable [String] the new record's variable
@@ -22,32 +25,6 @@ module KBSecret
22
25
  }
23
26
  end
24
27
 
25
- # @return [String] the record's variable
26
- def variable
27
- @data[:environment][:variable]
28
- end
29
-
30
- # @param var [String] the new variable to insert into the record
31
- # @return [void]
32
- # @note Triggers a record sync; see {Abstract#sync!}.
33
- def variable=(var)
34
- @data[:environment][:variable] = var
35
- sync!
36
- end
37
-
38
- # @return [String] the record's value
39
- def value
40
- @data[:environment][:value]
41
- end
42
-
43
- # @param val [String] the new value to insert into the record
44
- # @return [void]
45
- # @note Triggers a record sync; see {Abstract#sync!}.
46
- def value=(val)
47
- @data[:environment][:value] = val
48
- sync!
49
- end
50
-
51
28
  # @return [String] a sh-style environment assignment
52
29
  def to_assignment
53
30
  "#{variable}=#{value}"
@@ -2,6 +2,9 @@ module KBSecret
2
2
  module Record
3
3
  # Represents a record containing a login (username, password) pair.
4
4
  class Login < Abstract
5
+ data_field :username
6
+ data_field :password
7
+
5
8
  # @param session [Session] the session to associate with
6
9
  # @param label [Symbol] the new record's label
7
10
  # @param user [String] the new record's username
@@ -16,32 +19,6 @@ module KBSecret
16
19
  },
17
20
  }
18
21
  end
19
-
20
- # @return [String] the record's username
21
- def username
22
- @data[:login][:username]
23
- end
24
-
25
- # @param user [String] the new username to insert into the record
26
- # @return [void]
27
- # @note Triggers a record sync; see {Abstract#sync!}.
28
- def username=(user)
29
- @data[:login][:username] = user
30
- sync!
31
- end
32
-
33
- # @return [String] the record's password
34
- def password
35
- @data[:login][:password]
36
- end
37
-
38
- # @param pass [String] the new password to insert into the record
39
- # @return [void]
40
- # @note Triggers a record sync; see {Abstract#sync!}.
41
- def password=(pass)
42
- @data[:login][:password] = pass
43
- sync!
44
- end
45
22
  end
46
23
  end
47
24
  end
@@ -2,6 +2,8 @@ module KBSecret
2
2
  module Record
3
3
  # Represents a record containing unstructured text.
4
4
  class Unstructured < Abstract
5
+ data_field :text
6
+
5
7
  # @param session [Session] the session to associate with
6
8
  # @param label [Symbol] the new record's label
7
9
  # @param text [String] the new record's unstructured text
@@ -12,19 +14,6 @@ module KBSecret
12
14
  text: text
13
15
  }
14
16
  end
15
-
16
- # @return [String] the record's unstructured text
17
- def text
18
- @data[:text]
19
- end
20
-
21
- # @param new_text [String] the new text to insert into the record
22
- # @return [void]
23
- # @note Triggers a record sync; see {Abstract#sync!}.
24
- def text=(new_text)
25
- @data[:text] = new_text
26
- sync!
27
- end
28
17
  end
29
18
  end
30
19
  end
@@ -20,6 +20,13 @@ module KBSecret
20
20
  record_classes.map(&:type)
21
21
  end
22
22
 
23
+ # @param type [String] the record type
24
+ # @return [Class, nil] the record class corresponding to the given type
25
+ def self.class_for(type)
26
+ record_classes.find { |c| c.type == type }
27
+ end
28
+
29
+ # @param type [String] the record type
23
30
  # @return [Boolean] whether a record class exists of the given type
24
31
  def self.type?(type)
25
32
  record_types.include?(type)
@@ -14,7 +14,7 @@ module KBSecret
14
14
  # @param label [Symbol] the label of the session to initialize
15
15
  # @note This does not *create* a new session, but loads one already
16
16
  # specified in {Config::CONFIG_FILE}. To *create* a new session,
17
- # see {Config.add_session}.
17
+ # see {Config.configure_session}.
18
18
  def initialize(label: :default)
19
19
  @label = label
20
20
  @config = Config.session(label.to_sym)
data/lib/kbsecret.rb CHANGED
@@ -8,7 +8,7 @@ require_relative "kbsecret/session"
8
8
  # The primary namespace for kbsecret.
9
9
  module KBSecret
10
10
  # kbsecret's current version
11
- VERSION = "0.0.2".freeze
11
+ VERSION = "0.0.3".freeze
12
12
 
13
13
  # fail very early if the user doesn't have keybase and KBFS running
14
14
  raise Keybase::KeybaseNotRunningError unless Keybase.running?
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.0.2
4
+ version: 0.0.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: 2017-02-03 00:00:00.000000000 Z
11
+ date: 2017-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: keybase-unofficial
@@ -55,14 +55,14 @@ dependencies:
55
55
  description: Manages your passwords, environment, and more via KBFS.
56
56
  email: william@tuffbizz.com
57
57
  executables:
58
- - kbsecret-sessions
59
- - kbsecret-new-session
60
- - kbsecret-new
58
+ - kbsecret
61
59
  - kbsecret-rm
62
- - kbsecret-list
63
60
  - kbsecret-login
61
+ - kbsecret-new
64
62
  - kbsecret-env
65
- - kbsecret
63
+ - kbsecret-new-session
64
+ - kbsecret-list
65
+ - kbsecret-sessions
66
66
  extensions: []
67
67
  extra_rdoc_files: []
68
68
  files: