class Conf

Public Class Methods

add_config_file_name(configFileName) click to toggle source
# File lib/rake/config.rb, line 333
def self.add_config_file_name(configFileName)
  configFileName.sub!(/\.[^\.]*$/,'');
  Rake::Application.mesg "Adding config name: [#{configFileName}]";
  @@configFileNames.push(configFileName);
end
add_cookbook(aCookbookPath) click to toggle source
# File lib/rake/config.rb, line 413
  def self.add_cookbook(aCookbookPath)
    Rake::Application.mesg "Loading cookbook: [#{aCookbookPath}]";
    $LOAD_PATH.unshift(aCookbookPath+'/lib');
    Conf.add_recipes_path(aCookbookPath+'/');
    Conf.add_recipes_path(aCookbookPath+'/recipes/');
#    Dir.chdir(aCookbookPath) do
      #
      # load the cookbook configuration file first incase they are used
      # in the rakefile
      confFile = aCookbookPath + '/' + 'cookbook.conf';
      Conf.load_file(confFile) if File.exists?(confFile);
      encConfFile = aCookbookPath + '/' + 'cookbook.enc';
      Conf.load_encrypted_file(encConfFile) if File.exists?(encConfFile);

      # now load the corresponding cookbook rake file
      rakeFile = aCookbookPath + '/' + 'cookbook.rake';
      Rake.load_rakefile(rakeFile) if File.exists?(rakeFile);
#    end
  end
add_global_cookbook_directory(globalCookbookDirectory) click to toggle source
# File lib/rake/config.rb, line 392
def self.add_global_cookbook_directory(globalCookbookDirectory)
  Rake::Application.mesg "Adding global cookbook: [#{globalCookbookDirectory}]";
  @@globalCookbookDirectories.push(globalCookbookDirectory)
end
add_global_cookbooks() click to toggle source
# File lib/rake/config.rb, line 397
def self.add_global_cookbooks()
  if @@globalCookbookDirectories.empty?() then
    if ENV.has_key?('HOME') then
      if not ENV['HOME'].empty?() then
        @@globalCookbookDirectories.push(ENV['HOME']+'/.cookbook');
      end
    end
  end
  @@globalCookbookDirectories.each() do | aGlobalCookbookDir |
    if Dir.exists?(aGlobalCookbookDir) then
      Rake::Application.mesg "Adding global cookbook #{aGlobalCookbookDir}";
      Conf.add_cookbook(aGlobalCookbookDir);
    end
  end
end
add_recipes_path(aRecipesPath) click to toggle source
# File lib/rake/config.rb, line 361
def self.add_recipes_path(aRecipesPath)
  #
  # Make sure the recipeDir is in the load path
  #
  $LOAD_PATH.unshift(aRecipesPath);
  #
  # Add this path to the collection of recipe paths to search
  #
  @@recipePaths.push(aRecipesPath);
end
data() click to toggle source
# File lib/rake/config.rb, line 253
def self.data
  Thread.current[:confStack] = ConfStack.new(self, :Conf);
  Thread.current[:confStack].calling(@@data, :data, :data);
  return @@data;
end
each_resource(aPartialResourcePath, &aBlock) click to toggle source
# File lib/rake/config.rb, line 384
def self.each_resource(aPartialResourcePath, &aBlock)
  @@recipePaths.each do | aRecipePath |
    aResourcePath = aRecipePath+aPartialResourcePath;
    next unless File.exists?(aResourcePath);
    aBlock.call(aResourcePath);
  end
end
encryptedData() click to toggle source
# File lib/rake/config.rb, line 259
def self.encryptedData
  Thread.current[:confStack] = ConfStack.new(self, :Conf);
  Thread.current[:confStack].calling(@@encryptedData, :encryptedData, :encryptedData);
  return @@encryptedData;
end
find_resource(aPartialResourcePath) click to toggle source
# File lib/rake/config.rb, line 376
def self.find_resource(aPartialResourcePath)
  @@recipePaths.each do | aRecipePath |
    aResourcePath = aRecipePath+aPartialResourcePath;
    return aResourcePath if File.exists?(aResourcePath);
  end
  raise ResourceNotFoundError, "Resource file #{aPartialResourcePath} could not be found";
end
get_pass_phrase(check = false) click to toggle source
# File lib/rake/config.rb, line 236
def self.get_pass_phrase(check = false)
  if @@passPhrase.nil? then
    require 'highline';
    @@passPhrase = HighLine.new.ask("Pass phrase for encrypted configuration:") { | q | q.echo='*'; }
    while check do
      secondPassPhrase = HighLine.new.ask("Pass phrase (again):") { | q | q.echo='*'; }
      if @@passPhrase != secondPassPhrase then
        puts "The pass phrases do not match... please try again\n\n";
        @@passPhrase = HighLine.new.ask("Pass phrase for encrypted configuration:") { | q | q.echo='*'; }
      else
        check = false;
      end
    end
  end
  @@passPhrase;
end
get_recipe_paths() click to toggle source
# File lib/rake/config.rb, line 372
def self.get_recipe_paths()
  @@recipePaths;
end
has_encrypted_key?(aKey) click to toggle source
# File lib/rake/config.rb, line 269
def self.has_encrypted_key?(aKey)
  return @@encryptedData.has_key?(aKey);
end
has_key?(aKey) click to toggle source
# File lib/rake/config.rb, line 265
def self.has_key?(aKey)
  return @@data.has_key?(aKey);
end
load(yaml) click to toggle source
# File lib/rake/config.rb, line 273
def self.load(yaml)
  loadedHash = YAML::load(yaml);
  if loadedHash then
    @@data.merge(loadedHash);
  end
end
load_central_config_files() click to toggle source
# File lib/rake/config.rb, line 482
def self.load_central_config_files()
  @@recipePaths.reverse.each do | aRecipePath |
    load_config_files(aRecipePath.sub(/\/$/,''));
  end
end
load_config_files(recipeDir) click to toggle source
# File lib/rake/config.rb, line 339
def self.load_config_files(recipeDir)
  @@configFileNames.each() do  | aConfigFileName |
    #
    # load the yaml configuration file
    #
    confFile = recipeDir + '/' + aConfigFileName + '.conf';
    self.load_file(confFile) if File.exists?(confFile);
    encConfFile = recipeDir + '/' + aConfigFileName + '.enc';
    self.load_encrypted_file(encConfFile) if File.exists?(encConfFile);
  end
end
load_encrypted_file(yamlFileName) click to toggle source
# File lib/rake/config.rb, line 288
def self.load_encrypted_file(yamlFileName)
  Rake::Application.mesg "loading encrypted configuration file [#{yamlFileName}]\n  in #{Dir.getwd}" if Rake.application.options.trace;
  yamlPlainText = "";
  begin 
    yamlPlainText = gpgDecryptFile2Data(yamlFileName);
  rescue
    yamlPlainText = openSslDecryptFile2Data(yamlFileName);
  end
  loadedHash = YAML::load(yamlPlainText);
  if loadedHash then
    @@encryptedData.merge(loadedHash);
  end
end
load_file(yamlFileName) click to toggle source
# File lib/rake/config.rb, line 280
def self.load_file(yamlFileName)
  Rake::Application.mesg "loading configuration file [#{yamlFileName}]\n  in #{Dir.getwd}" if Rake.application.options.trace;
  loadedHash = YAML::load_file(yamlFileName);
  if loadedHash then
    @@data.merge(loadedHash);
  end
end
load_rake_files(recipeDir) click to toggle source
# File lib/rake/config.rb, line 351
def self.load_rake_files(recipeDir)
  @@configFileNames.each() do | aConfigFileName |
    #
    # load the corresponding rake file
    #
    rakeFile = recipeDir + '/' + aConfigFileName + '.rake';
    Rake.load_rakefile(rakeFile) if File.exists?(rakeFile);
  end
end
load_recipe(recipeName) click to toggle source
# File lib/rake/config.rb, line 474
def self.load_recipe(recipeName)
  @@recipePaths.reverse.each do | aRecipePath |
    recipeDir = aRecipePath+recipeName;
    next unless File.directory?(recipeDir);
    load_recipe_dir(recipeDir);
  end
end
load_recipe_dir(recipeDir) click to toggle source
# File lib/rake/config.rb, line 438
def self.load_recipe_dir(recipeDir)
  #
  # extract the last directory name in the path to use as the
  # recipeName
  #
  recipeName = recipeDir.split(/\//).pop();
  #
  # search for sub-directories and recursively calling
  # load_recipe_dir to load any *.conf/*.enc or *.rake fragments
  # found.
  #
  Dir.glob(recipeDir+'/*').each do | aFileName |
    next unless aFileName.dup.force_encoding("UTF-8").valid_encoding?
    next if aFileName =~ /\.$/;
    next unless File.directory?(aFileName);
    load_recipe_dir(aFileName);
  end
  #
  # load the configurtion files first in case they are used in the
  # rakefile
  # ... generic first ...
  confFile = recipeDir + '/' + recipeName + '.conf';
  Conf.load_file(confFile) if File.exists?(confFile);
  encConfFile = recipeDir + '/' + recipeName + '.enc';
  Conf.load_encrypted_file(encConfFile) if File.exists?(encConfFile);
  # ... then more specific ...
  Conf.load_config_files(recipeDir);

  # now load the corresponding rake files
  # ... generic first...
  rakeFile = recipeDir + '/' + recipeName + '.rake';
  Rake.load_rakefile(rakeFile) if File.exists?(rakeFile);
  # ... then more specific ...
  Conf.load_rake_files(recipeDir);
end
log_file_name() click to toggle source
# File lib/rake/config.rb, line 433
def self.log_file_name()
  return @@configFileNames.join('-') unless @@configFileNames.empty?;
  return "noConfig";
end
method_missing(meth, *args) click to toggle source
# File lib/rake/config.rb, line 318
def self.method_missing(meth, *args)
  Thread.current[:confStack] = ConfStack.new(self, :Conf, args);
  Thread.current[:confStack].calling(self, meth, :method_missing, args);
  meth_s = meth.to_s
  if @@data.respond_to?(meth) ||
    @@data.data.has_key?(meth) ||
    @@data.schema.has_key?(meth) ||
    meth_s[-1..-1] == '='then
    @@data.method_missing(meth, *args);
  else 
    Thread.current[:confStack].reportNoMethodError(
      NoMethodError.new("no such key #{meth} in construct"))
  end
end
prettyPrint() click to toggle source
# File lib/rake/config.rb, line 488
def self.prettyPrint
  result = StringIO.new;
  @@data.prettyPrint(result, "Conf");
  result.string;
end
save_file(yamlFileName, branch = []) click to toggle source
# File lib/rake/config.rb, line 302
def self.save_file(yamlFileName, branch = [])
  branchData = @@data;
  branch.each do | aKey |
    branchData = branchData[aKey] if branchData.has_key?(aKey);
  end
  branchData = branchData.to_stringHash if branchData.is_a?(Construct);
  branch.reverse.each do | aKey |
    tmpHash = Hash.new();
    tmpHash[aKey.to_s] = branchData;
    branchData = tmpHash;
  end
  yamlFile = File.open(yamlFileName, "w");
  YAML::dump(branchData, yamlFile);
  yamlFile.close();
end