From d7729c9b51ace63a1146c49e065d64d3e9476e2f Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Mon, 19 Mar 2018 12:58:23 +0100 Subject: [PATCH] fact projectid --- CHANGELOG.md | 4 ++++ lib/facter/eypconf_projectid.rb | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 lib/facter/eypconf_projectid.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 051f372..95b3ea8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.1.13 + +* added **eypconf_projectid** + ## 0.1.12 * added **yesno2bool** function diff --git a/lib/facter/eypconf_projectid.rb b/lib/facter/eypconf_projectid.rb new file mode 100644 index 0000000..25b2003 --- /dev/null +++ b/lib/facter/eypconf_projectid.rb @@ -0,0 +1,25 @@ +if File.exists?('/opt/eypconf/id/projectid.sh') then + userid = Facter::Util::Resolution.exec('bash /opt/eypconf/id/projectid.sh').to_s +else + userid = Facter::Util::Resolution.exec('bash -c \'if [ -f /opt/eypconf/id/projectid ]; then cat /opt/eypconf/id/projectid | paste -sd,; fi\'').to_s +end + +unless userid.nil? or userid.empty? + Facter.add('eypconf_projectid') do + setcode do + userid + end + end + + Facter.add('eypconf_projectid_uppercase') do + setcode do + userid.upcase + end + end + + Facter.add('eypconf_projectid_lowercase') do + setcode do + userid.downcase + end + end +end