Class: Tsclient::ApiFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/tsclient/api_finder.rb

Constant Summary collapse

DEFAULT_SOCKET_PATH =
"/var/run/tailscale/tailscaled.sock"

Instance Method Summary collapse

Instance Method Details

#call(env: ENV, ruby_platform: RUBY_PLATFORM) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tsclient/api_finder.rb', line 9

def call(env: ENV, ruby_platform: RUBY_PLATFORM)
  os = find_os(ruby_platform)
  if env.key?("TSCLIENT_API_URI")
    URI(env.fetch("TSCLIENT_API_URI"))
  elsif os == "linux"
    # Running on Linux, use default socket path
    URI("unix://#{DEFAULT_SOCKET_PATH}") if File.exist?(DEFAULT_SOCKET_PATH)
  elsif os == "macos"
    # Running on macOS, api port & auth are in a specific filename
    if (tsfile = Pathname.glob("#{env["HOME"]}/Library/Group Containers/*.io.tailscale.ipn.macos/sameuserproof-*-*").first)
      _, port, password = tsfile.basename.to_s.split("-", 3)
      URI("http://:#{password}@localhost:#{port}")
    end
  elsif os == "windows"
    raise NotImplementedError, "Windows not currently implemented"
  end
end