kbsecret 0.5.6 → 0.6.0

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: f988059d109942e54868a06c593c2f20f62972c6
4
- data.tar.gz: a6d1d9b5b52fcb4f136eab7ead9d404111855fc9
3
+ metadata.gz: 04bf388d61371a29a5f721a4a39a03037fbd674c
4
+ data.tar.gz: 4bc34dd530c79ecb34816c0013a36c47ecb969e4
5
5
  SHA512:
6
- metadata.gz: e627e140303c2966e2f824e751edd7bdd9e48bb999160b1ba9b498b8f1c14ceebc128ac331c20d0a5729665810033851f575ce200803c11a0ef179f90ca4698e
7
- data.tar.gz: 9700504918200ff1dd434a65466cecf666575205bcae655cac6208f12f942a8aa12e8a6348560b99f28c4f084baa51ee35c197d589ec342e3cb2ba5817036f80
6
+ metadata.gz: 6933f6c00c8ced6ebec24956790109f0238324e69194637fe7cabbb8be7cdac21e5de9732eba3c043f8cbc92d93def83195682013c1d019aca497423a04ff44a
7
+ data.tar.gz: 3fbd02c35aaf1531b0365e7475ab3047c6b07ac442bd83f195d656b613fae4d1a3f8e4d450ce1d770312c59a61fc4518f4e3e084f60ac425c0105ce02f071ed4
data/bin/kbsecret-new CHANGED
@@ -53,7 +53,8 @@ fields = if $stdin.tty? && !cmd.opts.args?
53
53
  prompt = TTY::Prompt.new
54
54
  klass = Record.class_for(resolved_type)
55
55
  klass.data_fields.map do |field|
56
- prompt.ask("#{field.capitalize}?", echo: cmd.opts.echo?)
56
+ prompt.ask "#{field.capitalize}?",
57
+ echo: !klass.sensitive?(field) || cmd.opts.echo?
57
58
  end
58
59
  else
59
60
  cmd.args[:fields]
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
+ require "forwardable"
4
5
 
5
6
  module KBSecret
6
7
  module Record
@@ -8,6 +9,8 @@ module KBSecret
8
9
  # more useful records.
9
10
  # @abstract
10
11
  class Abstract
12
+ extend Forwardable
13
+
11
14
  # @return [Session] the session associated with the record
12
15
  attr_accessor :session
13
16
 
@@ -29,10 +32,14 @@ module KBSecret
29
32
  class << self
30
33
  # Add a field to the record's data.
31
34
  # @param field [Symbol] the new field's name
35
+ # @param sensitive [Boolean] whether the field is sensitive (e.g., a password)
32
36
  # @return [void]
33
- def data_field(field)
34
- @fields ||= []
37
+ def data_field(field, sensitive: true)
38
+ @fields ||= []
39
+ @sensitive ||= {}
40
+
35
41
  @fields << field
42
+ @sensitive[field] = sensitive
36
43
 
37
44
  gen_methods field
38
45
  end
@@ -54,6 +61,12 @@ module KBSecret
54
61
  ]
55
62
  end
56
63
 
64
+ # @param field [Symbol] the field's name
65
+ # @return [Boolean] whether the field is sensitive
66
+ def sensitive?(field)
67
+ !!@sensitive[field]
68
+ end
69
+
57
70
  # @return [Array<Symbol>] all data fields for the record class
58
71
  def data_fields
59
72
  @fields
@@ -63,11 +76,11 @@ module KBSecret
63
76
  # @example
64
77
  # KBSecret::Record::Abstract.type # => :abstract
65
78
  def type
66
- name.split("::") # ["Foo", "BarBaz"]
67
- .last # "BarBaz"
68
- .gsub(/([^A-Z])([A-Z]+)/, '\1_\2') # "Bar_Baz"
69
- .downcase # "bar_baz"
70
- .to_sym # :bar_baz
79
+ name.split("::")
80
+ .last
81
+ .gsub(/([^A-Z])([A-Z]+)/, '\1_\2')
82
+ .downcase
83
+ .to_sym
71
84
  end
72
85
 
73
86
  # Load the given hash-representation into a record.
@@ -109,6 +122,12 @@ module KBSecret
109
122
  @path = File.join(session.directory, "#{label}.json")
110
123
  end
111
124
 
125
+ # @!method data_fields
126
+ # @return (see KBSecret::Record::Abstract.data_fields)
127
+ # @!method sensitive?
128
+ # @return (see KBSecret::Record::Abstract.sensitive?)
129
+ def_delegators :"self.class", :data_fields, :sensitive?
130
+
112
131
  # Create a string representation of the current record.
113
132
  # @return [String] the string representation
114
133
  def to_s
@@ -6,7 +6,7 @@ module KBSecret
6
6
  module Record
7
7
  # Represents a record containing an environment variable and value.
8
8
  class Environment < Abstract
9
- data_field :variable
9
+ data_field :variable, sensitive: false
10
10
  data_field :value
11
11
 
12
12
  # @param session [Session] the session to associate with
@@ -4,7 +4,7 @@ module KBSecret
4
4
  module Record
5
5
  # Represents a record containing a login (username, password) pair.
6
6
  class Login < Abstract
7
- data_field :username
7
+ data_field :username, sensitive: false
8
8
  data_field :password
9
9
 
10
10
  # @param session [Session] the session to associate with
@@ -4,8 +4,8 @@ module KBSecret
4
4
  module Record
5
5
  # Represents a record containing a code snippet and its description.
6
6
  class Snippet < Abstract
7
- data_field :code
8
- data_field :description
7
+ data_field :code, sensitive: false
8
+ data_field :description, sensitive: false
9
9
 
10
10
  # @param session [Session] the session to associate with
11
11
  # @param label [Symbol] the new record's label
@@ -14,10 +14,10 @@ module KBSecret
14
14
  # The stop time is the date and time at which the item was *either*
15
15
  # last suspended via {#suspend!} *or* finished via {#complete!}.
16
16
  class Todo < Abstract
17
- data_field :todo
18
- data_field :status
19
- data_field :start
20
- data_field :stop
17
+ data_field :todo, sensitive: false
18
+ data_field :status, sensitive: false
19
+ data_field :start, sensitive: false
20
+ data_field :stop, sensitive: false
21
21
 
22
22
  # @param session [Session] the session to associate with
23
23
  # @param label [Symbol] the new record's label
@@ -4,7 +4,7 @@ module KBSecret
4
4
  module Record
5
5
  # Represents a record containing unstructured text.
6
6
  class Unstructured < Abstract
7
- data_field :text
7
+ data_field :text, sensitive: false
8
8
 
9
9
  # @param session [Session] the session to associate with
10
10
  # @param label [Symbol] the new record's label
data/lib/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module KBSecret
4
4
  # kbsecret's current version
5
- VERSION = "0.5.6"
5
+ VERSION = "0.6.0"
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.5.6
4
+ version: 0.6.0
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-06-30 00:00:00.000000000 Z
11
+ date: 2017-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fpm
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.0.6
103
+ version: 0.0.7
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.0.6
110
+ version: 0.0.7
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: keybase-unofficial
113
113
  requirement: !ruby/object:Gem::Requirement