1 $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"..","..",".."))
2 require 'puppet/util/postgresql_validator'
4 # This file contains a provider for the resource type `postgresql_conn_validator`,
5 # which validates the puppetdb connection by attempting an https connection.
7 Puppet::Type.type(:postgresql_conn_validator).provide(:ruby) do
8 desc "A provider for the resource type `postgresql_conn_validator`,
9 which validates the PostgreSQL connection by attempting a query
10 to the target PostgreSQL server."
12 # Test to see if the resource exists, returns true if it does, false if it
15 # Here we simply monopolize the resource API, to execute a test to see if the
16 # database is connectable. When we return a state of `false` it triggers the
17 # create method where we can return an error message.
19 # @return [bool] did the test succeed?
21 validator.attempt_connection(resource[:sleep], resource[:tries])
24 # This method is called when the exists? method returns false.
28 # If `#create` is called, that means that `#exists?` returned false, which
29 # means that the connection could not be established... so we need to
30 # cause a failure here.
31 raise Puppet::Error, "Unable to connect to PostgreSQL server! (#{resource[:host]}:#{resource[:port]})"
34 # Returns the existing validator, if one exists otherwise creates a new object
39 @validator ||= Puppet::Util::PostgresqlValidator.new(resource)