kbsecret 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f807d04b3f3365845cb00d88dc4c117815f8338
4
- data.tar.gz: d5aa5f00590f7660391758f9408eb567b8ff9258
3
+ metadata.gz: 8d652f203478d7a4d2500fbb5b9c0987014a0b59
4
+ data.tar.gz: 9ce0b6fe98e4d48be2ca27d56518c4942a3717e3
5
5
  SHA512:
6
- metadata.gz: ffb8f5e6d8658c48911ee49b7f2f9cc4127bbb3c92aea221a9b06b9727d15bde4f283170def0f9f9337b40186baa970434b89994ea6050aeace0f31f7c45cd10
7
- data.tar.gz: 3a0656fc05c14ae990ceea61619476edf8c67ceb7b21f88e4b092e7894466f69600926f62620f2e1b786832d73c31b239c48f5fc959c3a31d08e97cdd362d84a
6
+ metadata.gz: 835518bd8f610440bfbfb3231a00e3470435b97aeba5ab3b6e0ced99c55afba87100b55377c6c7af1c4000c197637e62c42dfd5ac8449158da7397acac282817
7
+ data.tar.gz: dd8c91cbb42ad8872835cd04fea5d2c0c7c697d27b23f88173351b8d758e5894e563853da27bd8ed4df7217aec2837d86d2cc764388ea3207aac7719ca8f1793
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "kbsecret"
4
+ require "slop"
5
+
6
+ opts = Slop.parse suppress_errors: true do |o|
7
+ o.banner = <<~EOS
8
+ Deconfigure (and optionally delete) a session.
9
+
10
+ Usage:
11
+ kbsecret rm-session --delete <label>
12
+
13
+ Example:
14
+ kbsecret rm-session old-keys
15
+ kbsecret rm-session --delete even-older-keys
16
+ EOS
17
+
18
+ o.bool "-d", "--delete", "unlink the session in addition to deconfiguration"
19
+
20
+ o.on "-h", "--help" do
21
+ puts o
22
+ exit
23
+ end
24
+
25
+ o.on "--introspect-flags" do
26
+ puts o.options.flat_map { |o| o.flags }.join "\n"
27
+ exit
28
+ end
29
+ end
30
+
31
+ label = opts.args.shift
32
+
33
+ abort "Fatal: I need the label of a session to deconfigure." unless label
34
+
35
+ unless KBSecret::Config.session? label
36
+ abort "Fatal: Unknown session: '#{label}'."
37
+ end
38
+
39
+ if opts.delete?
40
+ session = KBSecret::Session.new label: label
41
+ session.unlink!
42
+ end
43
+
44
+ KBSecret::Config.deconfigure_session label
@@ -51,13 +51,25 @@ module KBSecret
51
51
  end
52
52
 
53
53
  # Configure a session.
54
- # @param label [Symbol] the session label
54
+ # @param label [String, Symbol] the session label
55
55
  # @param hsh [Hash] the session configuration
56
+ # @return [void]
56
57
  def self.configure_session(label, hsh)
57
58
  @@config[:sessions][label.to_sym] = hsh
58
59
  File.open(CONFIG_FILE, "w") { |io| io.write @@config.to_yaml }
59
60
  end
60
61
 
62
+ # Deconfigure a session.
63
+ # @param label [String, Symbol] the session label
64
+ # @return [void]
65
+ # @note This only removes the given session from the configuration, making
66
+ # it "invisible" to `kbsecret`. To actually remove all files associated
67
+ # with a session, see {KBSecret::Session#unlink!}.
68
+ def self.deconfigure_session(label)
69
+ @@config[:sessions].delete(label.to_sym)
70
+ File.open(CONFIG_FILE, "w") { |io| io.write @@config.to_yaml }
71
+ end
72
+
61
73
  if File.exist?(CONFIG_FILE)
62
74
  user_config = YAML.load_file(CONFIG_FILE)
63
75
  else
@@ -1,3 +1,5 @@
1
+ require "fileutils"
2
+
1
3
  module KBSecret
2
4
  # Represents a session of N keybase users with collective read/write
3
5
  # access to a collection of records.
@@ -12,13 +14,13 @@ module KBSecret
12
14
  # @return [String] the fully-qualified path of the session
13
15
  attr_reader :directory
14
16
 
15
- # @param label [Symbol] the label of the session to initialize
17
+ # @param label [String, Symbol] the label of the session to initialize
16
18
  # @note This does not *create* a new session, but loads one already
17
19
  # specified in {Config::CONFIG_FILE}. To *create* a new session,
18
20
  # see {Config.configure_session}.
19
21
  def initialize(label: :default)
20
- @label = label
21
- @config = Config.session(label.to_sym)
22
+ @label = label.to_sym
23
+ @config = Config.session(@label)
22
24
 
23
25
  @directory = rel_path config[:root], mkdir: true
24
26
  @records = load_records!
@@ -79,6 +81,15 @@ module KBSecret
79
81
  record_labels.include?(label)
80
82
  end
81
83
 
84
+ # Delete the entire session.
85
+ # @return [void]
86
+ # @note Use this with caution, as *all* files under the session directory
87
+ # will be deleted. Furthermore, the session directory itself will
88
+ # be deleted, and this object will become garbage.
89
+ def unlink!
90
+ FileUtils.rm_rf(directory)
91
+ end
92
+
82
93
  private
83
94
 
84
95
  def record_paths
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.1.1".freeze
11
+ VERSION = "0.2.0".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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kbsecret
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
@@ -77,6 +77,7 @@ executables:
77
77
  - kbsecret-todo
78
78
  - kbsecret-new
79
79
  - kbsecret-dump-fields
80
+ - kbsecret-rm-session
80
81
  - kbsecret-env
81
82
  - kbsecret-new-session
82
83
  - kbsecret-list
@@ -97,6 +98,7 @@ files:
97
98
  - bin/kbsecret-pass
98
99
  - bin/kbsecret-raw-edit
99
100
  - bin/kbsecret-rm
101
+ - bin/kbsecret-rm-session
100
102
  - bin/kbsecret-sessions
101
103
  - bin/kbsecret-todo
102
104
  - lib/kbsecret.rb