forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
puppet: Migrate Ruby functions from legacy Puppet 3.x API.
https://www.puppet.com/docs/puppet/7/functions_refactor_legacy.html This removes a bug in the 3.x API that was converting nil to the empty string, so some templates need to be adjusted. Signed-off-by: Anders Kaseorg <[email protected]>
- Loading branch information
Showing
11 changed files
with
100 additions
and
94 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "shellwords" | ||
|
||
Puppet::Functions.create_function(:zulipconf) do | ||
def zulipconf(section, key, default) | ||
zulip_conf_path = Facter.value("zulip_conf_path") | ||
output = `/usr/bin/crudini --get -- #{[zulip_conf_path, section, key].shelljoin} 2>&1`; result = $?.success? | ||
if result | ||
if [true, false].include? default | ||
# If the default is a bool, coerce into a bool. This list is also | ||
# maintained in scripts/lib/zulip_tools.py | ||
["1", "y", "t", "true", "yes", "enable", "enabled"].include? output.strip.downcase | ||
else | ||
output.strip | ||
end | ||
else | ||
default | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require "shellwords" | ||
|
||
Puppet::Functions.create_function(:zulipconf_keys) do | ||
def zulipconf_keys(section) | ||
zulip_conf_path = Facter.value("zulip_conf_path") | ||
output = `/usr/bin/crudini --get -- #{[zulip_conf_path, section].shelljoin} 2>&1`; result = $?.success? | ||
if result | ||
return output.lines.map { |l| l.strip } | ||
else | ||
return [] | ||
end | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
puppet/zulip/lib/puppet/functions/zulipconf_nagios_hosts.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "shellwords" | ||
|
||
Puppet::Functions.create_function(:zulipconf_nagios_hosts) do | ||
def zulipconf_nagios_hosts | ||
section = "nagios" | ||
prefix = "hosts_" | ||
zulip_conf_path = Facter.value("zulip_conf_path") | ||
keys = `/usr/bin/crudini --get -- #{[zulip_conf_path, section].shelljoin} 2>&1`; result = $?.success? | ||
if result | ||
filtered_keys = keys.lines.map { |l| l.strip }.select { |l| l.start_with?(prefix) } | ||
all_values = [] | ||
filtered_keys.each do |key| | ||
values = `/usr/bin/crudini --get -- #{[zulip_conf_path, section, key].shelljoin} 2>&1`; result = $?.success? | ||
if result | ||
all_values += values.strip.split(/,\s*/) | ||
end | ||
end | ||
return all_values | ||
else | ||
return [] | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require "shellwords" | ||
|
||
Puppet::Functions.create_function(:zulipsecret) do | ||
def zulipsecret(section, key, default) | ||
output = `/usr/bin/crudini --get -- /etc/zulip/zulip-secrets.conf #{[section, key].shelljoin} 2>&1`; result = $?.success? | ||
if result | ||
output.strip() | ||
else | ||
default | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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
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
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