kbsecret 0.2.2 → 0.3.0
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 +4 -4
- data/bin/kbsecret +26 -31
- data/bin/kbsecret-dump-fields +9 -2
- data/bin/kbsecret-env +2 -1
- data/bin/kbsecret-list +2 -2
- data/bin/kbsecret-login +3 -2
- data/bin/kbsecret-new +3 -3
- data/bin/kbsecret-new-session +2 -1
- data/bin/kbsecret-pass +2 -1
- data/bin/kbsecret-raw-edit +4 -5
- data/bin/kbsecret-rm +2 -1
- data/bin/kbsecret-rm-session +2 -1
- data/bin/kbsecret-sessions +2 -1
- data/bin/kbsecret-stash-file +2 -1
- data/bin/kbsecret-todo +3 -2
- data/lib/kbsecret/config.rb +12 -10
- data/lib/kbsecret/exceptions.rb +2 -0
- data/lib/kbsecret/record/abstract.rb +22 -9
- data/lib/kbsecret/record/environment.rb +2 -0
- data/lib/kbsecret/record/login.rb +2 -0
- data/lib/kbsecret/record/snippet.rb +2 -0
- data/lib/kbsecret/record/todo.rb +5 -5
- data/lib/kbsecret/record/unstructured.rb +3 -1
- data/lib/kbsecret/record.rb +4 -2
- data/lib/kbsecret/session.rb +7 -7
- data/lib/kbsecret.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 726c2a148f51589eeef719b170d7f5102532b0f1
|
4
|
+
data.tar.gz: 2500fec63f6f4a1f843197fc2e5e69be64232723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cec6a334486cf1286c2a11e4192b834a477c4472535192a1ecaf136dc54068fd64d3bae22e90340e5463580d2202a5a4fb2a9d5cff103a21165a9bba015673d1
|
7
|
+
data.tar.gz: 0acfe368d0e5891a58d905917885980449cd38f9c9d87b0c634d16f2b4b019140d63d152c5f22a052aebbe0837b86c19c3f49c5924ec90869460649ef428edc9
|
data/bin/kbsecret
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
|
5
|
-
BUILTIN_CMDS = [
|
6
|
-
"help",
|
7
|
-
"version",
|
8
|
-
"commands",
|
9
|
-
"types",
|
10
|
-
"conf",
|
11
|
-
].freeze
|
6
|
+
BUILTIN_CMDS = %w[help version commands types conf].freeze
|
12
7
|
|
13
8
|
EXT_PATHS = ENV["PATH"].split(File::PATH_SEPARATOR).map do |path|
|
14
9
|
Dir[File.join(path, "kbsecret-*")]
|
@@ -18,13 +13,24 @@ EXT_CMDS = EXT_PATHS.map do |c|
|
|
18
13
|
File.basename(c, File.extname(c)).sub!("kbsecret-", "")
|
19
14
|
end.freeze
|
20
15
|
|
21
|
-
ALIASES = Hash.new { |_, k| k }.update(
|
16
|
+
ALIASES = Hash.new { |_, k| k }.update(
|
22
17
|
"--help" => "help",
|
23
|
-
"-h" => "help"
|
24
|
-
|
18
|
+
"-h" => "help"
|
19
|
+
).freeze
|
25
20
|
|
26
21
|
ALL_CMDS = (ALIASES.keys + BUILTIN_CMDS + EXT_CMDS).freeze
|
27
22
|
|
23
|
+
KBSECRET_HELP = <<~EOS
|
24
|
+
Usage:
|
25
|
+
kbsecret <command> <args ...>
|
26
|
+
|
27
|
+
Available commands:
|
28
|
+
#{ALL_CMDS.join(", ")}
|
29
|
+
|
30
|
+
More more information about a particular command, try:
|
31
|
+
kbsecret help <command>
|
32
|
+
EOS
|
33
|
+
|
28
34
|
def external?(cmd)
|
29
35
|
EXT_CMDS.include?(cmd)
|
30
36
|
end
|
@@ -49,24 +55,13 @@ end
|
|
49
55
|
def help(*args)
|
50
56
|
command = normalize args.shift
|
51
57
|
if command.nil?
|
52
|
-
puts
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
Available commands:
|
57
|
-
#{ALL_CMDS.join(", ")}
|
58
|
-
|
59
|
-
More more information about a particular command, try:
|
60
|
-
kbsecret help <command>
|
61
|
-
EOS
|
58
|
+
puts KBSECRET_HELP
|
59
|
+
elsif builtin? command
|
60
|
+
send "#{command}_help"
|
62
61
|
else
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
# XXX: this probably doesn't make sense, since not every user command
|
67
|
-
# will implement --help.
|
68
|
-
system expand(command), "--help"
|
69
|
-
end
|
62
|
+
# XXX: this probably doesn't make sense, since not every user command
|
63
|
+
# will implement --help.
|
64
|
+
system expand(command), "--help"
|
70
65
|
end
|
71
66
|
end
|
72
67
|
|
@@ -83,7 +78,7 @@ def help_help
|
|
83
78
|
EOS
|
84
79
|
end
|
85
80
|
|
86
|
-
def version(*
|
81
|
+
def version(*_args)
|
87
82
|
puts <<~EOS
|
88
83
|
kbsecret version #{KBSecret::VERSION}.
|
89
84
|
EOS
|
@@ -98,7 +93,7 @@ def version_help
|
|
98
93
|
EOS
|
99
94
|
end
|
100
95
|
|
101
|
-
def commands
|
96
|
+
def commands(*_args)
|
102
97
|
puts ALL_CMDS.join("\n")
|
103
98
|
end
|
104
99
|
|
@@ -111,7 +106,7 @@ def commands_help
|
|
111
106
|
EOS
|
112
107
|
end
|
113
108
|
|
114
|
-
def types
|
109
|
+
def types(*_args)
|
115
110
|
puts KBSecret::Record.record_types.join("\n")
|
116
111
|
end
|
117
112
|
|
@@ -124,7 +119,7 @@ def types_help
|
|
124
119
|
EOS
|
125
120
|
end
|
126
121
|
|
127
|
-
def conf
|
122
|
+
def conf(*_args)
|
128
123
|
abort("You need to set $EDITOR!") unless ENV["EDITOR"]
|
129
124
|
Process.spawn("#{ENV["EDITOR"]} #{KBSecret::Config::CONFIG_FILE}")
|
130
125
|
end
|
data/bin/kbsecret-dump-fields
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -12,6 +13,8 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
12
13
|
EOS
|
13
14
|
|
14
15
|
o.string "-s", "--session", "the session name", default: :default
|
16
|
+
o.bool "-x", "--terse", "output in field:value format"
|
17
|
+
o.bool "-i", "--ifs", "separate terse pairs with this string", default: ":"
|
15
18
|
|
16
19
|
o.on "-h", "--help" do
|
17
20
|
puts o
|
@@ -19,7 +22,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
19
22
|
end
|
20
23
|
|
21
24
|
o.on "--introspect-flags" do
|
22
|
-
puts o.options.flat_map
|
25
|
+
puts o.options.flat_map(&:flags).join "\n"
|
23
26
|
exit
|
24
27
|
end
|
25
28
|
end
|
@@ -40,4 +43,8 @@ abort("Fatal: No such record.") unless record
|
|
40
43
|
field_values = record.class.data_fields.map { |f| record.send f }
|
41
44
|
field_pairs = record.class.data_fields.zip(field_values)
|
42
45
|
|
43
|
-
|
46
|
+
if opts.terse?
|
47
|
+
puts field_pairs.map { |f, v| "#{f}#{opts[:ifs]}#{v}" }.join "\n"
|
48
|
+
else
|
49
|
+
puts field_pairs.map { |f, v| "#{f}: #{v}" }.join "\n"
|
50
|
+
end
|
data/bin/kbsecret-env
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -25,7 +26,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
25
26
|
end
|
26
27
|
|
27
28
|
o.on "--introspect-flags" do
|
28
|
-
puts o.options.flat_map
|
29
|
+
puts o.options.flat_map(&:flags).join "\n"
|
29
30
|
exit
|
30
31
|
end
|
31
32
|
end
|
data/bin/kbsecret-list
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -21,7 +22,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
21
22
|
end
|
22
23
|
|
23
24
|
o.on "--introspect-flags" do
|
24
|
-
puts o.options.flat_map
|
25
|
+
puts o.options.flat_map(&:flags).join "\n"
|
25
26
|
exit
|
26
27
|
end
|
27
28
|
end
|
@@ -46,4 +47,3 @@ records.each do |record|
|
|
46
47
|
|
47
48
|
puts line
|
48
49
|
end
|
49
|
-
|
data/bin/kbsecret-login
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -16,7 +17,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
16
17
|
EOS
|
17
18
|
|
18
19
|
o.bool "-a", "--all", "retrieve all login records, not just listed ones"
|
19
|
-
o.bool "-
|
20
|
+
o.bool "-x", "--terse", "output in label:username:password format"
|
20
21
|
o.string "-i", "--ifs", "separate terse fields with this string", default: ":"
|
21
22
|
o.string "-s", "--session", "the session name", default: :default
|
22
23
|
|
@@ -26,7 +27,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
26
27
|
end
|
27
28
|
|
28
29
|
o.on "--introspect-flags" do
|
29
|
-
puts o.options.flat_map
|
30
|
+
puts o.options.flat_map(&:flags).join "\n"
|
30
31
|
exit
|
31
32
|
end
|
32
33
|
end
|
data/bin/kbsecret-new
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -33,7 +34,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
33
34
|
end
|
34
35
|
|
35
36
|
o.on "--introspect-flags" do
|
36
|
-
puts o.options.flat_map
|
37
|
+
puts o.options.flat_map(&:flags).join "\n"
|
37
38
|
exit
|
38
39
|
end
|
39
40
|
end
|
@@ -74,9 +75,8 @@ else
|
|
74
75
|
fields = opts.args
|
75
76
|
end
|
76
77
|
|
77
|
-
|
78
78
|
begin
|
79
79
|
session.add_record(type, label, *fields)
|
80
80
|
rescue => e
|
81
|
-
abort "Fatal: #{e
|
81
|
+
abort "Fatal: #{e}."
|
82
82
|
end
|
data/bin/kbsecret-new-session
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "keybase"
|
4
5
|
require "kbsecret"
|
@@ -26,7 +27,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
26
27
|
end
|
27
28
|
|
28
29
|
o.on "--introspect-flags" do
|
29
|
-
puts o.options.flat_map
|
30
|
+
puts o.options.flat_map(&:flags).join "\n"
|
30
31
|
exit
|
31
32
|
end
|
32
33
|
end
|
data/bin/kbsecret-pass
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -25,7 +26,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
25
26
|
end
|
26
27
|
|
27
28
|
o.on "--introspect-flags" do
|
28
|
-
puts o.options.flat_map
|
29
|
+
puts o.options.flat_map(&:flags).join "\n"
|
29
30
|
exit
|
30
31
|
end
|
31
32
|
end
|
data/bin/kbsecret-raw-edit
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -22,16 +23,14 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
22
23
|
end
|
23
24
|
|
24
25
|
o.on "--introspect-flags" do
|
25
|
-
puts o.options.flat_map
|
26
|
+
puts o.options.flat_map(&:flags).join "\n"
|
26
27
|
exit
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
31
|
sess_name = opts[:session]
|
31
32
|
|
32
|
-
unless ENV["EDITOR"]
|
33
|
-
abort "Fatal: $EDITOR is not set."
|
34
|
-
end
|
33
|
+
abort "Fatal: $EDITOR is not set." unless ENV["EDITOR"]
|
35
34
|
|
36
35
|
unless KBSecret::Config.session? sess_name
|
37
36
|
abort "Fatal: Unknown session: '#{sess_name}'."
|
@@ -39,7 +38,7 @@ end
|
|
39
38
|
|
40
39
|
session = KBSecret::Session.new label: sess_name
|
41
40
|
label = opts.args.shift
|
42
|
-
record = session.records.find { |r| r.label == label}
|
41
|
+
record = session.records.find { |r| r.label == label }
|
43
42
|
|
44
43
|
if record
|
45
44
|
Process.spawn("#{ENV["EDITOR"]} #{record.path}")
|
data/bin/kbsecret-rm
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -23,7 +24,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
23
24
|
end
|
24
25
|
|
25
26
|
o.on "--introspect-flags" do
|
26
|
-
puts o.options.flat_map
|
27
|
+
puts o.options.flat_map(&:flags).join "\n"
|
27
28
|
exit
|
28
29
|
end
|
29
30
|
end
|
data/bin/kbsecret-rm-session
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -23,7 +24,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
23
24
|
end
|
24
25
|
|
25
26
|
o.on "--introspect-flags" do
|
26
|
-
puts o.options.flat_map
|
27
|
+
puts o.options.flat_map(&:flags).join "\n"
|
27
28
|
exit
|
28
29
|
end
|
29
30
|
end
|
data/bin/kbsecret-sessions
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -20,7 +21,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
20
21
|
end
|
21
22
|
|
22
23
|
o.on "--introspect-flags" do
|
23
|
-
puts o.options.flat_map
|
24
|
+
puts o.options.flat_map(&:flags).join "\n"
|
24
25
|
exit
|
25
26
|
end
|
26
27
|
end
|
data/bin/kbsecret-stash-file
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -23,7 +24,7 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
23
24
|
end
|
24
25
|
|
25
26
|
o.on "--introspect-flags" do
|
26
|
-
puts o.options.flat_map
|
27
|
+
puts o.options.flat_map(&:flags).join "\n"
|
27
28
|
exit
|
28
29
|
end
|
29
30
|
end
|
data/bin/kbsecret-todo
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "kbsecret"
|
4
5
|
require "slop"
|
@@ -24,8 +25,8 @@ opts = Slop.parse suppress_errors: true do |o|
|
|
24
25
|
end
|
25
26
|
|
26
27
|
o.on "--introspect-flags" do
|
27
|
-
subcmds = [
|
28
|
-
comp = o.options.flat_map
|
28
|
+
subcmds = %w[start suspend complete]
|
29
|
+
comp = o.options.flat_map(&:flags) + subcmds
|
29
30
|
puts comp.join "\n"
|
30
31
|
exit
|
31
32
|
end
|
data/lib/kbsecret/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "yaml"
|
2
4
|
require "fileutils"
|
3
5
|
|
@@ -21,27 +23,27 @@ module KBSecret
|
|
21
23
|
default: {
|
22
24
|
users: [Keybase.current_user],
|
23
25
|
root: "kbsecret",
|
24
|
-
}
|
25
|
-
}
|
26
|
+
},
|
27
|
+
},
|
26
28
|
}.freeze
|
27
29
|
|
28
30
|
# Retrieve a configured value.
|
29
31
|
# @param key [String]
|
30
32
|
# @return [Object] the corresponding configuration
|
31
33
|
def self.[](key)
|
32
|
-
|
34
|
+
@config[key]
|
33
35
|
end
|
34
36
|
|
35
37
|
# Retrieve a session's configuration.
|
36
38
|
# @param sess [Symbol] the session's label
|
37
39
|
# @return [Hash] the session configuration
|
38
40
|
def self.session(sess)
|
39
|
-
|
41
|
+
@config[:sessions][sess]
|
40
42
|
end
|
41
43
|
|
42
44
|
# @return [Array<Symbol>] all configured session labels
|
43
45
|
def self.session_labels
|
44
|
-
|
46
|
+
@config[:sessions].keys
|
45
47
|
end
|
46
48
|
|
47
49
|
# @param sess [Symbol] the session label
|
@@ -55,8 +57,8 @@ module KBSecret
|
|
55
57
|
# @param hsh [Hash] the session configuration
|
56
58
|
# @return [void]
|
57
59
|
def self.configure_session(label, hsh)
|
58
|
-
|
59
|
-
File.open(CONFIG_FILE, "w") { |io| io.write
|
60
|
+
@config[:sessions][label.to_sym] = hsh
|
61
|
+
File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml }
|
60
62
|
end
|
61
63
|
|
62
64
|
# Deconfigure a session.
|
@@ -66,8 +68,8 @@ module KBSecret
|
|
66
68
|
# it "invisible" to `kbsecret`. To actually remove all files associated
|
67
69
|
# with a session, see {KBSecret::Session#unlink!}.
|
68
70
|
def self.deconfigure_session(label)
|
69
|
-
|
70
|
-
File.open(CONFIG_FILE, "w") { |io| io.write
|
71
|
+
@config[:sessions].delete(label.to_sym)
|
72
|
+
File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml }
|
71
73
|
end
|
72
74
|
|
73
75
|
if File.exist?(CONFIG_FILE)
|
@@ -78,6 +80,6 @@ module KBSecret
|
|
78
80
|
File.open(CONFIG_FILE, "w") { |io| io.write DEFAULT_CONFIG.to_yaml }
|
79
81
|
end
|
80
82
|
|
81
|
-
|
83
|
+
@config = DEFAULT_CONFIG.merge(user_config)
|
82
84
|
end
|
83
85
|
end
|
data/lib/kbsecret/exceptions.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "json"
|
2
4
|
|
3
5
|
module KBSecret
|
@@ -20,6 +22,13 @@ module KBSecret
|
|
20
22
|
@fields ||= []
|
21
23
|
@fields << field
|
22
24
|
|
25
|
+
gen_methods field
|
26
|
+
end
|
27
|
+
|
28
|
+
# Generate the methods used to access a given field.
|
29
|
+
# @param field [Symbol] the new field's name
|
30
|
+
# @return [void]
|
31
|
+
def gen_methods(field)
|
23
32
|
class_eval %[
|
24
33
|
def #{field}
|
25
34
|
@data[self.class.type.to_sym]["#{field}".to_sym]
|
@@ -42,7 +51,11 @@ module KBSecret
|
|
42
51
|
# @example
|
43
52
|
# KBSecret::Record::Abstract.type # => :abstract
|
44
53
|
def type
|
45
|
-
name.split("::")
|
54
|
+
name.split("::") # ["Foo", "BarBaz"]
|
55
|
+
.last # "BarBaz"
|
56
|
+
.gsub(/([^A-Z])([A-Z]+)/, '\1_\2') # "Bar_Baz"
|
57
|
+
.downcase # "bar_baz"
|
58
|
+
.to_sym # :bar_baz
|
46
59
|
end
|
47
60
|
|
48
61
|
# Load the given hash-representation into a record.
|
@@ -51,7 +64,7 @@ module KBSecret
|
|
51
64
|
# @return [Record::AbstractRecord] the created record
|
52
65
|
# @api private
|
53
66
|
def load!(session, hsh)
|
54
|
-
instance
|
67
|
+
instance = allocate
|
55
68
|
instance.session = session
|
56
69
|
instance.initialize_from_hash(hsh)
|
57
70
|
|
@@ -64,11 +77,11 @@ module KBSecret
|
|
64
77
|
# @param label [Symbol] the new record's label
|
65
78
|
# @note Creation does *not* sync the new record; see {#sync!} for that.
|
66
79
|
def initialize(session, label)
|
67
|
-
@session
|
80
|
+
@session = session
|
68
81
|
@timestamp = Time.now.to_i
|
69
|
-
@label
|
70
|
-
@type
|
71
|
-
@data
|
82
|
+
@label = label
|
83
|
+
@type = self.class.type
|
84
|
+
@data = {}
|
72
85
|
end
|
73
86
|
|
74
87
|
# Fill in instance fields from a record's hash-representation.
|
@@ -77,9 +90,9 @@ module KBSecret
|
|
77
90
|
# @api private
|
78
91
|
def initialize_from_hash(hsh)
|
79
92
|
@timestamp = hsh[:timestamp]
|
80
|
-
@label
|
81
|
-
@type
|
82
|
-
@data
|
93
|
+
@label = hsh[:label]
|
94
|
+
@type = hsh[:type].to_sym
|
95
|
+
@data = hsh[:data]
|
83
96
|
end
|
84
97
|
|
85
98
|
# The fully qualified path to the record's file.
|
data/lib/kbsecret/record/todo.rb
CHANGED
@@ -11,9 +11,9 @@ module KBSecret
|
|
11
11
|
# The start time is the date and time at which the item was started via
|
12
12
|
# {#start!}.
|
13
13
|
#
|
14
|
-
# The stop
|
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
|
-
class
|
16
|
+
class Todo < Abstract
|
17
17
|
data_field :todo
|
18
18
|
data_field :status
|
19
19
|
data_field :start
|
@@ -57,7 +57,7 @@ module KBSecret
|
|
57
57
|
return if started?
|
58
58
|
|
59
59
|
self.status = "started"
|
60
|
-
self.start
|
60
|
+
self.start = Time.now.to_s
|
61
61
|
end
|
62
62
|
|
63
63
|
# Suspend the to do item.
|
@@ -66,7 +66,7 @@ module KBSecret
|
|
66
66
|
def suspend!
|
67
67
|
return if suspended?
|
68
68
|
self.status = "suspended"
|
69
|
-
self.stop
|
69
|
+
self.stop = Time.now.to_s
|
70
70
|
end
|
71
71
|
|
72
72
|
# Complete the to do item.
|
@@ -75,7 +75,7 @@ module KBSecret
|
|
75
75
|
def complete!
|
76
76
|
return if completed?
|
77
77
|
self.status = "complete"
|
78
|
-
self.stop
|
78
|
+
self.stop = Time.now.to_s
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
data/lib/kbsecret/record.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "json"
|
2
4
|
|
3
5
|
# we have to require abstract first because ruby's module resolution is bad
|
@@ -38,9 +40,9 @@ module KBSecret
|
|
38
40
|
# @return [Record::AbstractRecord] the loaded record
|
39
41
|
# @api private
|
40
42
|
def self.load_record!(session, path)
|
41
|
-
hsh
|
43
|
+
hsh = JSON.parse(File.read(path), symbolize_names: true)
|
42
44
|
klass = record_classes.find { |c| c.type == hsh[:type].to_sym }
|
43
|
-
klass
|
45
|
+
klass&.load!(session, hsh)
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
data/lib/kbsecret/session.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "fileutils"
|
2
4
|
|
3
5
|
module KBSecret
|
@@ -19,11 +21,11 @@ module KBSecret
|
|
19
21
|
# specified in {Config::CONFIG_FILE}. To *create* a new session,
|
20
22
|
# see {Config.configure_session}.
|
21
23
|
def initialize(label: :default)
|
22
|
-
@label
|
23
|
-
@config
|
24
|
+
@label = label.to_sym
|
25
|
+
@config = Config.session(@label)
|
24
26
|
|
25
27
|
@directory = rel_path config[:root], mkdir: true
|
26
|
-
@records
|
28
|
+
@records = load_records!
|
27
29
|
end
|
28
30
|
|
29
31
|
# @param type [String, Symbol] the type of the records to return (or `nil` for all)
|
@@ -51,12 +53,10 @@ module KBSecret
|
|
51
53
|
# @raise RecordCreationArityError if the number of specified record
|
52
54
|
# arguments does not match the record type's constructor
|
53
55
|
def add_record(type, label, *args)
|
54
|
-
klass = Record.
|
56
|
+
klass = Record.class_for(type.to_sym)
|
55
57
|
arity = klass.instance_method(:initialize).arity - 2
|
56
58
|
|
57
|
-
unless arity == args.size
|
58
|
-
raise RecordCreationArityError.new(arity, args.size)
|
59
|
-
end
|
59
|
+
raise RecordCreationArityError.new(arity, args.size) unless arity == args.size
|
60
60
|
|
61
61
|
record = klass.new(self, label, *args)
|
62
62
|
records << record
|
data/lib/kbsecret.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "keybase"
|
2
4
|
|
3
5
|
require_relative "kbsecret/config"
|
@@ -8,7 +10,7 @@ require_relative "kbsecret/session"
|
|
8
10
|
# The primary namespace for kbsecret.
|
9
11
|
module KBSecret
|
10
12
|
# kbsecret's current version
|
11
|
-
VERSION = "0.
|
13
|
+
VERSION = "0.3.0"
|
12
14
|
|
13
15
|
# fail very early if the user doesn't have keybase and KBFS running
|
14
16
|
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.
|
4
|
+
version: 0.3.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-05-
|
11
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: keybase-unofficial
|