# TODO: reimplement it :-)

certs = node['certs']

if certs
  certs.each do |cert_name, cert_props|
    cert_key_file = cert_props['key_file']
    cert_crt_file = cert_props['cert_file']
    certs_databag = cert_props['databag']

    begin
      cert = data_bag_item(certs_databag, cert_name)

      file cert_key_file do
        content cert['key']
      end
      file cert_crt_file do
        content cert['crt']
      end
    rescue
      Chef::Log.warn("Cannot find databag #{certs_databag} with item skipping #{cert_key_file} file creation")
    end
  end
end
