<commit_before>#
# Cookbook Name:: elasticsearch-cluster
# Recipe:: config
#
# Copyright 2015, <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

raise "require value for node['elasticsearch']['#{node['elasticsearch']['config_attribute']}']['cluster.name']" unless node['elasticsearch'][node['elasticsearch']['config_attribute']]['cluster.name']

directory node['elasticsearch']['conf_dir'] do
  mode node['elasticsearch']['dir_mode']
end

[node['elasticsearch']['scripts_dir'],
 node['elasticsearch']['plugins_dir']].each do |d|
  directory d do
    owner node['elasticsearch']['user']
    group node['elasticsearch']['group']
    mode node['elasticsearch']['mode']
  end
end

template 'elasticsearch_env_file' do
  path node['elasticsearch']['sysconfig_file']
  cookbook node['elasticsearch']['cookbook']
  source 'sysconfig.erb'
  owner 'root'
  group 'root'
  mode 0644
  notifies :restart, 'service[elasticsearch]' if node['elasticsearch']['notify_restart']
end

if node['elasticsearch']['use_chef_search']
  node.default['elasticsearch']['config']['discovery.zen.ping.unicast.hosts'] = search_cluster_nodes(node.chef_environment, node['elasticsearch']['search_role_name'], node['elasticsearch']['search_cluster_name_attr'], node[node['elasticsearch']['search_cluster_name_attr']])
end

config = node['elasticsearch'][node['elasticsearch']['config_attribute']].to_h
node['elasticsearch']['databag_configs'].each do |databag|
  data_bag_item = Chef::EncryptedDataBagItem.load(databag['name'], databag['item'])
  databag['config_items'].each do |k, v|
    config[k] = data_bag_item[v]
  end
end if node['elasticsearch']['databag_configs']

template node['elasticsearch']['conf_file'] do
  cookbook node['elasticsearch']['cookbook']<commit_msg>fix rubocop<commit_after>#
# Cookbook Name:: elasticsearch-cluster
# Recipe:: config
#
# Copyright 2015, <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

raise "require value for node['elasticsearch']['#{node['elasticsearch']['config_attribute']}']['cluster.name']" unless node['elasticsearch'][node['elasticsearch']['config_attribute']]['cluster.name']

directory node['elasticsearch']['conf_dir'] do
  mode node['elasticsearch']['dir_mode']
end

[node['elasticsearch']['scripts_dir'],
 node['elasticsearch']['plugins_dir']].each do |d|
  directory d do
    owner node['elasticsearch']['user']
    group node['elasticsearch']['group']
    mode node['elasticsearch']['mode']
  end
end

template 'elasticsearch_env_file' do
  path node['elasticsearch']['sysconfig_file']
  cookbook node['elasticsearch']['cookbook']
  source 'sysconfig.erb'
  owner 'root'
  group 'root'
  mode 0644
  notifies :restart, 'service[elasticsearch]' if node['elasticsearch']['notify_restart']
end

if node['elasticsearch']['use_chef_search']
  node.default['elasticsearch']['config']['discovery.zen.ping.unicast.hosts'] = search_cluster_nodes(node.chef_environment, node['elasticsearch']['search_role_name'], node['elasticsearch']['search_cluster_name_attr'], node[node['elasticsearch']['search_cluster_name_attr']])
end

config = node['elasticsearch'][node['elasticsearch']['config_attribute']].to_h
if node['elasticsearch']['databag_configs']
  node['elasticsearch']['databag_configs'].each do |databag|
    data_bag_item = Chef::EncryptedDataBagItem.load(databag['name'], databag['item'])
    databag['config_items'].each do |k, v|
      config[k] = data_bag_item[v]
    end
  end
end

template node['elasticsearch']['conf_file'] do
  cookbook node['elasticsearch']['cookbook']
{'fraction_non_alphanumeric': 0.1488042515500443, 'fraction_numerical': 0.005314437555358724, 'mean_word_length': 7.080500894454383, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5958246', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1292, 'n_words': 335}