class LicenseAcceptance::Config

Attributes

license_locations[RW]
logger[RW]
output[RW]
persist[RW]
persist_location[RW]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/license_acceptance/config.rb, line 7
def initialize(opts = {})
  @output = opts.fetch(:output, $stdout)
  @logger = opts.fetch(:logger, ::Logger.new(IO::NULL))
  @license_locations = opts.fetch(:license_locations, default_license_locations)
  @license_locations = [ @license_locations ].flatten
  @persist_location = opts.fetch(:persist_location, default_persist_location)
  @persist = opts.fetch(:persist, true)
end

Private Instance Methods

default_license_locations() click to toggle source
# File lib/license_acceptance/config.rb, line 22
def default_license_locations
  if windows?
    root = ENV.fetch("SYSTEMDRIVE", "C:")
    l = [ File.join(root, "chef/accepted_licenses/") ]
    unless is_root?
      # Look through a list of possible user locations and pick the first one that exists
      # copied from path_helper.rb in chef-config gem
      possible_dirs = []
      possible_dirs << ENV["HOME"] if ENV["HOME"]
      possible_dirs << ENV["HOMEDRIVE"] + ENV["HOMEPATH"] if ENV["HOMEDRIVE"] && ENV["HOMEPATH"]
      possible_dirs << ENV["HOMESHARE"] + ENV["HOMEPATH"] if ENV["HOMESHARE"] && ENV["HOMEPATH"]
      possible_dirs << ENV["USERPROFILE"] if ENV["USERPROFILE"]
      raise NoValidEnvironmentVar if possible_dirs.empty?

      possible_dirs.each do |possible_dir|
        if Dir.exist?(possible_dir)
          full_possible_dir = File.join(possible_dir, ".chef/accepted_licenses/")
          l << full_possible_dir
          break
        end
      end
    end
  else
    l = [ "/etc/chef/accepted_licenses/" ]
    l << File.join(ENV["HOME"], ".chef/accepted_licenses/") unless is_root?
  end
  l
end
default_persist_location() click to toggle source
# File lib/license_acceptance/config.rb, line 51
def default_persist_location
  license_locations[-1]
end
is_root?() click to toggle source
# File lib/license_acceptance/config.rb, line 18
def is_root?
  Process.uid == 0
end
windows?() click to toggle source
# File lib/license_acceptance/config.rb, line 55
def windows?
  !!(RUBY_PLATFORM =~ /(cygwin|mswin|mingw|bccwin|wince|emx)/i)
end