Module: ChefWorkstationInitialize::SelfBootstrap::WithChef::ChefHelpers
Instance Attribute Summary
Attributes included from NoChef::SelfBootstrapHelpers
Attributes included from NoChef::WorkstationHelpers
Instance Method Summary collapse
- #generate_databag(databag_name, item_name, raw_databag, secret_databag_item = nil, databag_action = :create) ⇒ Object
- #generate_secret_databag(databag_name, item_name) ⇒ Object
- #get_databag(databag_name, item_name, secret_databag_item = nil) ⇒ Object
Methods included from GitHelpers
#get_git_server, #get_git_submodule
Methods included from CommandlineHelpers
Methods included from DefaultMethodsHelpers
Methods included from NoChef::SelfBootstrapHelpers
#boostrapp_once, #boostrapped?, #bootstrap_self, #bootstrap_self_command, #chef_client_self_bootstrap_cmd, #chef_solo_options, #chef_solo_options_command, #chef_solo_options_encode, #for_search_local_node?, #for_solo?, #install_this_gem, #is_boostrapping?, #is_self_bootsrapping?, #is_solo?, #remove_bootstrap_file, #restart_bootstrap, #run_as_root?, #set_chef_profile, #skip_boostrap?, #solo_options, #unauthorized_to_boostrap?
Methods included from NoChef::WorkstationResourceHelpers
#default_workstation_data, #get_workstation, #set_workstation_data, #set_workstation_resource, #swap_workstation, #workstation_resource, #workstation_resource_keys
Methods included from NoChef::WorkstationHelpers
#auto_repo, #bootstrapping_progress_file, #change_unix_permission, #create_main_generator, #main_generator_name, #new_cookbook_name, #node_infra_chef, #prepare_new_resource, #project_name, #workstation_acl_path, #workstation_berks_vendor_dir, #workstation_cache_dir, #workstation_cache_options_syntaxe_path, #workstation_cache_path, #workstation_checksum_path, #workstation_chef_environments_dir, #workstation_chef_repo_path, #workstation_client_d_dir, #workstation_client_key_path, #workstation_client_path, #workstation_config_d_dir, #workstation_config_dir, #workstation_container_path, #workstation_cookbook_artifact_path, #workstation_cookbooks_dir, #workstation_data_bags_dir, #workstation_download_dir, #workstation_file, #workstation_file_backup_path, #workstation_file_cache_path, #workstation_generators_dir, #workstation_group_path, #workstation_libraries_dir, #workstation_logs_dir, #workstation_nodes_dir, #workstation_ohai_segment_plugin_path, #workstation_policy_dir, #workstation_policy_files_dir, #workstation_policy_group_dir, #workstation_resources_dir, #workstation_roles_dir, #workstation_scripts_dir, #workstation_solo_d_dir, #workstation_syntax_check_cache_path, #workstation_trusted_certs_dir, #workstation_user_path
Methods included from NoChef::UsersHelpers
#create_group, #create_user, #generate_secret, #generate_ssh_user_key, #generate_user_data, #secretdatabag, #secretdatabagitem, #secretdatabagkey, #set_cookbook_user_secret_key, #user_fully_created?, #userdatabag
Methods included from NoChef::UpdateHelpers
Methods included from NoChef::KnifeHelpers
#get_solo_cmd, #is_knife?, #knife, #knife_get_node_attribute, #knife_search_self_cmd, #knife_self_bootstrap_cmd, #self_bootstrap_options
Methods included from NoChef::ChefRepoHelpers
#create_attribute_file, #create_chef_additionnal_dir, #create_chef_infra_cookbook, #create_cookbook, #create_generator, #create_recipe, #create_template_file, #define_cron_job, #ensure_main_environment, #project_environment_json, #project_role_json, #render_template, #write_Solo_file, #write_kitchen_file, #write_main_environment, #write_main_role, #write_main_role_environment, #write_role_environment
Methods included from NoChef::KitchenHelpers
#building_kitchen, #generate_kitchen, #generate_machine, #is_kitchen_command?, #kitchen, #kitchen_machine, #kitchen_root
Methods included from NoChef::ProvisionersHelpers
#chef_zero_provisioner, #provisioners
Methods included from NoChef::PlatformsHelpers
Methods included from NoChef::SuitesHelpers
Methods included from NoChef::VerifiersHelpers
Methods included from NoChef::ChefHelpers
#chef, #chef_client, #install_chef_workstation, #is_chef_cli_command?, #is_chef_client_command?, #is_chef_command?, #is_chef_enabled?, #is_chef_installed?, #is_chef_profile_set?, #is_chefworkstation_available?, #is_knife_gem_install?
Methods included from NoChef::BerksHelpers
#berks, #berks_vendor, #berks_vendor_all_cookbook, #berks_vendor_cookbook, #berks_vendor_init, #delete_all_berkslock, #delete_cookbook_berkslock, #reset_berks_vendor_dir, #self_berks_vendor
Methods included from NoChef::GitHelpers
#all_cookbooks, #generate_git_submodules, #generate_json_repo, #get_git_path, #get_git_relative_path, #get_git_server, #get_git_submodule, #get_self_git, #git_exec, #git_submodule_init, #repository_list
Methods included from NoChef::SSHHelpers
#delete_hostkey, #delete_hostkey_ip_or_name, #generate_private_key, #ssh, #ssh_command, #ssh_keygen
Methods included from NoChef::CommandlineHelpers
#base_command, #get_homedir, #is_mixlib_disabled?, #main_command, #run_options
Methods included from NoChef::DefaultMethodsHelpers
#analyse_object, #check_install_dir, #debug_worklog, #default_chefzero_portrange, #default_hostname, #default_install_dir, #define_resource_requirements, #error_worklog, #generate_default_install_dir, #generate_directory, #get_out_of_cache_path, #get_out_of_folder, #get_out_of_local_chef_path, #get_path, #is_chef_constant_enabled?, #parent_nil?, #require_implement_method, #search_local_project_folder, #warning_worklog, #worklog, #worklog_counter
Instance Method Details
#generate_databag(databag_name, item_name, raw_databag, secret_databag_item = nil, databag_action = :create) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/selfbootstrap/withchef/chef.rb', line 60 def generate_databag(databag_name, item_name, raw_databag, secret_databag_item = nil, databag_action = :create) chef_data_bag databag_name generate_secret_databag(cookbook_name, secret_databag_item) unless secret_databag_item.nil? debug_worklog("Generating databag #{databag_name} for item #{item_name} using the secret #{secret_databag_item.nil? ? 'no secret' : "#{get_databag(cookbook_name, secret_databag_item)['secret']} using encryption version #{Chef::Config[:data_bag_encrypt_version]}"} containing #{raw_databag}") chef_data_bag_item item_name do raw_json raw_databag data_bag databag_name unless secret_databag_item.nil? encryption_version Chef::Config[:data_bag_encrypt_version].nil? ? 3 : Chef::Config[:data_bag_encrypt_version] secret get_databag(cookbook_name, secret_databag_item)['secret'] encrypt true end end if databag_action == :update # dtbg = get_databag(databag_name, item_name, secret_databag_item) # raw_databag['id'] = item_name if raw_databag['id'].nil? # dtbg.raw_data = raw_databag # dtbg.save ruby_block "Update data bag item #{databag_name}/#{item_name}" do block do # extend ChefWorkstationInitialize::SelfBootstrap extend ChefWorkstationInitialize::ChefHelpers dtbg = get_databag(databag_name, item_name, secret_databag_item) unless dtbg.nil? raw_databag['id'] = item_name if raw_databag['id'].nil? dtbg.raw_data = raw_databag dtbg.save end end action :run end end end |
#generate_secret_databag(databag_name, item_name) ⇒ Object
29 30 31 |
# File 'lib/selfbootstrap/withchef/chef.rb', line 29 def generate_secret_databag(databag_name, item_name) generate_databag(databag_name, item_name, { secret: UnixCrypt::SHA512.build(SecureRandom.base64(12)) }, nil, :update) end |
#get_databag(databag_name, item_name, secret_databag_item = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/selfbootstrap/withchef/chef.rb', line 33 def get_databag(databag_name, item_name, secret_databag_item = nil) secret = nil unless secret_databag_item.nil? secret = get_databag(cookbook_name, secret_databag_item) if secret.nil? # chef_vault_secret "github_ssh_keys" do # data_bag "github" # admins ENV['USER'] # if ENV['USER'] != "root" # clients [node[:name]] # environment node[:chef_environment] # raw_data({ENV['USER'] => {"private_key" => file_open("#{ENV["HOME"]}/.ssh/id_rsa.pub")}}) # search "*:*" # action :create # end generate_secret_databag(cookbook_name, secret_databag_item) secret = get_databag(cookbook_name, secret_databag_item)['secret'] end end case ChefVault::Item.data_bag_item_type(databag_name, item_name) when :normal || :encrypted data_bag_item(databag_name, item_name, secret) when :vault ChefVault::Item.load(databag_name, item_name) end unless data_bag(databag_name).nil? || data_bag(databag_name).empty? || !data_bag(databag_name).include?(item_name) end |