File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
lib/sensu-plugins-postgres Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 1
1
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
+
2
13
def pgpass
3
14
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 ] ) ) ]
5
16
pgpass [ :database ] = nil if pgpass [ :database ] == '*'
6
17
pgpass . each do |k , v |
7
18
config [ k ] ||= v
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ RUBY_HOME=${MY_RUBY_HOME}
17
17
18
18
# setup a .pgpass file
19
19
cat << EOF > /tmp/.pgpass
20
+ # This is a comment
20
21
*:5432:*:postgres:<REDACTED>
21
22
EOF
22
23
You can’t perform that action at this time.
0 commit comments