Class: KBSecret::Config

Inherits:
Object
  • Object
show all
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.expand_path("~/.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
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",
  sessions: {
    default: {
      users: [Keybase.current_user],
      root: "default",
    },
  },

  session_root: File.join("/keybase/private/",
                          Keybase.current_user,
                          "kbsecret"),
}.freeze

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object

Retrieve a configured value.

Parameters:

  • key (String)

    the configuration key to retrieve

Returns:

  • (Object)

    the corresponding configuration



36
37
38
# File 'lib/kbsecret/config.rb', line 36

def self.[](key)
  @config[key]
end

.configure_session(label, hsh) ⇒ void

This method returns an undefined value.

Configure a session.

Parameters:

  • label (String, Symbol)

    the session label

  • hsh (Hash)

    the session configuration



62
63
64
65
# File 'lib/kbsecret/config.rb', line 62

def self.configure_session(label, hsh)
  @config[:sessions][label.to_sym] = hsh
  File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml }
end

.deconfigure_session(label) ⇒ void

Note:

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.

Parameters:

  • label (String, Symbol)

    the session label



73
74
75
76
# File 'lib/kbsecret/config.rb', line 73

def self.deconfigure_session(label)
  @config[:sessions].delete(label.to_sym)
  File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml }
end

.session(sess) ⇒ Hash

Retrieve a session's configuration.

Parameters:

  • sess (String, Symbol)

    the session's label

Returns:

  • (Hash)

    the session configuration



43
44
45
# File 'lib/kbsecret/config.rb', line 43

def self.session(sess)
  @config[:sessions][sess.to_sym]
end

.session?(sess) ⇒ Boolean

Returns whether or not the given session is configured.

Parameters:

  • sess (String, Symbol)

    the session label

Returns:

  • (Boolean)

    whether or not the given session is configured



54
55
56
# File 'lib/kbsecret/config.rb', line 54

def self.session?(sess)
  session_labels.include?(sess.to_sym)
end

.session_labelsArray<Symbol>

Returns all configured session labels.

Returns:

  • (Array<Symbol>)

    all configured session labels



48
49
50
# File 'lib/kbsecret/config.rb', line 48

def self.session_labels
  @config[:sessions].keys
end