<commit_before>#
# Author:: <NAME> (<<EMAIL>>)
# Cookbook Name:: zncrypt
# Recipe:: mongodb
#
# Copyright 2012, Gazzang, Inc.
#
# 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.
#

case node['platform_family']
when "rhel","fedora"
 data_dir="/var/lib/mongo"
 service_name="mongod"
when "debian"
 data_dir="/var/lib/mongodb"
 service_name="mongodb"
end

# let the mongodb cookbook do our heavy lifting
include_recipe "mongodb::default"

# Mongo is installed, we proceed to set up the encryption
# the path here is hardcoded, if it does not match yours edit here

acl_rule1 = which("mongod").first
acl_rule2 = which("mkdir").first

# before anything we stop mongodb
# create the ACLs
passphrase=data_bag_item('license_pool', 'license1')['passphrase']
passphrase2=data_bag_item('license_pool', 'license1')['passphrase2']
script "create ACL" do
 interpreter "bash"
 user "root"
 cwd "/tmp"
 code <<-EOH
 service #{service_name} stop
 ezncrypt-service start
 ezncrypt-access-control -a "ALLOW @mongodb * #{acl_rule1}" -P #{passphrase} -S #{passphrase2}
 ezncrypt-access-control -a "ALLOW @mongodb * #{acl_rule2}" -P #{passphrase} -S #{passphrase2}
 ezncrypt -e @mongodb #{data_dir}
 service #{service_name} start
 EOH
end<commit_msg>reworking mongodb recipe<commit_after>#
# Author:: <NAME> (<<EMAIL>>)
# Cookbook Name:: zncrypt
# Recipe:: mongodb
#
# Copyright 2012, Gazzang, Inc.
#
# 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.
#

include_recipe "mongodb::default"

%w{mongod mkdir}.each do |proc|
  zncrypt_acl which(proc).first do
    category "mongodb"
    path "*"
    permission "ALLOW"
  end
end

unless ::File.exists?(::File.join(node['zncrypt']['zncrypt_mount'],'/',node['mongodb']['dbpath']))

  service "mongodb" do
    action :stop
  end

  license = load_license(node['zncrypt']['license_pool'])

  encrypt_cmd = "ezncrypt -e @mongodb #{node['mongodb']['dbpath']} -P #{license['passphrase']}"

  if license['salt']
    encrypt_cmd = encrypt_cmd + " -S #{license['salt']}"
  end

  execute "encrypt mongodb data" do
    command encrypt_cmd
    notifies :start, "service[mongodb]", :immediately 
  end

end
{'fraction_non_alphanumeric': 0.12173913043478261, 'fraction_numerical': 0.008373590982286634, 'mean_word_length': 4.8273921200750465, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '67436', 'n_tokens_mistral': 1013, 'n_tokens_neox': 962, 'n_words': 340}