kbsecret 0.8.0.pre.4 → 0.8.0.pre.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/kbsecret +4 -2
- data/lib/kbsecret/cli.rb +8 -9
- data/lib/kbsecret/config.rb +39 -7
- data/lib/kbsecret/record/abstract.rb +13 -11
- data/lib/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac8d2f2070dfe623994a9fe08b79b9eed5ac8b4a
|
4
|
+
data.tar.gz: 88762582df2085091179d1f723585a25038f3ca7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2690cb31def84423bdcf818e1379ac502221e6a196036658ee34e5b34c621bbcca59efcfbdfc6df52dce5e7d9e7c2f4450ce58fe555ced38dd20d6c6ecb23890
|
7
|
+
data.tar.gz: 1aea1c3940e0503106e1f13a07af5c1ed7c6639ab4d35b0c2a927cee0462316cc35f016af52b2e03e9acb457ca582f484418b73857baba06405679a6ec23a18d
|
data/bin/kbsecret
CHANGED
@@ -156,10 +156,12 @@ end
|
|
156
156
|
|
157
157
|
command = normalize(ARGV.shift || "help")
|
158
158
|
|
159
|
+
args = KBSecret::Config.command_args(command) + ARGV
|
160
|
+
|
159
161
|
if builtin?(command)
|
160
|
-
send command, *
|
162
|
+
send command, *args
|
161
163
|
elsif external?(command) || internal?(command)
|
162
|
-
exec expand(command), *
|
164
|
+
exec expand(command), *args
|
163
165
|
else
|
164
166
|
KBSecret::CLI.die "Unknown command: '#{command}'."
|
165
167
|
end
|
data/lib/kbsecret/cli.rb
CHANGED
@@ -6,6 +6,7 @@ require "dreck"
|
|
6
6
|
|
7
7
|
module KBSecret
|
8
8
|
# An encapsulation of useful methods for kbsecret's CLI.
|
9
|
+
# Most methods in this class assume that they are being called from the context of
|
9
10
|
class CLI
|
10
11
|
# @return [Slop::Result, nil] the result of option parsing, if requested
|
11
12
|
# via {#slop}
|
@@ -39,16 +40,14 @@ module KBSecret
|
|
39
40
|
# cmd.opts # => Slop::Result
|
40
41
|
# cmd.args # => Dreck::Result
|
41
42
|
def self.create(&block)
|
42
|
-
|
43
|
-
yield cmd
|
44
|
-
cmd
|
43
|
+
CLI.new(&block)
|
45
44
|
end
|
46
45
|
|
47
46
|
# @api private
|
48
47
|
# @deprecated see {create}
|
49
|
-
def initialize
|
50
|
-
@
|
51
|
-
guard {
|
48
|
+
def initialize
|
49
|
+
@argv = ARGV.dup
|
50
|
+
guard { yield self }
|
52
51
|
end
|
53
52
|
|
54
53
|
# Parse options for a kbsecret utility, adding some default options for
|
@@ -58,7 +57,7 @@ module KBSecret
|
|
58
57
|
# @return [Slop::Result] the result of argument parsing
|
59
58
|
# @note This should be called within the block passed to {#initialize}.
|
60
59
|
def slop(cmds: [], errors: true)
|
61
|
-
@opts = Slop.parse suppress_errors: !errors do |o|
|
60
|
+
@opts = Slop.parse @argv, suppress_errors: !errors do |o|
|
62
61
|
o.separator "Options:"
|
63
62
|
|
64
63
|
yield o
|
@@ -78,7 +77,7 @@ module KBSecret
|
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
81
|
-
@
|
80
|
+
@argv = @opts.args
|
82
81
|
end
|
83
82
|
|
84
83
|
# Parse trailing arguments for a kbsecret utility, using the elements remaining
|
@@ -86,7 +85,7 @@ module KBSecret
|
|
86
85
|
# @param errors [Boolean] whether or not to produce (strict) Dreck errors
|
87
86
|
# @note *If* {#slop} is called, it must be called before this.
|
88
87
|
def dreck(errors: true, &block)
|
89
|
-
@args = Dreck.parse @
|
88
|
+
@args = Dreck.parse @argv, strict: errors do
|
90
89
|
instance_eval(&block)
|
91
90
|
end
|
92
91
|
end
|
data/lib/kbsecret/config.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "yaml"
|
4
3
|
require "fileutils"
|
4
|
+
require "inih"
|
5
|
+
require "shellwords"
|
6
|
+
require "yaml"
|
5
7
|
|
6
8
|
module KBSecret
|
7
9
|
# Global and per-session configuration for kbsecret.
|
@@ -14,6 +16,10 @@ module KBSecret
|
|
14
16
|
# @api private
|
15
17
|
CONFIG_FILE = File.join(CONFIG_DIR, "config.yml").freeze
|
16
18
|
|
19
|
+
# The command configuration file.
|
20
|
+
# @api private
|
21
|
+
COMMAND_CONFIG_FILE = File.join(CONFIG_DIR, "commands.ini").freeze
|
22
|
+
|
17
23
|
# Configuration facets used for method generation.
|
18
24
|
# @api private
|
19
25
|
CONFIG_FACETS = {
|
@@ -65,6 +71,26 @@ module KBSecret
|
|
65
71
|
@config[key]
|
66
72
|
end
|
67
73
|
|
74
|
+
# Fetch the configuration for a `kbsecret` command.
|
75
|
+
# @param cmd [String] the short name of the command
|
76
|
+
# @return [Hash, nil] the command's configuration
|
77
|
+
# @example
|
78
|
+
# # retrieves the config for `kbsecret-list`
|
79
|
+
# Config.command("list") # => { "args" => "...", }
|
80
|
+
def self.command(cmd)
|
81
|
+
@command_config[cmd]
|
82
|
+
end
|
83
|
+
|
84
|
+
# Fetch the configured default arguments for a `kbsecret` command.
|
85
|
+
# @param cmd [String] the short name of the command
|
86
|
+
# @return [Array] the command's default arguments
|
87
|
+
# @note Default arguments are split according to normal shell splitting rules.
|
88
|
+
# @example
|
89
|
+
# Config.command_args("list") # => ["--show-all"]
|
90
|
+
def self.command_args(cmd)
|
91
|
+
@command_config.dig(cmd, "args")&.shellsplit || []
|
92
|
+
end
|
93
|
+
|
68
94
|
# @!method session(label)
|
69
95
|
# Retrieve a session's configuration.
|
70
96
|
# @param label [String, Symbol] the session's label
|
@@ -134,12 +160,18 @@ module KBSecret
|
|
134
160
|
end
|
135
161
|
end
|
136
162
|
|
137
|
-
if File.exist?(CONFIG_FILE)
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
163
|
+
user_config = if File.exist?(CONFIG_FILE)
|
164
|
+
YAML.load_file(CONFIG_FILE)
|
165
|
+
else
|
166
|
+
FileUtils.mkdir_p CONFIG_DIR
|
167
|
+
DEFAULT_CONFIG
|
168
|
+
end
|
169
|
+
|
170
|
+
@command_config = if File.exist?(COMMAND_CONFIG_FILE)
|
171
|
+
INIH.load(COMMAND_CONFIG_FILE)
|
172
|
+
else
|
173
|
+
{}
|
174
|
+
end
|
143
175
|
|
144
176
|
@config = DEFAULT_CONFIG.merge(user_config)
|
145
177
|
@config[:sessions].merge!(DEFAULT_SESSION)
|
@@ -122,12 +122,13 @@ module KBSecret
|
|
122
122
|
# @param body [Hash<Symbol, String>] a mapping of the record's data fields
|
123
123
|
# @note Creation does *not* sync the new record; see {#sync!} for that.
|
124
124
|
def initialize(session, label, **body)
|
125
|
-
@session
|
126
|
-
@timestamp
|
127
|
-
@label
|
128
|
-
@type
|
129
|
-
@data
|
130
|
-
@path
|
125
|
+
@session = session
|
126
|
+
@timestamp = Time.now.to_i
|
127
|
+
@label = label.to_s
|
128
|
+
@type = self.class.type
|
129
|
+
@data = { @type => body }
|
130
|
+
@path = File.join(session.directory, "#{label}.json")
|
131
|
+
@defer_sync = false
|
131
132
|
|
132
133
|
populate_internal_fields
|
133
134
|
end
|
@@ -137,11 +138,12 @@ module KBSecret
|
|
137
138
|
# @return [void]
|
138
139
|
# @api private
|
139
140
|
def initialize_from_hash(hsh)
|
140
|
-
@timestamp
|
141
|
-
@label
|
142
|
-
@type
|
143
|
-
@data
|
144
|
-
@path
|
141
|
+
@timestamp = hsh[:timestamp]
|
142
|
+
@label = hsh[:label]
|
143
|
+
@type = hsh[:type].to_sym
|
144
|
+
@data = hsh[:data]
|
145
|
+
@path = File.join(session.directory, "#{label}.json")
|
146
|
+
@defer_sync = false
|
145
147
|
end
|
146
148
|
|
147
149
|
# @!method data_fields
|
data/lib/version.rb
CHANGED
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.8.0.pre.
|
4
|
+
version: 0.8.0.pre.5
|
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-
|
11
|
+
date: 2017-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fpm
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 0.2.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: inih
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.1'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.1'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: keybase-unofficial
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|