Module: Keybase::Local::Config

Included in:
Keybase::Local
Defined in:
lib/keybase/local/config.rb

Overview

Methods and constants related to a local Keybase installation.

Constant Summary collapse

CONFIG_DIR =

The Keybase configuration directory.

if Gem.win_platform?
  File.expand_path("#{ENV["LOCALAPPDATA"]}/Keybase").freeze
elsif RUBY_PLATFORM =~ /darwin/
  File.expand_path("~/Library/Application Support/Keybase").freeze
else
  File.expand_path("~/.config/keybase").freeze
end
CONFIG_FILE =

The Keybase configuration file.

File.join(CONFIG_DIR, "config.json").freeze
CONFIG_HASH =

The hash from Keybase's configuration file.

JSON.parse(File.read(CONFIG_FILE)).freeze
KBFS_MOUNT =

The mountpoint for KBFS.

"/keybase"

Instance Method Summary collapse

Instance Method Details

#current_userString

Returns the currently logged-in user.

Returns:

  • (String)

    the currently logged-in user



31
32
33
# File 'lib/keybase/local/config.rb', line 31

def current_user
  CONFIG_HASH["current_user"]
end

#local_usersArray<Keybase::Local::User>

Returns a list of all local users known to Keybase.

Returns:



37
38
39
# File 'lib/keybase/local/config.rb', line 37

def local_users
  CONFIG_HASH["users"].map { |_, v| User.new(v) }
end

#private_dirString

Returns the user's private KBFS directory.

Returns:

  • (String)

    the user's private KBFS directory



42
43
44
# File 'lib/keybase/local/config.rb', line 42

def private_dir
  File.join(KBFS_MOUNT, "private", current_user)
end

#public_dirString

Returns the user's public KBFS directory.

Returns:

  • (String)

    the user's public KBFS directory



47
48
49
# File 'lib/keybase/local/config.rb', line 47

def public_dir
  File.join(KBFS_MOUNT, "public", current_user)
end

#running?Boolean

Returns whether or not Keybase is currently running.

Returns:

  • (Boolean)

    whether or not Keybase is currently running



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/keybase/local/config.rb', line 52

def running?
  if Gem.win_platform?
    !`tasklist | find "keybase.exe"`.empty?
  elsif RUBY_PLATFORM =~ /darwin/
    !`pgrep keybase`.empty?
  else
    # is there a more efficient way to do this that doesn't involve an exec?
    Dir["/proc/[0-9]*/comm"].any? do |comm|
      File.read(comm).chomp == "keybase" rescue false # hooray for TOCTOU
    end
  end
end

#running_versionString

Returns the running Keybase's version string.

Returns:

  • (String)

    the running Keybase's version string

Raises:



67
68
69
70
# File 'lib/keybase/local/config.rb', line 67

def running_version
  raise Exceptions::KeybaseNotRunningError unless running?
  `keybase --version`.split[2]
end