Class: Conf
- Inherits:
-
Object
- Object
- Conf
- Defined in:
- lib/rake/config.rb
Constant Summary collapse
- @@data =
Construct.new()
- @@encryptedData =
Construct.new()
- @@passPhrase =
nil- @@configFileNames =
Array.new()
- @@recipePaths =
Array.new()
- @@globalCookbookDirectories =
Array.new()
Class Method Summary collapse
- .add_config_file_name(configFileName) ⇒ Object
- .add_cookbook(aCookbookPath) ⇒ Object
- .add_global_cookbook_directory(globalCookbookDirectory) ⇒ Object
- .add_global_cookbooks ⇒ Object
- .add_recipes_path(aRecipesPath) ⇒ Object
- .data ⇒ Object
- .each_resource(aPartialResourcePath, &aBlock) ⇒ Object
- .encryptedData ⇒ Object
- .find_resource(aPartialResourcePath) ⇒ Object
- .get_pass_phrase(check = false) ⇒ Object
- .get_recipe_paths ⇒ Object
- .has_encrypted_key?(aKey) ⇒ Boolean
- .has_key?(aKey) ⇒ Boolean
- .load(yaml) ⇒ Object
- .load_central_config_files ⇒ Object
- .load_config_files(recipeDir) ⇒ Object
- .load_encrypted_file(yamlFileName) ⇒ Object
- .load_file(yamlFileName) ⇒ Object
- .load_rake_files(recipeDir) ⇒ Object
- .load_recipe(recipeName) ⇒ Object
- .load_recipe_dir(recipeDir) ⇒ Object
- .log_file_name ⇒ Object
- .method_missing(meth, *args) ⇒ Object
- .prettyPrint ⇒ Object
- .save_file(yamlFileName, branch = []) ⇒ Object
Class Method Details
.add_config_file_name(configFileName) ⇒ Object
332 333 334 335 336 |
# File 'lib/rake/config.rb', line 332 def self.add_config_file_name(configFileName) configFileName.sub!(/\.[^\.]*$/,''); Rake::Application.mesg "Adding config name: [#{configFileName}]"; @@configFileNames.push(configFileName); end |
.add_cookbook(aCookbookPath) ⇒ Object
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/rake/config.rb', line 412 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) ⇒ Object
391 392 393 394 |
# File 'lib/rake/config.rb', line 391 def self.add_global_cookbook_directory(globalCookbookDirectory) Rake::Application.mesg "Adding global cookbook: [#{globalCookbookDirectory}]"; @@globalCookbookDirectories.push(globalCookbookDirectory) end |
.add_global_cookbooks ⇒ Object
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/rake/config.rb', line 396 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) ⇒ Object
360 361 362 363 364 365 366 367 368 369 |
# File 'lib/rake/config.rb', line 360 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 ⇒ Object
253 254 255 256 257 |
# 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) ⇒ Object
383 384 385 386 387 388 389 |
# File 'lib/rake/config.rb', line 383 def self.each_resource(aPartialResourcePath, &aBlock) @@recipePaths.each do | aRecipePath | aResourcePath = aRecipePath+aPartialResourcePath; next unless File.exists?(aResourcePath); aBlock.call(aResourcePath); end end |
.encryptedData ⇒ Object
259 260 261 262 263 |
# 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) ⇒ Object
375 376 377 378 379 380 381 |
# File 'lib/rake/config.rb', line 375 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) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# 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 ⇒ Object
371 372 373 |
# File 'lib/rake/config.rb', line 371 def self.get_recipe_paths() @@recipePaths; end |
.has_encrypted_key?(aKey) ⇒ Boolean
269 270 271 |
# File 'lib/rake/config.rb', line 269 def self.has_encrypted_key?(aKey) return @@encryptedData.has_key?(aKey); end |
.has_key?(aKey) ⇒ Boolean
265 266 267 |
# File 'lib/rake/config.rb', line 265 def self.has_key?(aKey) return @@data.has_key?(aKey); end |
.load(yaml) ⇒ Object
273 274 275 276 277 278 |
# 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 ⇒ Object
481 482 483 484 485 |
# File 'lib/rake/config.rb', line 481 def self.load_central_config_files() @@recipePaths.reverse.each do | aRecipePath | load_config_files(aRecipePath.sub(/\/$/,'')); end end |
.load_config_files(recipeDir) ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/rake/config.rb', line 338 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) ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 299 300 |
# 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..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) ⇒ Object
280 281 282 283 284 285 286 |
# 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..trace; loadedHash = YAML::load_file(yamlFileName); if loadedHash then @@data.merge(loadedHash); end end |
.load_rake_files(recipeDir) ⇒ Object
350 351 352 353 354 355 356 357 358 |
# File 'lib/rake/config.rb', line 350 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) ⇒ Object
473 474 475 476 477 478 479 |
# File 'lib/rake/config.rb', line 473 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) ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/rake/config.rb', line 437 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 ⇒ Object
432 433 434 435 |
# File 'lib/rake/config.rb', line 432 def self.log_file_name() return @@configFileNames.join('-') unless @@configFileNames.empty?; return "noConfig"; end |
.method_missing(meth, *args) ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/rake/config.rb', line 318 def self.method_missing(meth, *args) Thread.current[:confStack] = ConfStack.new(self, :Conf, 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 self.reportNoMethodError(); #raise ConfigurationError, "No configuation value specified for Conf[#{meth.to_s}]"; end end |
.prettyPrint ⇒ Object
487 488 489 490 491 |
# File 'lib/rake/config.rb', line 487 def self.prettyPrint result = StringIO.new; @@data.prettyPrint(result, "Conf"); result.string; end |
.save_file(yamlFileName, branch = []) ⇒ Object
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# 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 |