Created
May 10, 2016 07:51
-
-
Save kazuhisa/fdc876e303690bb20ba946eb9b170770 to your computer and use it in GitHub Desktop.
chefでImageTragickの対応
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file '/etc/ImageMagick/policy.xml' do | |
policy =<<EOS | |
<policymap> | |
<policy domain="coder" rights="none" pattern="EPHEMERAL" /> | |
<policy domain="coder" rights="none" pattern="URL" /> | |
<policy domain="coder" rights="none" pattern="HTTPS" /> | |
<policy domain="coder" rights="none" pattern="MVG" /> | |
<policy domain="coder" rights="none" pattern="MSL" /> | |
<policy domain="coder" rights="none" pattern="TEXT" /> | |
<policy domain="coder" rights="none" pattern="SHOW" /> | |
<policy domain="coder" rights="none" pattern="WIN" /> | |
<policy domain="coder" rights="none" pattern="PLT" /> | |
</policymap> | |
EOS | |
# Chefの置換は複数行に対応していないためChef::Util::Editor#linesからテキストの中身を | |
# 取り出してRubyのgsubで置換している | |
file_edit = Chef::Util::FileEdit.new(path) | |
editor = file_edit.send(:editor) | |
target_text = editor.lines.join | |
target_text.gsub!(/<policymap>.+?<\/policymap>/m, policy) | |
editor.instance_variable_set(:@lines, target_text.split("\n").map { |v| v + "\n" }) | |
content file_edit.send(:editor).lines.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment