Class: KBSecret::Config
- Inherits:
-
Object
- Object
- KBSecret::Config
- Defined in:
- lib/kbsecret/config.rb
Overview
Global and per-session configuration for kbsecret.
Constant Summary collapse
- CONFIG_DIR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The configuration directory.
File.("~/.config/kbsecret").freeze
- CONFIG_FILE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The configuration file.
File.join(CONFIG_DIR, "config.yml").freeze
- COMMAND_CONFIG_FILE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The command configuration file.
File.join(CONFIG_DIR, "commands.ini").freeze
- CUSTOM_TYPES_DIR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The directory searched for custom record types.
File.join(CONFIG_DIR, "record").freeze
- CONFIG_FACETS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Configuration facets used for method generation.
{ session: { plural: :sessions, except: Exceptions::SessionUnknownError, }, generator: { plural: :generators, except: Exceptions::GeneratorUnknownError, }, }.freeze
- DEFAULT_SESSION =
The default session configuration.
{ default: { users: [Keybase.current_user], root: "default", }, }.freeze
- DEFAULT_GENERATOR =
The default generator configuration.
{ default: { format: "hex", length: 16, }, }.freeze
- DEFAULT_CONFIG =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
configuration defaults
{ sessions: DEFAULT_SESSION.dup, generators: DEFAULT_GENERATOR.dup, }.freeze
Class Method Summary collapse
-
.[](key) ⇒ Object
Retrieve a configured value.
-
.command(cmd) ⇒ Hash?
Fetch the configuration for a
kbsecretcommand. -
.command_args(cmd) ⇒ Array
Fetch the configured default arguments for a
kbsecretcommand. -
.sync! ⇒ void
Writes the user's configuration to disk.
Instance Method Summary collapse
-
#configure_generator(label, hsh) ⇒ void
Configure a secret generator.
-
#configure_session(label, hsh) ⇒ void
Configure a session.
-
#deconfigure_generator(label) ⇒ void
Deconfigure a generator.
-
#deconfigure_session(label) ⇒ void
Deconfigure a session.
-
#generator(label) ⇒ Hash
Retrieve a generator's configuration.
-
#generator?(label) ⇒ Boolean
Whether or not the given generator is configured.
-
#generator_labels ⇒ Array<Symbol>
All configured session labels.
-
#session(label) ⇒ Hash
Retrieve a session's configuration.
-
#session?(label) ⇒ Boolean
Whether or not the given session is configured.
-
#session_labels ⇒ Array<Symbol>
All configured session labels.
Class Method Details
.[](key) ⇒ Object
Retrieve a configured value.
73 74 75 |
# File 'lib/kbsecret/config.rb', line 73 def self.[](key) @config[key] end |
.command(cmd) ⇒ Hash?
Fetch the configuration for a kbsecret command.
83 84 85 |
# File 'lib/kbsecret/config.rb', line 83 def self.command(cmd) @command_config[cmd] end |
.command_args(cmd) ⇒ Array
Default arguments are split according to normal shell splitting rules.
Fetch the configured default arguments for a kbsecret command.
93 94 95 |
# File 'lib/kbsecret/config.rb', line 93 def self.command_args(cmd) @command_config.dig(cmd, "args")&.shellsplit || [] end |
.sync! ⇒ void
This method returns an undefined value.
Writes the user's configuration to disk.
66 67 68 |
# File 'lib/kbsecret/config.rb', line 66 def self.sync! File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml } end |
Instance Method Details
#configure_generator(label, hsh) ⇒ void
This method returns an undefined value.
Configure a secret generator.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kbsecret/config.rb', line 138 CONFIG_FACETS.each do |facet, data| define_singleton_method facet do |label| hsh = @config[data[:plural]][label.to_sym] raise data[:except], label unless hsh hsh end define_singleton_method "#{facet}_labels" do @config[data[:plural]].keys end define_singleton_method "#{facet}?" do |label| @config[data[:plural]].keys.include? label.to_sym end define_singleton_method "configure_#{facet}" do |label, **hsh| @config[data[:plural]][label.to_sym] = hsh sync! end define_singleton_method "deconfigure_#{facet}" do |label| @config[data[:plural]].delete(label.to_sym) sync! end end |
#configure_session(label, hsh) ⇒ void
This method returns an undefined value.
Configure a session.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kbsecret/config.rb', line 138 CONFIG_FACETS.each do |facet, data| define_singleton_method facet do |label| hsh = @config[data[:plural]][label.to_sym] raise data[:except], label unless hsh hsh end define_singleton_method "#{facet}_labels" do @config[data[:plural]].keys end define_singleton_method "#{facet}?" do |label| @config[data[:plural]].keys.include? label.to_sym end define_singleton_method "configure_#{facet}" do |label, **hsh| @config[data[:plural]][label.to_sym] = hsh sync! end define_singleton_method "deconfigure_#{facet}" do |label| @config[data[:plural]].delete(label.to_sym) sync! end end |
#deconfigure_generator(label) ⇒ void
This method returns an undefined value.
Deconfigure a generator.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kbsecret/config.rb', line 138 CONFIG_FACETS.each do |facet, data| define_singleton_method facet do |label| hsh = @config[data[:plural]][label.to_sym] raise data[:except], label unless hsh hsh end define_singleton_method "#{facet}_labels" do @config[data[:plural]].keys end define_singleton_method "#{facet}?" do |label| @config[data[:plural]].keys.include? label.to_sym end define_singleton_method "configure_#{facet}" do |label, **hsh| @config[data[:plural]][label.to_sym] = hsh sync! end define_singleton_method "deconfigure_#{facet}" do |label| @config[data[:plural]].delete(label.to_sym) sync! end end |
#deconfigure_session(label) ⇒ void
This only removes the given session from the configuration, making
it "invisible" to kbsecret. To actually remove all files associated
with a session, see Session#unlink!.
This method returns an undefined value.
Deconfigure a session.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kbsecret/config.rb', line 138 CONFIG_FACETS.each do |facet, data| define_singleton_method facet do |label| hsh = @config[data[:plural]][label.to_sym] raise data[:except], label unless hsh hsh end define_singleton_method "#{facet}_labels" do @config[data[:plural]].keys end define_singleton_method "#{facet}?" do |label| @config[data[:plural]].keys.include? label.to_sym end define_singleton_method "configure_#{facet}" do |label, **hsh| @config[data[:plural]][label.to_sym] = hsh sync! end define_singleton_method "deconfigure_#{facet}" do |label| @config[data[:plural]].delete(label.to_sym) sync! end end |
#generator(label) ⇒ Hash
Retrieve a generator's configuration.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kbsecret/config.rb', line 138 CONFIG_FACETS.each do |facet, data| define_singleton_method facet do |label| hsh = @config[data[:plural]][label.to_sym] raise data[:except], label unless hsh hsh end define_singleton_method "#{facet}_labels" do @config[data[:plural]].keys end define_singleton_method "#{facet}?" do |label| @config[data[:plural]].keys.include? label.to_sym end define_singleton_method "configure_#{facet}" do |label, **hsh| @config[data[:plural]][label.to_sym] = hsh sync! end define_singleton_method "deconfigure_#{facet}" do |label| @config[data[:plural]].delete(label.to_sym) sync! end end |
#generator?(label) ⇒ Boolean
Returns whether or not the given generator is configured.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kbsecret/config.rb', line 138 CONFIG_FACETS.each do |facet, data| define_singleton_method facet do |label| hsh = @config[data[:plural]][label.to_sym] raise data[:except], label unless hsh hsh end define_singleton_method "#{facet}_labels" do @config[data[:plural]].keys end define_singleton_method "#{facet}?" do |label| @config[data[:plural]].keys.include? label.to_sym end define_singleton_method "configure_#{facet}" do |label, **hsh| @config[data[:plural]][label.to_sym] = hsh sync! end define_singleton_method "deconfigure_#{facet}" do |label| @config[data[:plural]].delete(label.to_sym) sync! end end |
#generator_labels ⇒ Array<Symbol>
Returns all configured session labels.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kbsecret/config.rb', line 138 CONFIG_FACETS.each do |facet, data| define_singleton_method facet do |label| hsh = @config[data[:plural]][label.to_sym] raise data[:except], label unless hsh hsh end define_singleton_method "#{facet}_labels" do @config[data[:plural]].keys end define_singleton_method "#{facet}?" do |label| @config[data[:plural]].keys.include? label.to_sym end define_singleton_method "configure_#{facet}" do |label, **hsh| @config[data[:plural]][label.to_sym] = hsh sync! end define_singleton_method "deconfigure_#{facet}" do |label| @config[data[:plural]].delete(label.to_sym) sync! end end |
#session(label) ⇒ Hash
Retrieve a session's configuration.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kbsecret/config.rb', line 138 CONFIG_FACETS.each do |facet, data| define_singleton_method facet do |label| hsh = @config[data[:plural]][label.to_sym] raise data[:except], label unless hsh hsh end define_singleton_method "#{facet}_labels" do @config[data[:plural]].keys end define_singleton_method "#{facet}?" do |label| @config[data[:plural]].keys.include? label.to_sym end define_singleton_method "configure_#{facet}" do |label, **hsh| @config[data[:plural]][label.to_sym] = hsh sync! end define_singleton_method "deconfigure_#{facet}" do |label| @config[data[:plural]].delete(label.to_sym) sync! end end |
#session?(label) ⇒ Boolean
Returns whether or not the given session is configured.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kbsecret/config.rb', line 138 CONFIG_FACETS.each do |facet, data| define_singleton_method facet do |label| hsh = @config[data[:plural]][label.to_sym] raise data[:except], label unless hsh hsh end define_singleton_method "#{facet}_labels" do @config[data[:plural]].keys end define_singleton_method "#{facet}?" do |label| @config[data[:plural]].keys.include? label.to_sym end define_singleton_method "configure_#{facet}" do |label, **hsh| @config[data[:plural]][label.to_sym] = hsh sync! end define_singleton_method "deconfigure_#{facet}" do |label| @config[data[:plural]].delete(label.to_sym) sync! end end |
#session_labels ⇒ Array<Symbol>
Returns all configured session labels.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/kbsecret/config.rb', line 138 CONFIG_FACETS.each do |facet, data| define_singleton_method facet do |label| hsh = @config[data[:plural]][label.to_sym] raise data[:except], label unless hsh hsh end define_singleton_method "#{facet}_labels" do @config[data[:plural]].keys end define_singleton_method "#{facet}?" do |label| @config[data[:plural]].keys.include? label.to_sym end define_singleton_method "configure_#{facet}" do |label, **hsh| @config[data[:plural]][label.to_sym] = hsh sync! end define_singleton_method "deconfigure_#{facet}" do |label| @config[data[:plural]].delete(label.to_sym) sync! end end |