Created
June 20, 2012 19:49
-
-
Save nmische/2961810 to your computer and use it in GitHub Desktop.
ColdFusion Config LWRP
This file contains 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
# | |
# Cookbook Name:: coldfusion902 | |
# Providers:: config | |
# | |
# Copyright 2012, Nathan Mische | |
# | |
# 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 Chef::Mixin::Checksum | |
def initialize(*args) | |
super | |
# Make sure we have unzip package | |
p = package "unzip" do | |
action :nothing | |
end | |
p.run_action(:install) | |
# Download the config manager app | |
rf = remote_file "#{Chef::Config['file_cache_path']}/configmanager.zip" do | |
source "#{node['cf902']['configmanager']['source']['url']}" | |
action :nothing | |
mode "0744" | |
owner "root" | |
group "root" | |
not_if { ::File.exists?("#{node['cf902']['install_path']}/wwwroot/CFIDE/administrator/configmanager") } | |
end | |
rf.run_action(:create_if_missing) | |
# Install the application | |
e = execute "unzip #{Chef::Config['file_cache_path']}/configmanager.zip -d #{node['cf902']['install_path']}/wwwroot/CFIDE/administrator/configmanager" do | |
action :nothing | |
not_if { ::File.exists?("#{node['cf902']['install_path']}/wwwroot/CFIDE/administrator/configmanager") } | |
end | |
e.run_action(:run) | |
end | |
action :set do | |
config = { "#{new_resource.component}" => { "#{new_resource.property}" => [ new_resource.args ] } } | |
if make_api_call(config) | |
new_resource.updated_by_last_action(true) | |
Chef::Log.info("Updated ColdFusion #{new_resource.component} configuration.") | |
else | |
Chef::Log.info("No ColdFusion configuration changes made.") | |
end | |
end | |
action :bulk_set do | |
config = new_resource.config | |
if make_api_call(config) | |
new_resource.updated_by_last_action(true) | |
Chef::Log.info("Updated ColdFusion configuration.") | |
else | |
Chef::Log.info("No ColdFusion configuration changes made.") | |
end | |
end | |
def make_api_call(msg) | |
last_mod = nil | |
made_update = false | |
# Get config state before attempted update | |
before = Dir.glob("#{node['cf902']['install_path']}/lib/neo-*.xml").map { |filename| checksum(filename) } | |
# Make API call | |
hr = http_request "post_config" do | |
action :nothing | |
url "http://#{node['ipaddress']}:8500/CFIDE/administrator/configmanager/api/index.cfm" | |
message msg | |
headers({"AUTHORIZATION" => "Basic #{Base64.encode64("admin:#{node['cf902']['admin_pw']}")}"}) | |
end | |
hr.run_action(:post) | |
# Get config state after attempted update | |
after = Dir.glob("#{node['cf902']['install_path']}/lib/neo-*.xml").map { |filename| checksum(filename) } | |
made_update = true if (after - before).length > 0 | |
made_update | |
end | |
This file contains 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
# | |
# Cookbook Name:: coldfusion902 | |
# Resources:: config | |
# | |
# Copyright 2012, Nathan Mische | |
# | |
# 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. | |
# | |
def initialize(*args) | |
super | |
@action = :set | |
end | |
actions :set, :bulk_set | |
attribute :component, :kind_of => String, :name_attribute => true | |
attribute :property, :kind_of => String | |
attribute :args, :kind_of => Hash | |
attribute :config, :kind_of => Hash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment