module Towel::Environment

Helpers to collect the environment-specific details for invocations.

Constants

REDACTED

Value that is substituted for environment variables that have been redacted.

REDACT_ENV

Environment variable that, if set, defines what other environment variables should be redacted.

REVISION_ENV

Environment variable that, if set, defines the source control management revision that is reported to Towel. See `Invocation.revision` in towel.proto for more details.

Public Class Methods

argv() click to toggle source

The arguments used to launch this process.

# File lib/towel/environment.rb, line 43
def self.argv
  [$0].concat(ARGV)
end
env_vars() click to toggle source

The environment variables set for this process.

# File lib/towel/environment.rb, line 48
def self.env_vars
  redacted = ENV.fetch(REDACT_ENV, "").split(",").map(&:strip)
  ENV.to_h do |name, value|
    if redacted.include?(name)
      [name, REDACTED]
    else
      [name, value]
    end
  end
end
hostname() click to toggle source

The hostname of this machine.

# File lib/towel/environment.rb, line 28
def self.hostname
  Socket.gethostname
end
platform() click to toggle source

The current platform that Towel is running on.

# File lib/towel/environment.rb, line 18
def self.platform
  platform = Towel::V1alpha::Platform.new
  uname = Etc.uname
  platform.os = uname[:sysname]
  platform.os_version = uname[:release]
  platform.arch = uname[:machine]
  return platform
end
revision() click to toggle source

The version control system (VCS) revision for the code that is running.

# File lib/towel/environment.rb, line 60
def self.revision
  ENV.fetch(REVISION_ENV, "")
end
user() click to toggle source

The OS user that this process is running as.

# File lib/towel/environment.rb, line 33
def self.user
  Etc.getlogin
end
working_dir() click to toggle source

The current working directory.

# File lib/towel/environment.rb, line 38
def self.working_dir
  Dir.getwd
end