kbsecret 0.7.0.pre.2 → 0.7.0.pre.3

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: 880375c3b35cffd81cc94adba77037fb59fdbeaa
4
- data.tar.gz: 05c2e322dfe48b7fa3b526b32c7233d6778c0651
3
+ metadata.gz: 8c5f8f62886813839cd84f823e1b3c5e1d0ef621
4
+ data.tar.gz: 7b8bfe9c9672bff900825568001362790b88a1db
5
5
  SHA512:
6
- metadata.gz: 33a12d9bc5c28081e036a546ee05256dadfde708fe6dafd9ad211174cbf97f5efdd455e36f0b2d3a479a42aa4a46e920d88878c78bdab6bf461642032c8295d8
7
- data.tar.gz: a068a60e73e107793ffee460cc86524f701a87dae2b4a987789f1d5f9c882a9a4284fd95b9dc532284f5c2769a15019b37cb5bb728fa640f9184252b72cbfe49
6
+ metadata.gz: c2f59a671138ea5867c2511e20bb15098ca1f578bf0389b91046d8a17bfa4441c2ad15d62a6bd57a1ea513106e561e8d576f325b54d40a168b44ca2f9e395b79
7
+ data.tar.gz: 04e18852305aba35410105cf6371ef76ca2ce8f3a4e6ba5849437e91345d22ead4144eb6de8bd4d911eef3746d24a4c9e578040e41fbf1425dcedbb952cbdaec
data/README.md CHANGED
@@ -24,6 +24,10 @@ kbsecret is available via [RubyGems](https://rubygems.org/gems/kbsecret):
24
24
 
25
25
  ```bash
26
26
  $ gem install kbsecret
27
+
28
+ # or, install the prerelease:
29
+
30
+ $ gem install --pre kbsecret
27
31
  ```
28
32
 
29
33
  For hacking:
@@ -53,7 +53,7 @@ end
53
53
  fields = if $stdin.tty? && !cmd.opts.args?
54
54
  prompt = TTY::Prompt.new
55
55
  klass = Record.class_for(resolved_type)
56
- klass.data_fields.map do |field|
56
+ klass.external_fields.map do |field|
57
57
  if cmd.opts.generate? && klass.sensitive?(field)
58
58
  generator.secret
59
59
  else
@@ -33,13 +33,16 @@ module KBSecret
33
33
  # Add a field to the record's data.
34
34
  # @param field [Symbol] the new field's name
35
35
  # @param sensitive [Boolean] whether the field is sensitive (e.g., a password)
36
+ # @param internal [Boolean] whether the field should be populated by the user
36
37
  # @return [void]
37
- def data_field(field, sensitive: true)
38
+ def data_field(field, sensitive: true, internal: false)
38
39
  @fields ||= []
39
40
  @sensitive ||= {}
41
+ @internal ||= {}
40
42
 
41
43
  @fields << field
42
44
  @sensitive[field] = sensitive
45
+ @internal[field] = internal
43
46
 
44
47
  gen_methods field
45
48
  end
@@ -67,11 +70,27 @@ module KBSecret
67
70
  !!@sensitive[field]
68
71
  end
69
72
 
73
+ # @param field [Symbol] the field's name
74
+ # @return [Boolean] whether the field is internal
75
+ # @note Fields that are marked as "internal" should *not* be presented to the user
76
+ # for population. Instead, it is up to the record type itself to define a reasonable
77
+ # default (and subsequent values) for these fields.
78
+ def internal?(field)
79
+ !!@internal[field]
80
+ end
81
+
70
82
  # @return [Array<Symbol>] all data fields for the record class
83
+ # @note This includes internal fields, which are generated. See {external_fields}
84
+ # for the list of exclusively external fields.
71
85
  def data_fields
72
86
  @fields
73
87
  end
74
88
 
89
+ # @return [Array<Symbol>] all external data fields for the record class
90
+ def external_fields
91
+ @fields.reject { |f| internal? f }
92
+ end
93
+
75
94
  # @return [Symbol] the record's type
76
95
  # @example
77
96
  # KBSecret::Record::Abstract.type # => :abstract
@@ -100,13 +119,14 @@ module KBSecret
100
119
  # Create a brand new record, associated with a session.
101
120
  # @param session [Session] the session to associate with
102
121
  # @param label [String, Symbol] the new record's label
122
+ # @param body [Hash<Symbol, String>] a mapping of the record's data fields
103
123
  # @note Creation does *not* sync the new record; see {#sync!} for that.
104
- def initialize(session, label)
124
+ def initialize(session, label, **body)
105
125
  @session = session
106
126
  @timestamp = Time.now.to_i
107
127
  @label = label.to_s
108
128
  @type = self.class.type
109
- @data = {}
129
+ @data = { @type => body }
110
130
  @path = File.join(session.directory, "#{label}.json")
111
131
  end
112
132
 
@@ -124,9 +144,13 @@ module KBSecret
124
144
 
125
145
  # @!method data_fields
126
146
  # @return (see KBSecret::Record::Abstract.data_fields)
147
+ # @!method external_fields
148
+ # @return (see KBSecret::Record::Abstract.external_fields)
127
149
  # @!method sensitive?
128
150
  # @return (see KBSecret::Record::Abstract.sensitive?)
129
- def_delegators :"self.class", :data_fields, :sensitive?
151
+ # @!method internal?
152
+ # @return (see KBSecret::Record::Abstract.internal?)
153
+ def_delegators :"self.class", :data_fields, :external_fields, :sensitive?, :internal?
130
154
 
131
155
  # Create a string representation of the current record.
132
156
  # @return [String] the string representation
@@ -14,14 +14,7 @@ module KBSecret
14
14
  # @param variable [String] the new record's variable
15
15
  # @param value [String] the new record's value
16
16
  def initialize(session, label, variable, value)
17
- super(session, label)
18
-
19
- @data = {
20
- environment: {
21
- variable: variable.shellescape,
22
- value: value.shellescape,
23
- },
24
- }
17
+ super(session, label, variable: variable.shellescape, value: value.shellescape)
25
18
  end
26
19
 
27
20
  # @return [String] a sh-style environment assignment
@@ -12,14 +12,7 @@ module KBSecret
12
12
  # @param user [String] the new record's username
13
13
  # @param pass [String] the new record's password
14
14
  def initialize(session, label, user, pass)
15
- super(session, label)
16
-
17
- @data = {
18
- login: {
19
- username: user,
20
- password: pass,
21
- },
22
- }
15
+ super(session, label, username: user, password: pass)
23
16
  end
24
17
  end
25
18
  end
@@ -12,14 +12,7 @@ module KBSecret
12
12
  # @param code [String] the code
13
13
  # @param description [String] a description of the code
14
14
  def initialize(session, label, code, description)
15
- super(session, label)
16
-
17
- @data = {
18
- snippet: {
19
- code: code,
20
- description: description,
21
- },
22
- }
15
+ super(session, label, code: code, description: description)
23
16
  end
24
17
  end
25
18
  end
@@ -17,24 +17,15 @@ module KBSecret
17
17
  # last suspended via {#suspend!} *or* finished via {#complete!}.
18
18
  class Todo < Abstract
19
19
  data_field :todo, sensitive: false
20
- data_field :status, sensitive: false
21
- data_field :start, sensitive: false
22
- data_field :stop, sensitive: false
20
+ data_field :status, sensitive: false, internal: true
21
+ data_field :start, sensitive: false, internal: true
22
+ data_field :stop, sensitive: false, internal: true
23
23
 
24
24
  # @param session [Session] the session to associate with
25
25
  # @param label [Symbol] the new record's label
26
26
  # @param todo [String] the to do item
27
27
  def initialize(session, label, todo)
28
- super(session, label)
29
-
30
- @data = {
31
- todo: {
32
- todo: todo,
33
- status: "suspended",
34
- start: nil,
35
- stop: nil,
36
- },
37
- }
28
+ super(session, label, todo: todo, status: "suspended", start: nil, stop: nil)
38
29
  end
39
30
 
40
31
  # @return [Boolean] whether or not the item is marked as started
@@ -10,13 +10,7 @@ module KBSecret
10
10
  # @param label [Symbol] the new record's label
11
11
  # @param text [String] the new record's unstructured text
12
12
  def initialize(session, label, text)
13
- super(session, label)
14
-
15
- @data = {
16
- unstructured: {
17
- text: text,
18
- },
19
- }
13
+ super(session, label, text: text)
20
14
  end
21
15
  end
22
16
  end
@@ -63,8 +63,8 @@ module KBSecret
63
63
  # arguments does not match the record type's constructor
64
64
  def add_record(type, label, *args)
65
65
  klass = Record.class_for(type.to_sym)
66
-
67
66
  arity = klass.instance_method(:initialize).arity - 2
67
+
68
68
  raise RecordCreationArityError.new(arity, args.size) unless arity == args.size
69
69
 
70
70
  record = klass.new(self, label.to_s, *args)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module KBSecret
4
4
  # kbsecret's current version
5
- VERSION = "0.7.0.pre.2"
5
+ VERSION = "0.7.0.pre.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: 0.7.0.pre.2
4
+ version: 0.7.0.pre.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-07-12 00:00:00.000000000 Z
11
+ date: 2017-07-15 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.1.1
103
+ version: 0.2.1
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.1.1
110
+ version: 0.2.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: keybase-unofficial
113
113
  requirement: !ruby/object:Gem::Requirement