11Puppet ::Type . type ( :postgresql_psql ) . provide ( :ruby ) do
2-
32 def run_unless_sql_command ( sql )
43 # for the 'unless' queries, we wrap the user's query in a 'SELECT COUNT',
54 # which makes it easier to parse and process the output.
6- run_sql_command ( 'SELECT COUNT(*) FROM (' << sql << ') count' )
5+ run_sql_command ( 'SELECT COUNT(*) FROM (' << sql << ') count' )
76 end
87
98 def run_sql_command ( sql )
@@ -12,9 +11,9 @@ def run_sql_command(sql)
1211 end
1312
1413 command = [ resource [ :psql_path ] ]
15- command . push ( "-d" , resource [ :db ] ) if resource [ :db ]
16- command . push ( "-p" , resource [ :port ] ) if resource [ :port ]
17- command . push ( "-t" , "-c" , '"' + sql . gsub ( '"' , '\"' ) + '"' )
14+ command . push ( '-d' , resource [ :db ] ) if resource [ :db ]
15+ command . push ( '-p' , resource [ :port ] ) if resource [ :port ]
16+ command . push ( '-t' , '-c' , '"' + sql . gsub ( '"' , '\"' ) + '"' )
1817
1918 environment = get_environment
2019
@@ -29,28 +28,29 @@ def run_sql_command(sql)
2928
3029 private
3130
32- def get_environment
31+ def get_environment # rubocop:disable Style/AccessorMethodName : Refactor does not work correctly
3332 environment = ( resource [ :connect_settings ] || { } ) . dup
34- if envlist = resource [ :environment ]
35- envlist = [ envlist ] unless envlist . is_a? Array
36- envlist . each do |setting |
37- if setting =~ /^(\w +)=((.|\n )+)$/
38- env_name = $1
39- value = $2
40- if environment . include? ( env_name ) || environment . include? ( env_name . to_sym )
41- if env_name == 'NEWPGPASSWD'
42- warning "Overriding environment setting '#{ env_name } ' with '****'"
43- else
44- warning "Overriding environment setting '#{ env_name } ' with '#{ value } '"
45- end
33+ envlist = resource [ :environment ]
34+ return environment unless envlist
35+
36+ envlist = [ envlist ] unless envlist . is_a? Array
37+ envlist . each do |setting |
38+ if setting =~ %r{^(\w +)=((.|\n )+)$}
39+ env_name = Regexp . last_match ( 1 )
40+ value = Regexp . last_match ( 2 )
41+ if environment . include? ( env_name ) || environment . include? ( env_name . to_sym )
42+ if env_name == 'NEWPGPASSWD'
43+ warning "Overriding environment setting '#{ env_name } ' with '****'"
44+ else
45+ warning "Overriding environment setting '#{ env_name } ' with '#{ value } '"
4646 end
47- environment [ env_name ] = value
48- else
49- warning "Cannot understand environment setting #{ setting . inspect } "
5047 end
48+ environment [ env_name ] = value
49+ else
50+ warning "Cannot understand environment setting #{ setting . inspect } "
5151 end
5252 end
53- return environment
53+ environment
5454 end
5555
5656 def run_command ( command , user , group , environment )
@@ -65,16 +65,13 @@ def run_command(command, user, group, environment)
6565 Puppet ::Util ::SUIDManager . run_and_capture ( command , user , group )
6666 end
6767 else
68- output = Puppet ::Util ::Execution . execute ( command , {
69- :uid => user ,
70- :gid => group ,
71- :failonfail => false ,
72- :combine => true ,
73- :override_locale => true ,
74- :custom_environment => environment ,
75- } )
68+ output = Puppet ::Util ::Execution . execute ( command , uid : user ,
69+ gid : group ,
70+ failonfail : false ,
71+ combine : true ,
72+ override_locale : true ,
73+ custom_environment : environment )
7674 [ output , $CHILD_STATUS. dup ]
7775 end
7876 end
79-
8077end
0 commit comments