Class: Fhcap::Tasks::Chef::Cookbook::UpdateConfig

Inherits:
Fhcap::Tasks::Chef::ChefTaskBase show all
Defined in:
lib/fhcap/tasks/chef/cookbook/update_config.rb

Constant Summary collapse

COMP_CFG_MAP =
{
    "fh-aaa" => "fh-aaa/config/dev.json",
    "millicore" => "millicore/src/main/resources/config/cluster-config.properties",
    "fh-reaper" => "millicore/src/main/resources/config/reaper.properties",
    "fh-supercore" => "fh-supercore/config/dev.json",
    "fh-messaging" => "fh-messaging/fh-messaging/config/dev.json",
    "fh-metrics" => "fh-messaging/fh-metrics/config/dev.json",
    "fh-ditch" => "fh-ditch/config/dev.json",
    "fh-scm" => "fh-scm/config/dev.json",
    "fh-stats" => "fh-stats/fh-statsd/config/dev.json",
    "fh-dynoman" => "fh-dynoman/config/dev.json",
    "fh-proxy" => "fh-proxy/config/dev.json",
    "fh-ngui" => "fh-ngui/config/dev.json",
    "fh-appstore" => "fh-appstore/config/dev.json",
    "fh-digger" => "fh-digger/config/dev.json",
    "fh-mbaas" => "fh-mbaas/config/dev.json",
}

Instance Attribute Summary collapse

Attributes inherited from TaskBase

#config, #options, #thor, #verbose

Instance Method Summary collapse

Methods inherited from Fhcap::Tasks::Chef::ChefTaskBase

#knife_config_dir, #knife_config_file_for, #run_chef_client_cmd, #run_knife_cmd, #run_knife_ssh_cmd

Methods inherited from TaskBase

#ask_config, #color_pad, #exit_with_error, #set_color, #suppress_stdout, #table_header, #table_row, #with_progress

Methods included from KnifeHelper

#chef_server_config_for, #chef_server_config_hash_for, #chef_server_names, #delete_chef_object, #knife_config, #knife_config_dir, #knife_config_file_for, #knife_data_bag_delete, #knife_download, #knife_environment_delete, #knife_upload, #local_chef_server?, #with_chef_server, #with_local_chef_server

Methods included from ProvidersHelper

#provider_availability_zones, #provider_config, #provider_credentials, #provider_for, #provider_names, #provider_names_for, #provider_regions, #provider_type, #providers_config

Methods included from ReposHelper

#find_cluster, #find_cluster_pwds, #find_cluster_pwds_with_repo, #find_cluster_with_repo, #find_data_bag, #find_data_bag_item, #find_environment, #find_repo_item, #find_role, #get_cookbook_deps, #get_cookbook_meta, #get_cookbook_versions, #get_cookbooks, #get_dirty_cookbooks, #get_entry_dependencies, #get_modified_cookbooks, #git_diff, #is_dirty?, #modified?, #repo_cfg, #repo_clusters_dir, #repo_cookbook_paths, #repo_dir, #repo_names, #repo_paths, #repos_config, #repos_dir, #run_inside_repo_dir

Methods included from FhcapHelper

#cluster_template_names

Constructor Details

#initialize(options) ⇒ UpdateConfig

Returns a new instance of UpdateConfig.



31
32
33
34
35
36
37
# File 'lib/fhcap/tasks/chef/cookbook/update_config.rb', line 31

def initialize(options)
  super
  @name = options[:cookbook]
  @overrides = options[:overrides] || []
  @sort = options[:sort] || true
  @force = options[:force] || false
end

Instance Attribute Details

#forceObject (readonly)

Returns the value of attribute force.



29
30
31
# File 'lib/fhcap/tasks/chef/cookbook/update_config.rb', line 29

def force
  @force
end

#nameObject (readonly)

Returns the value of attribute name.



29
30
31
# File 'lib/fhcap/tasks/chef/cookbook/update_config.rb', line 29

def name
  @name
end

#overridesObject (readonly)

Returns the value of attribute overrides.



29
30
31
# File 'lib/fhcap/tasks/chef/cookbook/update_config.rb', line 29

def overrides
  @overrides
end

#sortObject (readonly)

Returns the value of attribute sort.



29
30
31
# File 'lib/fhcap/tasks/chef/cookbook/update_config.rb', line 29

def sort
  @sort
end

Instance Method Details

#runObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fhcap/tasks/chef/cookbook/update_config.rb', line 39

def run
  thor.say "Chef::Cookbook::UpdateConfig cookbook = #{name}", :yellow
  cookbook = cookbook_loader.cookbooks_by_name[name]

  conf_attr_file = cookbook.attribute_filenames.find { |e| /conf.rb/ =~ e }
  unless conf_attr_file
    return thor.say "No cookbook conf.rb attribute file found for #{name}, skipping config update"
  end

  conf_src_files = cfg_lookup(name)

  if conf_src_files.empty?
    return thor.say "No local src config file found for #{name}, skipping config update"
  end

  thor.say "conf_attr_file = #{conf_attr_file}"
  thor.say "conf_src_files = #{conf_src_files}"

  conf_src_files.each() do |file|
    if File.exists? file
      if File.extname(file) =~ /.properties/
        cfg = Fhcap::JavaConfig.new
      else
        cfg = Fhcap::JsonConfig.new
      end
      cfg.from_attributes_file(name, conf_attr_file)
      cfg.from_file(file, force, overrides)
      thor.create_file(conf_attr_file, cfg.attribute_file_content(name, sort), {force: force})
      if is_dirty?(conf_attr_file)
        thor.say "Updated #{name} config: #{git_diff(conf_attr_file)}"
      else
        thor.say "No config changes for #{name}"
      end
    else
      thor.say "Missing local file '#{file}', skipping config update"
    end
  end

end