Module: Foreman::Util

Included in:
PuppetSetting
Defined in:
lib/foreman/util.rb

Instance Method Summary collapse

Instance Method Details

#secure_tokenObject

Generates a URL-safe token for use with Rails for signing cookies


21
22
23
# File 'lib/foreman/util.rb', line 21

def secure_token
  SecureRandom.base64(96).tr('+/=', '-_*')
end

#which(bin, *path) ⇒ Object

searches for binaries in predefined directories and user PATH accepts a binary name and an array of paths to search first if path is omitted will search only in user PATH


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/foreman/util.rb', line 8

def which(bin, *path)
  path += ENV['PATH'].split(File::PATH_SEPARATOR)
  path.flatten.uniq.each do |dir|
    dest = File.join(dir, bin)
    return dest if FileTest.file? dest and FileTest.executable? dest
  end
  return false
rescue StandardError => e
  logger.warn e
  return false
end