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
- .save_file(yamlFileName, branch = []) ⇒ Object
Class Method Details
.add_config_file_name(configFileName) ⇒ Object
313 314 315 316 317 |
# File 'lib/rake/config.rb', line 313 def self.add_config_file_name(configFileName) configFileName.sub!(/\.[^\.]*$/,''); Rake::Application.mesg "Adding config name: [#{configFileName}]"; @@configFileNames.push(configFileName); end |
.add_cookbook(aCookbookPath) ⇒ Object
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/rake/config.rb', line 386 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
365 366 367 368 |
# File 'lib/rake/config.rb', line 365 def self.add_global_cookbook_directory(globalCookbookDirectory) Rake::Application.mesg "Adding global cookbook: [#{globalCookbookDirectory}]"; @@globalCookbookDirectories.push(globalCookbookDirectory) end |
.add_global_cookbooks ⇒ Object
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/rake/config.rb', line 370 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
341 342 343 |
# File 'lib/rake/config.rb', line 341 def self.add_recipes_path(aRecipesPath) @@recipePaths.push(aRecipesPath); end |
.data ⇒ Object
234 235 236 237 238 |
# File 'lib/rake/config.rb', line 234 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
357 358 359 360 361 362 363 |
# File 'lib/rake/config.rb', line 357 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
240 241 242 243 244 |
# File 'lib/rake/config.rb', line 240 def self.encryptedData Thread.current[:confStack] = ConfStack.new(self, :Conf); Thread.current[:confStack].calling(@@encryptedData, :encryptedData, :encryptedData); return @@encryptedData; end |
.find_resource(aPartialResourcePath) ⇒ Object
349 350 351 352 353 354 355 |
# File 'lib/rake/config.rb', line 349 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
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/rake/config.rb', line 217 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
345 346 347 |
# File 'lib/rake/config.rb', line 345 def self.get_recipe_paths() @@recipePaths; end |
.has_encrypted_key?(aKey) ⇒ Boolean
250 251 252 |
# File 'lib/rake/config.rb', line 250 def self.has_encrypted_key?(aKey) return @@encryptedData.has_key?(aKey); end |
.has_key?(aKey) ⇒ Boolean
246 247 248 |
# File 'lib/rake/config.rb', line 246 def self.has_key?(aKey) return @@data.has_key?(aKey); end |
.load(yaml) ⇒ Object
254 255 256 257 258 259 |
# File 'lib/rake/config.rb', line 254 def self.load(yaml) loadedHash = YAML::load(yaml); if loadedHash then @@data.merge(loadedHash); end end |
.load_central_config_files ⇒ Object
455 456 457 458 459 |
# File 'lib/rake/config.rb', line 455 def self.load_central_config_files() @@recipePaths.reverse.each do | aRecipePath | load_config_files(aRecipePath.sub(/\/$/,'')); end end |
.load_config_files(recipeDir) ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/rake/config.rb', line 319 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
269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/rake/config.rb', line 269 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
261 262 263 264 265 266 267 |
# File 'lib/rake/config.rb', line 261 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
331 332 333 334 335 336 337 338 339 |
# File 'lib/rake/config.rb', line 331 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
447 448 449 450 451 452 453 |
# File 'lib/rake/config.rb', line 447 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
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/rake/config.rb', line 411 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
406 407 408 409 |
# File 'lib/rake/config.rb', line 406 def self.log_file_name() return @@configFileNames.join('-') unless @@configFileNames.empty?; return "noConfig"; end |
.method_missing(meth, *args) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/rake/config.rb', line 299 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 |
.save_file(yamlFileName, branch = []) ⇒ Object
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/rake/config.rb', line 283 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 |