Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting functions to the modern Puppet 4.x API #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions lib/puppet/functions/managedmac/compact_hash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This is an autogenerated function, ported from the original legacy version.
# It /should work/ as is, but will not have all the benefits of the modern
# function API. You should see the function docs to learn how to add function
# signatures for type safety and to document this function using puppet-strings.
#
# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html
#
# ---- original file header ----

# ---- original file header ----
#
# @summary
# Hash keys with empty or undef values are deleted. Returns resulting Hash.
#
#
Puppet::Functions.create_function(:'managedmac::compact_hash') do
# @param args
# The original array of arguments. Port this to individually managed params
# to get the full benefit of the modern function API.
#
# @return [Data type]
# Describe what the function returns here
#
dispatch :default_impl do
# Call the method named 'default_impl' when this is matched
# Port this to match individual params for better type safety
repeated_param 'Any', :args
end


def default_impl(*args)


e = "compact_hash(): Wrong number of args: #{args.size} for 1"
raise(Puppet::ParseError, e) if args.size != 1

the_hash = args.shift
raise(Puppet::ParseError, "arg was not a Hash") unless the_hash.is_a? Hash

the_hash.delete_if do |k,v|
(v.empty? if v.respond_to? :empty?) or v == :undef or v.nil?
end

end
end
53 changes: 53 additions & 0 deletions lib/puppet/functions/managedmac/portablehomes_excluded_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This is an autogenerated function, ported from the original legacy version.
# It /should work/ as is, but will not have all the benefits of the modern
# function API. You should see the function docs to learn how to add function
# signatures for type safety and to document this function using puppet-strings.
#
# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html
#
# ---- original file header ----

# ---- original file header ----
#
# @summary
# Returns a Array of properly formatted excludeItems Hashes.
#
#
Puppet::Functions.create_function(:'managedmac::portablehomes_excluded_items') do
# @param args
# The original array of arguments. Port this to individually managed params
# to get the full benefit of the modern function API.
#
# @return [Data type]
# Describe what the function returns here
#
dispatch :default_impl do
# Call the method named 'default_impl' when this is matched
# Port this to match individual params for better type safety
repeated_param 'Any', :args
end


def default_impl(*args)


if args.size != 1
e = "portablehomes_excluded_items(): Too many args! (#{args.size} instead of 1)"
raise(Puppet::ParseError, e)
end

unless args[0].is_a? Hash
e = "portablehomes_excluded_items(): Wrong arg type! (#{args[0].class} instead of Hash)"
raise(Puppet::ParseError, e)
end

args[0].inject([]) do |memo,(k,v)|
v.each do |p|
memo << {'comparison' => k, 'value' => p}
end
memo
end


end
end
51 changes: 51 additions & 0 deletions lib/puppet/functions/managedmac/portablehomes_synced_folders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This is an autogenerated function, ported from the original legacy version.
# It /should work/ as is, but will not have all the benefits of the modern
# function API. You should see the function docs to learn how to add function
# signatures for type safety and to document this function using puppet-strings.
#
# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html
#
# ---- original file header ----

# ---- original file header ----
#
# @summary
# Returns a Array of properly formatted syncedFolder Hashes.
#
#
Puppet::Functions.create_function(:'managedmac::portablehomes_synced_folders') do
# @param args
# The original array of arguments. Port this to individually managed params
# to get the full benefit of the modern function API.
#
# @return [Data type]
# Describe what the function returns here
#
dispatch :default_impl do
# Call the method named 'default_impl' when this is matched
# Port this to match individual params for better type safety
repeated_param 'Any', :args
end


def default_impl(*args)


if args.size != 1
e = "portablehomes_synced_folders(): Too many args! (#{args.size} instead of 1)"
raise(Puppet::ParseError, e)
end

unless args[0].is_a? Array
e = "portablehomes_synced_folders(): Wrong arg type! (#{args[0].class} instead of Array)"
raise(Puppet::ParseError, e)
end

args[0].inject([]) do |memo,e|
memo << {'path' => e}
memo
end


end
end
69 changes: 69 additions & 0 deletions lib/puppet/functions/managedmac/process_dsconfigad_params.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This is an autogenerated function, ported from the original legacy version.
# It /should work/ as is, but will not have all the benefits of the modern
# function API. You should see the function docs to learn how to add function
# signatures for type safety and to document this function using puppet-strings.
#
# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html
#
# ---- original file header ----

# ---- original file header ----
#
# @summary
# Returns a Hash for Dsconfigad type suitable for consumption by
#`create_resources`. It will compact the data and transform Booleans into the
#preferred enable|disable toggle. Accepts a single argument, a Hash.
#
#
Puppet::Functions.create_function(:'managedmac::process_dsconfigad_params') do
# @param args
# The original array of arguments. Port this to individually managed params
# to get the full benefit of the modern function API.
#
# @return [Data type]
# Describe what the function returns here
#
dispatch :default_impl do
# Call the method named 'default_impl' when this is matched
# Port this to match individual params for better type safety
repeated_param 'Any', :args
end


def default_impl(*args)


if args.size != 1
e = "process_dsconfigad_params(): Wrong number of args: #{args.size} \
for 1"
raise(Puppet::ParseError, e)
end

params = args[0]

unless params.is_a? Hash
e = "process_dsconfigad_params(): Wrong arg type! (#{params.class} \
instead of Hash)"
raise(Puppet::ParseError, e)
end

params.inject({}) do |memo, (key,value)|
value = case value
when NilClass, :absent, :undef
nil
when TrueClass
'enable'
when FalseClass
'disable'
else
value
end
unless value.nil? or (value.respond_to? :empty? and value.empty?)
memo[key] = value
end
memo
end


end
end
134 changes: 134 additions & 0 deletions lib/puppet/functions/managedmac/process_mcx_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# This is an autogenerated function, ported from the original legacy version.
# It /should work/ as is, but will not have all the benefits of the modern
# function API. You should see the function docs to learn how to add function
# signatures for type safety and to document this function using puppet-strings.
#
# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html
#
# ---- original file header ----
require 'time'

# ---- original file header ----
#
# @summary
# Returns a com.apple.ManagedClient.preferences Payload.
#
#
Puppet::Functions.create_function(:'managedmac::process_mcx_options') do
# @param args
# The original array of arguments. Port this to individually managed params
# to get the full benefit of the modern function API.
#
# @return [Data type]
# Describe what the function returns here
#
dispatch :default_impl do
# Call the method named 'default_impl' when this is matched
# Port this to match individual params for better type safety
repeated_param 'Any', :args
end


def default_impl(*args)


if args.size != 5
e = "process_mcx_options(): Wrong number of args: #{args.size} for 5"
raise(Puppet::ParseError, e)
end

bluetooth,
wifi,
loginitems,
suppress_icloud_setup,
hidden_preference_panes = *args

settings = {
'com.apple.MCXBluetooth' => {},
'com.apple.MCXAirPort' => {},
'loginwindow' => {},
'com.apple.SetupAssistant' => {},
'com.apple.systempreferences' => {},
}

case bluetooth
when TrueClass, FalseClass
settings['com.apple.MCXBluetooth'] = {
'Forced' => [
{ 'mcx_preference_settings' => { 'DisableBluetooth' => true } }
]
}
else
settings.delete('com.apple.MCXBluetooth')
end

case wifi
when TrueClass, FalseClass
settings['com.apple.MCXAirPort'] = {
'Forced' => [
{ 'mcx_preference_settings' => { 'DisableAirPort' => true } }
]
}
else
settings.delete('com.apple.MCXAirPort')
end

if loginitems.empty?
settings.delete('loginwindow')
else
values = loginitems.collect do |path|
Hash['Hide', false, 'Path', path]
end
settings['loginwindow'] = {
'Forced' => [
{ 'mcx_preference_settings' => {
'AutoLaunchedApplicationDictionary-managed' => values,
'DisableLoginItemsSuppression' => false,
'LoginUserMayAddItems' => true,
}
},
]
}
end

case suppress_icloud_setup
when true
settings['com.apple.SetupAssistant'] = {
'Set-Once' => [
{ 'mcx_data_timestamp' => Time.parse('2013-10-29T17:20:10'),
'mcx_preference_settings' => {
'DidSeeCloudSetup' => true,
'LastSeenCloudProductVersion' =>
lookupvar('macosx_productversion_major'),
},
},
]
}
else
settings.delete('com.apple.SetupAssistant')
end

if hidden_preference_panes.empty?
settings.delete('com.apple.systempreferences')
else
settings['com.apple.systempreferences'] = {
'Forced' => [
{ 'mcx_preference_settings' => {
'HiddenPreferencePanes' => hidden_preference_panes,
}
},
]
}
end

return [] if settings.empty?

# Return a PayloadContent Array
hash = { 'PayloadType' => 'com.apple.ManagedClient.preferences',
'PayloadContent' => settings,
}

[hash]

end
end
Loading