# @param method auth method
# @param order ordering of this entry in pg_hba.conf
define postgres::cluster::hba_entry (
- Integer $pg_port,
- String $pg_cluster,
- String $pg_version,
+ Optional[Integer] $pg_port = undef,
+ Optional[String] $pg_cluster = undef,
+ Optional[String] $pg_version = undef,
Enum['local', 'hostssl'] $connection_type = 'hostssl',
Variant[String,Array[String]] $database = 'sameuser',
Variant[String,Array[String]] $user = 'all',
}
}
+ $clusters = $facts['postgresql_clusters']
+ if $pg_port {
+ $filtered = $clusters.filter |$cluster| { $cluster['port'] == $pg_port }
+ if $filtered.length != 1 {
+ fail("Did not find exactly one cluster with port ${pg_port}")
+ }
+ } elsif $pg_cluster and $pg_version {
+ $filtered = $clusters.filter |$cluster| { $cluster['version'] == $pg_version and $cluster['cluster'] == $pg_cluster}
+ if $filtered.length != 1 {
+ fail("Did not find exactly one cluster ${pg_version}/${pg_cluster}")
+ }
+ } else {
+ fail('postgres::cluster::hba_entry needs either the port of both a pg version and cluster name')
+ }
+ $real_port = $filtered['port']
+ $real_version = $filtered['version']
+ $real_cluster = $filtered['cluster']
+ if $pg_version and $pg_version != $real_version {
+ fail("Inconsisten cluster version information: ${pg_version} != ${real_version}")
+ }
+ if $pg_cluster and $pg_cluster != $real_cluster {
+ fail("Inconsisten cluster name information: ${pg_cluster} != ${real_cluster}")
+ }
+
if ($address) {
ferm::rule::simple { "postgres::cluster::hba_entry::${name}":
- description => "allow access to pg${pg_version}/${pg_cluster}: ${name}",
+ description => "allow access to pg${real_version}/${real_cluster}: ${name}",
saddr => $address,
- chain => "pg-${pg_port}",
+ chain => "pg-${real_port}",
}
}
}
@concat::fragment { "postgres::cluster::pg_hba::${name}":
- tag => "postgres::cluster::${pg_version}::${pg_cluster}::hba",
- target => "postgres::cluster::${pg_version}::${pg_cluster}::hba",
+ tag => "postgres::cluster::${real_version}::${real_cluster}::hba",
+ target => "postgres::cluster::${real_version}::${real_cluster}::hba",
order => $order,
content => inline_template( @(EOF) ),
#