Class: Puppet::Util::PostgresqlValidator
- Inherits:
-
Object
- Object
- Puppet::Util::PostgresqlValidator
- Defined in:
- lib/puppet/util/postgresql_validator.rb
Overview
postgresql_validator.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #attempt_connection(sleep_length, tries) ⇒ Object
- #build_psql_cmd ⇒ Object
- #connect_settings ⇒ Object
-
#initialize(resource) ⇒ PostgresqlValidator
constructor
A new instance of PostgresqlValidator.
Constructor Details
#initialize(resource) ⇒ PostgresqlValidator
Returns a new instance of PostgresqlValidator.
8 9 10 |
# File 'lib/puppet/util/postgresql_validator.rb', line 8 def initialize(resource) @resource = resource end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
6 7 8 |
# File 'lib/puppet/util/postgresql_validator.rb', line 6 def resource @resource end |
Instance Method Details
#attempt_connection(sleep_length, tries) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/puppet/util/postgresql_validator.rb', line 39 def attempt_connection(sleep_length, tries) (0..tries - 1).each do |_try| Puppet.debug "PostgresqlValidator.attempt_connection: Attempting connection to #{@resource[:db_name]}" cmd = build_psql_cmd Puppet.debug "PostgresqlValidator.attempt_connection: #{cmd.inspect}" result = Execution.execute(cmd, custom_environment: connect_settings, uid: @resource[:run_as]) if result && !result.empty? Puppet.debug "PostgresqlValidator.attempt_connection: Connection to #{@resource[:db_name] || connect_settings.select { |elem| elem.include?('PGDATABASE') }} successful!" return true else Puppet.warning "PostgresqlValidator.attempt_connection: Sleeping for #{sleep_length} seconds" sleep sleep_length end end false end |
#build_psql_cmd ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/puppet/util/postgresql_validator.rb', line 12 def build_psql_cmd cmd = [@resource[:psql_path], '--tuples-only', '--quiet', '--no-psqlrc'] args = { host: '--host', port: '--port', db_username: '--username', db_name: '--dbname', command: '--command' } args.each do |k, v| if @resource[k] cmd.push v cmd.push @resource[k] end end cmd end |
#connect_settings ⇒ Object
33 34 35 36 37 |
# File 'lib/puppet/util/postgresql_validator.rb', line 33 def connect_settings result = @resource[:connect_settings] || {} result['PGPASSWORD'] = @resource[:db_password] if @resource[:db_password] result end |