Skip to content

Commit e07866e

Browse files
phumpalmajormoses
authored andcommitted
ignore comments in pgpass
1 parent aca5874 commit e07866e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/sensu-plugins-postgres/pgpass.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
module Pgpass
2+
def read_pgpass(pg_pass_file)
3+
File.readlines(pg_pass_file).each do |line|
4+
if line.start_with?('#')
5+
# Perform no action. Line is a comment
6+
next
7+
else
8+
return line.strip.split(':')
9+
end
10+
end
11+
end
12+
213
def pgpass
314
if File.file?(config[:pgpass])
4-
pgpass = Hash[%i[hostname port database user password].zip(File.readlines(config[:pgpass])[0].strip.split(':'))]
15+
pgpass = Hash[%i[hostname port database user password].zip(read_pgpass(config[:pgpass]))]
516
pgpass[:database] = nil if pgpass[:database] == '*'
617
pgpass.each do |k, v|
718
config[k] ||= v

test/fixtures/bootstrap.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ RUBY_HOME=${MY_RUBY_HOME}
1717

1818
# setup a .pgpass file
1919
cat << EOF > /tmp/.pgpass
20+
# This is a comment
2021
*:5432:*:postgres:<REDACTED>
2122
EOF
2223

0 commit comments

Comments
 (0)