chef/cookbooks/cpe_nudge/resources/cpe_nudge_python_json.rb (44 lines of code) (raw):

# # Cookbook:: cpe_nudge # Resources:: cpe_nudge_python_json # # vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2 # # Copyright:: (c) 2019-present, Uber Technologies, Inc. # All rights reserved. # # This source code is licensed under the Apache 2.0 license found in the # LICENSE file in the root directory of this source tree. # unified_mode true resource_name :cpe_nudge_python_json provides :cpe_nudge_python_json, :os => 'darwin' default_action :manage action :manage do install if install? && !uninstall? end action_class do def install? node['cpe_nudge']['nudge-python']['manage_json'] end def uninstall? node['cpe_nudge']['nudge-python']['uninstall'] end def launchagent_label node.nudge_launchctl_label('python', 'launchagent_identifier') end def launchagent_path node.nudge_launchctl_path('python', 'launchagent_identifier') end def install unless ::File.exists?(node['cpe_nudge']['nudge-python']['python_path']) Chef::Log.warn("Python defined in node['cpe_nudge']['nudge-python']['python_path'] is not installed.") return end # JSON json_path = node['cpe_nudge']['nudge-python']['json_path'] json_prefs = node['cpe_nudge']['nudge-python']['json_prefs'].to_h.compact if json_prefs.empty? || json_prefs.nil? Chef::Log.warn('config is not populated, skipping configuration') return end # If we are updating nudge JSON, we need to disable the launch agent. # cpe_launchd will turn it back on later in the run so we don't have a # mismatch in what's loaded in memory and what's on disk file json_path do mode '0644' owner root_owner group node['root_group'] content Chef::JSONCompat.to_json_pretty(json_prefs.sort.to_h) notifies :disable, "launchd[#{launchagent_label}]", :immediately if ::File.exists?(launchagent_path) end # Triggered Launch Agent action launchd launchagent_label do action :nothing type 'agent' end end end