require"mixlib/config"unlessdefined?(Mixlib::Config)require"openssl"unlessdefined?(OpenSSL)# we need this method, but have to inject it into mixlib-config directly# to have it available from config contextsmoduleMixlibmoduleConfigdefeach(&block)save(true).each(&block)endendendmoduleBerkshelfclassConfigclass<<self# @return [String]defstore_locationFile.join(Berkshelf.berkshelf_path,"config.json")end# @return [String]deflocal_locationENV["BERKSHELF_CONFIG"]||File.join(".",".berkshelf","config.json")end# @return [String]defpathpath=File.exist?(local_location)?local_location:store_locationFile.expand_path(path)end# @param [Berkshelf::Config] configdefset_config(config)@instance=configend# @param [String] new_pathdefset_path(new_path)@instance=nilend# Instantiate and return or just return the currently instantiated Berkshelf# configuration## @return [Config]definstance@instance||=new(path)coerce_sslend# Reload the currently instantiated Berkshelf configuration## @return [Config]defreload@instance=nilinstanceend# force proper X509 types from any configuration strings## @return [Config]defcoerce_sslssl=@instance[:ssl]ssl[:ca_cert]=OpenSSL::X509::Certificate.new(File.read(ssl[:ca_cert]))ifssl[:ca_cert]&&ssl[:ca_cert].is_a?(String)ssl[:client_cert]=OpenSSL::X509::Certificate.new(File.read(ssl[:client_cert]))ifssl[:client_cert]&&ssl[:client_cert].is_a?(String)ssl[:client_key]=OpenSSL::PKey::RSA.new(File.read(ssl[:client_key]))ifssl[:client_key]&&ssl[:client_key].is_a?(String)@instanceenddeffrom_file(path)new(path)endendattr_accessor:path# @param [String] pathdefinitialize(path=self.class.path)# this is a bit tricky, mixlib-config wants to extend a class and create effectively a global config object while# what we want to do is use an instance, so we create an anonymous class and shove it into an instance variable.# this is actually similar to what mixlib-config itself does to create config contexts.@klass=Class.new@klass.extend(Mixlib::Config)@klass.extend(BerksConfig)@path=File.expand_path(path)@klass.from_file(@path)ifFile.exist?(@path)# yeah, if !File.exist?() you just get back an empty config objectBerkshelf.ui.warn"The `cookbook.copyright' config is deprecated and will be removed in a future release."unlesscookbook.copyright.nil?Berkshelf.ui.warn"The `cookbook.email' config is deprecated and will be removed in a future release."unlesscookbook.email.nil?Berkshelf.ui.warn"The `cookbook.license' config is deprecated and will be removed in a future release."unlesscookbook.license.nil?Berkshelf.ui.warn"The `vagrant.vm.box' config is deprecated and will be removed in a future release."unlessvagrant.vm.box.nil?Berkshelf.ui.warn"The `vagrant.vm.forward_port' config is deprecated and will be removed in a future release."unlessvagrant.vm.forward_port.nil?Berkshelf.ui.warn"The `vagrant.vm.provision' config is deprecated and will be removed in a future release."unlessvagrant.vm.provision.nil?Berkshelf.ui.warn"The `vagrant.vm.omnibus.version' config is deprecated and will be removed in a future release."unlessvagrant.vm.omnibus.version.nil?enddefmethod_missing(method,*args,&block)@klass.send(method,*args,&block)endmoduleBerksConfigdefself.extended(base)base.class_execdoconfig_strict_modetrueconfig_context:apidodefault:timeout,"30"endconfig_context:chefdodefault:chef_server_url,Berkshelf.chef_config.chef_server_urldefault:validation_client_name,Berkshelf.chef_config.validation_client_namedefault:validation_key_path,Berkshelf.chef_config.validation_keydefault:client_key,Berkshelf.chef_config.client_keydefault:node_name,Berkshelf.chef_config.node_namedefault:trusted_certs_dir,Berkshelf.chef_config.trusted_certs_dirdefault:artifactory_api_key,Berkshelf.chef_config.artifactory_api_keyendconfig_context:cookbookdodefault:copyright,nildefault:email,nildefault:license,nilenddefault:allowed_licenses,[]default:raise_license_exception,falseconfig_context:vagrantdoconfig_context:vmdodefault:box,nildefault:forward_port,nildefault:provision,nilconfig_context:omnibusdodefault:version,nilendendendconfig_context:ssldodefault:verify,truedefault:cert_store,falsedefault:ca_file,nildefault:ca_path,nildefault:ca_cert,nildefault:client_cert,nildefault:client_key,nilenddefault:github,[]default:gitlab,[]# :git, :ssh, or :httpsdefault:github_protocol,:httpsendendendendend