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.join(Keybase::Local.private_dir, "kbsecret/.config").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::Local.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
{ mount: Keybase::Local::Config::KBFS_MOUNT, 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
kbsecret
command. -
.command_args(cmd) ⇒ Array
Fetch the configured default arguments for a
kbsecret
command. -
.load! ⇒ void
private
Reads the user's configuration files from disk, introducing default values as necessary.
-
.sync! ⇒ void
Writes the user's configuration to disk.
-
.unalias_command(acmd) ⇒ String
Attempt to resolve an alias into a
kbsecret
command.
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.
95 96 97 |
# File 'lib/kbsecret/config.rb', line 95 def self.[](key) @config[key] end |
.command(cmd) ⇒ Hash?
Fetch the configuration for a kbsecret
command.
105 106 107 |
# File 'lib/kbsecret/config.rb', line 105 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.
115 116 117 |
# File 'lib/kbsecret/config.rb', line 115 def self.command_args(cmd) @command_config.dig(cmd, "args")&.shellsplit || [] end |
.load! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Reads the user's configuration files from disk, introducing default values as necessary.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/kbsecret/config.rb', line 68 def self.load! user_config = if File.exist?(CONFIG_FILE) YAML.load_file(CONFIG_FILE) else DEFAULT_CONFIG end @command_config = if File.exist?(COMMAND_CONFIG_FILE) INIH.load(COMMAND_CONFIG_FILE) else {} end @config = DEFAULT_CONFIG.merge(user_config) @config[:sessions].merge!(DEFAULT_SESSION) @config[:generators].merge!(DEFAULT_GENERATOR) end |
.sync! ⇒ void
This method returns an undefined value.
Writes the user's configuration to disk.
88 89 90 |
# File 'lib/kbsecret/config.rb', line 88 def self.sync! File.write(CONFIG_FILE, @config.to_yaml) end |
.unalias_command(acmd) ⇒ String
Attempt to resolve an alias into a kbsecret
command.
125 126 127 128 129 130 131 132 |
# File 'lib/kbsecret/config.rb', line 125 def self.unalias_command(acmd) @command_config.each do |cmd, conf| aliases = conf["aliases"]&.split || [] return cmd if aliases.include?(acmd) end acmd end |
Instance Method Details
#configure_generator(label, hsh) ⇒ void
This method returns an undefined value.
Configure a secret generator.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/kbsecret/config.rb', line 175 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/kbsecret/config.rb', line 175 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/kbsecret/config.rb', line 175 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/kbsecret/config.rb', line 175 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/kbsecret/config.rb', line 175 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/kbsecret/config.rb', line 175 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/kbsecret/config.rb', line 175 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/kbsecret/config.rb', line 175 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/kbsecret/config.rb', line 175 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/kbsecret/config.rb', line 175 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 |