puppet-openstack_extras/lib/puppet/functions/validate_yum_hash.rb
Tobias Urdin 79481df8ef Use puppet4 functions-api
Depends-On: https://review.openstack.org/#/c/614782/
Change-Id: I7bb50c4e591585b80661fe0d41c7cc2dfec5fdf8
2018-11-01 16:31:22 +01:00

59 lines
1.3 KiB
Ruby

Puppet::Functions.create_function(:validate_yum_hash) do
def validate_yum_hash(*args)
yumrepo_arguments = [
'name',
'ensure',
'baseurl',
'cost',
'descr',
'enabled',
'enablegroups',
'exclude',
'failovermethod',
'gpgcheck',
'gpgkey',
'http_caching',
'include',
'includepkgs',
'keepalive',
'metadata_expire',
'metalink',
'mirrorlist',
'priority',
'protect',
'provider',
'proxy',
'proxy_password',
'proxy_username',
'repo_gpgcheck',
's3_enabled',
'skip_if_unavailable',
'sslcacert',
'sslclientcert',
'sslclientkey',
'sslverify',
'target',
'timeout'
]
if args.size > 1
raise Puppet::Error, "validate_yum_hash takes only a single argument, #{args.size} provided"
end
arg = args[0]
if not arg.kind_of?(Hash)
raise Puppet::Error, "non-hash argument provided to validate_yum_hash"
end
if arg.size > 0
arg.each do |title, params|
params.each do |param, value|
if ! yumrepo_arguments.include?(param)
raise Puppet::Error, "Parameter #{param} is not valid for the yumrepo type"
end
end
end
end
end
end