puppetlabs-postgresql-3.2.0/000755 000765 000024 00000000000 12236260460 016677 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/Changelog000644 000765 000024 00000043410 12236260460 020513 0ustar00apenneystaff000000 000000 2013-11-05 - Version 3.2.0 Summary: Add's support for Ubuntu 13.10 (and 14.04) as well as x, y, z. Features: - Add versions for Ubuntu 13.10 and 14.04. - Use default_database in validate_db_connection instead of a hardcoded 'postgres' - Add globals/params layering for default_database. - Allow specification of default database name. Bugs: - Fixes to the README. 2013-10-25 - Version 3.1.0 Summary: This is a minor feature and bug fix release. Firstly, the postgresql_psql type now includes a new parameter `search_path` which is equivalent to using `set search_path` which allows you to change the default schema search path. The default version of Fedora 17 has now been added, so that Fedora 17 users can enjoy the module. And finally we've extended the capabilities of the defined type postgresql::validate_db_connection so that now it can handle retrying and sleeping between retries. This feature has been monopolized to fix a bug we were seeing with startup race conditions, but it can also be used by remote systems to 'wait' for PostgreSQL to start before their Puppet run continues. Features: - Defined $default_version for Fedora 17 (Bret Comnes) - add search_path attribute to postgresql_psql resource (Jeremy Kitchen) - (GH-198) Add wait and retry capability to validate_db_connection (Ken Barber) Bugs: - enabling defined postgres user password without resetting on every puppet run (jonoterc) - periods are valid in configuration variables also (Jeremy Kitchen) - Add zero length string to join() function (Jarl Stefansson) - add require of install to reload class (cdenneen) - (GH-198) Fix race condition on postgresql startup (Ken Barber) - Remove concat::setup for include in preparation for the next concat release (Ken Barber) 2013-10-14 - Version 3.0.0 Final release of 3.0, enjoy! 2013-10-14 - Version 3.0.0-rc3 Summary: Add a parameter to unmanage pg_hba.conf to fix a regression from 2.5, as well as allowing owner to be passed into x. Features: - `manage_pg_hba_conf` parameter added to control pg_hba.conf management. - `owner` parameter added to server::db. 2013-10-09 - Version 3.0.0-rc2 Summary: A few bugfixes have been found since -rc1. Fixes: - Special case for $datadir on Amazon - Fix documentation about username/password for the postgresql_hash function 2013-10-01 - Version 3.0.0-rc1 Summary: Version 3 was a major rewrite to fix some internal dependency issues, and to make the new Public API more clear. As a consequence a lot of things have changed for version 3 and older revisions that we will try to outline here. (NOTE: The format of this CHANGELOG differs to normal in an attempt to explain the scope of changes) * Server specific objects now moved under `postgresql::server::` namespace: To restructure server specific elements under the `postgresql::server::` namespaces the following objects were renamed as such: `postgresql::database` -> `postgresql::server::database` `postgresql::database_grant` -> `postgresql::server::database_grant` `postgresql::db` -> `postgresql::server::db` `postgresql::grant` -> `postgresql::server::grant` `postgresql::pg_hba_rule` -> `postgresql::server::pg_hba_rule` `postgresql::plperl` -> `postgresql::server::plperl` `postgresql::contrib` -> `postgresql::server::contrib` `postgresql::role` -> `postgresql::server::role` `postgresql::table_grant` -> `postgresql::server::table_grant` `postgresql::tablespace` -> `postgresql::server::tablespace` * New `postgresql::server::config_entry` resource for managing configuration: Previously we used the `file_line` resource to modify `postgresql.conf`. This new revision now adds a new resource named `postgresql::server::config_entry` for managing this file. For example: ```puppet postgresql::server::config_entry { 'check_function_bodies': value => 'off', } ``` If you were using `file_line` for this purpose, you should change to this new methodology. * `postgresql_puppet_extras.conf` has been removed: Now that we have a methodology for managing `postgresql.conf`, and due to concerns over the file management methodology using an `exec { 'touch ...': }` as a way to create an empty file the existing postgresql\_puppet\_extras.conf file is no longer managed by this module. If you wish to recreate this methodology yourself, use this pattern: ```puppet class { 'postgresql::server': } $extras = "/tmp/include.conf" file { $extras: content => 'max_connections = 123', notify => Class['postgresql::server::service'], }-> postgresql::server::config_entry { 'include': value => $extras, } ``` * All uses of the parameter `charset` changed to `encoding`: Since PostgreSQL uses the terminology `encoding` not `charset` the parameter has been made consisent across all classes and resources. * The `postgresql` base class is no longer how you set globals: The old global override pattern was less then optimal so it has been fixed, however we decided to demark this properly by specifying these overrides in the class `postgresql::global`. Consult the documentation for this class now to see what options are available. Also, some parameter elements have been moved between this and the `postgresql::server` class where it made sense. * `config_hash` parameter collapsed for the `postgresql::server` class: Because the `config_hash` was really passing data through to what was in effect an internal class (`postgresql::config`). And since we don't want this kind of internal exposure the parameters were collapsed up into the `postgresql::server` class directly. * Lots of changes to 'private' or 'undocumented' classes: If you were using these before, these have changed names. You should only use what is documented in this README.md, and if you don't have what you need you should raise a patch to add that feature to a public API. All internal classes now have a comment at the top indicating them as private to make sure the message is clear that they are not supported as Public API. * `pg_hba_conf_defaults` parameter included to turn off default pg\_hba rules: The defaults should be good enough for most cases (if not raise a bug) but if you simply need an escape hatch, this setting will turn off the defaults. If you want to do this, it may affect the rest of the module so make sure you replace the rules with something that continues operation. * `postgresql::database_user` has now been removed: Use `postgresql::server::role` instead. * `postgresql::psql` resource has now been removed: Use `postgresql_psql` instead. In the future we may recreate this as a wrapper to add extra capability, but it will not match the old behaviour. * `postgresql_default_version` fact has now been removed: It didn't make sense to have this logic in a fact any more, the logic has been moved into `postgresql::params`. * `ripienaar/concat` is no longer used, instead we use `puppetlabs/concat`: The older concat module is now deprecated and moved into the `puppetlabs/concat` namespace. Functionality is more or less identical, but you may need to intervene during the installing of this package - as both use the same `concat` namespace. 2013-09-09 Release 2.5.0 ======================= Summary ------- The focus of this release is primarily to capture the fixes done to the types and providers to make sure refreshonly works properly and to set the stage for the large scale refactoring work of 3.0.0. Features -------- Bugfixes -------- - Use boolean for refreshonly. - Fix postgresql::plperl documentation. - Add two missing parameters to config::beforeservice - Style fixes 2013-08-01 Release 2.4.1 ======================== Summary ------- This minor bugfix release solves an idempotency issue when using plain text passwords for the password_hash parameter for the postgresql::role defined type. Without this, users would continually see resource changes everytime your run Puppet. Bugfixes --------- - Alter role call not idempotent with cleartext passwords (Ken Barber) 2013-07-19 Release 2.4.0 ======================== Summary ------- This updates adds the ability to change permissions on tables, create template databases from normal databases, manage PL-Perl's postgres package, and disable the management of `pg_hba.conf`. Features -------- - Add `postgresql::table_grant` defined resource - Add `postgresql::plperl` class - Add `manage_pg_hba_conf` parameter to the `postgresql::config` class - Add `istemplate` parameter to the `postgresql::database` define Bugfixes -------- - Update `postgresql::role` class to be able to update roles when modified instead of only on creation. - Update tests - Fix documentation of `postgresql::database_grant` 2.3.0 ===== This feature release includes the following changes: * Add a new parameter `owner` to the `database` type. This can be used to grant ownership of a new database to a specific user. (Bruno Harbulot) * Add support for operating systems other than Debian/RedHat, as long as the user supplies custom values for all of the required paths, package names, etc. (Chris Price) * Improved integration testing (Ken Barber) 2.2.1 ===== This release fixes a bug whereby one of our shell commands (psql) were not ran from a globally accessible directory. This was causing permission denied errors when the command attempted to change user without changing directory. Users of previous versions might have seen this error: Error: Error executing SQL; psql returned 256: 'could not change directory to "/root" This patch should correct that. #### Detail Changes * Set /tmp as default CWD for postgresql_psql 2.2.0 ===== This feature release introduces a number of new features and bug fixes. First of all it includes a new class named `postgresql::python` which provides you with a convenient way of install the python Postgresql client libraries. class { 'postgresql::python': } You are now able to use `postgresql::database_user` without having to specify a password_hash, useful for different authentication mechanisms that do not need passwords (ie. cert, local etc.). We've also provided a lot more advanced custom parameters now for greater control of your Postgresql installation. Consult the class documentation for PuppetDB in the README. This release in particular has largely been contributed by the community members below, a big thanks to one and all. #### Detailed Changes * Add support for psycopg installation (Flaper Fesp and Dan Prince) * Added default PostgreSQL version for Ubuntu 13.04 (Kamil Szymanski) * Add ability to create users without a password (Bruno Harbulot) * Three Puppet 2.6 fixes (Dominic Cleal) * Add explicit call to concat::setup when creating concat file (Dominic Cleal) * Fix readme typo (Jordi Boggiano) * Update postgres_default_version for Ubuntu (Kamil Szymanski) * Allow to set connection for noew role (Kamil Szymanski) * Fix pg_hba_rule for postgres local access (Kamil Szymanski) * Fix versions for travis-ci (Ken Barber) * Add replication support (Jordi Boggiano) * Cleaned up and added unit tests (Ken Barber) * Generalization to provide more flexability in postgresql configuration (Karel Brezina) * Create dependent directory for sudoers so tests work on Centos 5 (Ken Barber) * Allow SQL commands to be run against a specific DB (Carlos Villela) * Drop trailing comma to support Puppet 2.6 (Michael Arnold) 2.1.1 ===== This release provides a bug fix for RHEL 5 and Centos 5 systems, or specifically systems using PostgreSQL 8.1 or older. On those systems one would have received the error: Error: Could not start Service[postgresqld]: Execution of ‘/sbin/service postgresql start’ returned 1: And the postgresql log entry: FATAL: unrecognized configuration parameter "include" This bug is due to a new feature we had added in 2.1.0, whereby the `include` directive in `postgresql.conf` was not compatible. As a work-around we have added checks in our code to make sure systems running PostgreSQL 8.1 or older do not have this directive added. #### Detailed Changes 2013-01-21 - Ken Barber * Only install `include` directive and included file on PostgreSQL >= 8.2 * Add system tests for Centos 5 2.1.0 ===== This release is primarily a feature release, introducing some new helpful constructs to the module. For starters, we've added the line `include 'postgresql_conf_extras.conf'` by default so extra parameters not managed by the module can be added by other tooling or by Puppet itself. This provides a useful escape-hatch for managing settings that are not currently managed by the module today. We've added a new defined resource for managing your tablespace, so you can now create new tablespaces using the syntax: postgresql::tablespace { 'dbspace': location => '/srv/dbspace', } We've added a locale parameter to the `postgresql` class, to provide a default. Also the parameter has been added to the `postgresql::database` and `postgresql::db` defined resources for changing the locale per database: postgresql::db { 'mydatabase': user => 'myuser', password => 'mypassword', encoding => 'UTF8', locale => 'en_NG', } There is a new class for installing the necessary packages to provide the PostgreSQL JDBC client jars: class { 'postgresql::java': } And we have a brand new defined resource for managing fine-grained rule sets within your pg_hba.conf access lists: postgresql::pg_hba { 'Open up postgresql for access from 200.1.2.0/24': type => 'host', database => 'app', user => 'app', address => '200.1.2.0/24', auth_method => 'md5', } Finally, we've also added Travis-CI support and unit tests to help us iterate faster with tests to reduce regression. The current URL for these tests is here: https://travis-ci.org/puppetlabs/puppet-postgresql. Instructions on how to run the unit tests available are provided in the README for the module. A big thanks to all those listed below who made this feature release possible :-). #### Detailed Changes 2013-01-18 - Simão Fontes & Flaper Fesp * Remove trailing commas from params.pp property definition for Puppet 2.6.0 compatibility 2013-01-18 - Lauren Rother * Updated README.md to conform with best practices template 2013-01-09 - Adrien Thebo * Update postgresql_default_version to 9.1 for Debian 7.0 2013-01-28 - Karel Brezina * Add support for tablespaces 2013-01-16 - Chris Price & Karel Brezina * Provide support for an 'include' config file 'postgresql_conf_extras.conf' that users can modify manually or outside of the module. 2013-01-31 - jv * Fix typo in README.pp for postgresql::db example 2013-02-03 - Ken Barber * Add unit tests and travis-ci support 2013-02-02 - Ken Barber * Add locale parameter support to the 'postgresql' class 2013-01-21 - Michael Arnold * Add a class for install the packages containing the PostgreSQL JDBC jar 2013-02-06 - fhrbek * Coding style fixes to reduce warnings in puppet-lint and Geppetto 2013-02-10 - Ken Barber * Provide new defined resource for managing pg_hba.conf 2013-02-11 - Ken Barber * Fix bug with reload of Postgresql on Redhat/Centos 2013-02-15 - Erik Dalén * Fix more style issues to reduce warnings in puppet-lint and Geppetto 2013-02-15 - Erik Dalén * Fix case whereby we were modifying a hash after creation 2.0.1 ===== Minor bugfix release. 2013-01-16 - Chris Price * Fix revoke command in database.pp to support postgres 8.1 (43ded42) 2013-01-15 - Jordi Boggiano * Add support for ubuntu 12.10 status (3504405) 2.0.0 ===== Many thanks to the following people who contributed patches to this release: * Adrien Thebo * Albert Koch * Andreas Ntaflos * Brett Porter * Chris Price * dharwood * Etienne Pelletier * Florin Broasca * Henrik * Hunter Haugen * Jari Bakken * Jordi Boggiano * Ken Barber * nzakaria * Richard Arends * Spenser Gilliland * stormcrow * William Van Hevelingen Notable features: * Add support for versions of postgres other than the system default version (which varies depending on OS distro). This includes optional support for automatically managing the package repo for the "official" postgres yum/apt repos. (Major thanks to Etienne Pelletier and Ken Barber for their tireless efforts and patience on this feature set!) For example usage see `tests/official-postgresql-repos.pp`. * Add some support for Debian Wheezy and Ubuntu Quantal * Add new `postgres_psql` type with a Ruby provider, to replace the old exec-based `psql` type. This gives us much more flexibility around executing SQL statements and controlling their logging / reports output. * Major refactor of the "spec" tests--which are actually more like acceptance tests. We now support testing against multiple OS distros via vagrant, and the framework is in place to allow us to very easily add more distros. Currently testing against Cent6 and Ubuntu 10.04. * Fixed a bug that was preventing multiple databases from being owned by the same user (9adcd182f820101f5e4891b9f2ff6278dfad495c - Etienne Pelletier ) * Add support for ACLs for finer-grained control of user/interface access (b8389d19ad78b4fb66024897097b4ed7db241930 - dharwood ) * Many other bug fixes and improvements! 1.0.0 ===== 2012-09-17 - Version 0.3.0 released 2012-09-14 - Chris Price * Add a type for validating a postgres connection (ce4a049) 2012-08-25 - Jari Bakken * Remove trailing commas. (e6af5e5) 2012-08-16 - Version 0.2.0 released puppetlabs-postgresql-3.2.0/files/000755 000765 000024 00000000000 12236260460 020001 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/Gemfile000644 000765 000024 00000000606 12236260460 020174 0ustar00apenneystaff000000 000000 source 'https://rubygems.org' group :development, :test do gem 'rake' gem 'puppetlabs_spec_helper', :require => false gem 'rspec-system-puppet', '~>2.0' gem 'rspec-system-serverspec', '~>1.0' gem 'puppet-lint', '~> 0.3.2' end if puppetversion = ENV['PUPPET_GEM_VERSION'] gem 'puppet', puppetversion, :require => false else gem 'puppet', :require => false end # vim:ft=ruby puppetlabs-postgresql-3.2.0/Gemfile.lock000644 000765 000024 00000003057 12236260460 021126 0ustar00apenneystaff000000 000000 GEM remote: https://rubygems.org/ specs: builder (3.2.2) diff-lcs (1.2.4) facter (1.7.2) hiera (1.2.1) json_pure highline (1.6.20) json_pure (1.8.0) kwalify (0.7.2) metaclass (0.0.1) mocha (0.14.0) metaclass (~> 0.0.1) net-scp (1.1.2) net-ssh (>= 2.6.5) net-ssh (2.6.8) nokogiri (1.5.10) puppet (3.2.3) facter (~> 1.6) hiera (~> 1.0) rgen (~> 0.6.5) puppet-lint (0.3.2) puppetlabs_spec_helper (0.4.1) mocha (>= 0.10.5) rake rspec (>= 2.9.0) rspec-puppet (>= 0.1.1) rake (10.1.0) rbvmomi (1.6.0) builder nokogiri (>= 1.4.1) trollop rgen (0.6.5) rspec (2.14.1) rspec-core (~> 2.14.0) rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) rspec-core (2.14.5) rspec-expectations (2.14.1) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.14.3) rspec-puppet (0.1.6) rspec rspec-system (2.2.0) kwalify (~> 0.7.2) net-scp (~> 1.1) net-ssh (~> 2.6) nokogiri (~> 1.5.9) rbvmomi (~> 1.6) rspec (~> 2.13) systemu (~> 2.5) rspec-system-puppet (2.1.0) rspec-system (~> 2.0) rspec-system-serverspec (1.0.1) rspec-system (~> 2.0) serverspec (~> 0.0) serverspec (0.10.9) highline net-ssh rspec (>= 2.13.0) systemu (2.5.2) trollop (2.0) PLATFORMS ruby DEPENDENCIES puppet puppet-lint (~> 0.3.2) puppetlabs_spec_helper rake rspec-system-puppet (~> 2.0) rspec-system-serverspec (~> 1.0) puppetlabs-postgresql-3.2.0/lib/000755 000765 000024 00000000000 12236260460 017445 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/LICENSE000644 000765 000024 00000026116 12236260460 017712 0ustar00apenneystaff000000 000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2013 Puppet Labs Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. puppetlabs-postgresql-3.2.0/manifests/000755 000765 000024 00000000000 12236260460 020670 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/metadata.json000644 000765 000024 00000024610 12236260460 021355 0ustar00apenneystaff000000 000000 { "name": "puppetlabs-postgresql", "version": "3.2.0", "source": "git://github.com/puppetlabs/puppet-postgresql.git", "author": "Inkling/Puppet Labs", "license": "ASL 2.0", "summary": "PostgreSQL defined resource types", "description": "PostgreSQL defined resource types", "project_page": "https://github.com/puppetlabs/puppet-postgresql", "dependencies": [ { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }, { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }, { "name": "puppetlabs/apt", "version_requirement": ">=1.1.0 <2.0.0" }, { "name": "puppetlabs/concat", "version_requirement": ">= 1.0.0 <2.0.0" } ], "types": [ { "name": "postgresql_conf", "doc": "This type allows puppet to manage postgresql.conf parameters.", "properties": [ { "name": "ensure", "doc": "The basic property that the resource should be in. Valid values are `present`, `absent`." }, { "name": "value", "doc": "The value to set for this parameter." }, { "name": "target", "doc": "The path to postgresql.conf" } ], "parameters": [ { "name": "name", "doc": "The postgresql parameter name to manage. Values can match `/^[\\w\\.]+$/`." } ], "providers": [ { "name": "parsed", "doc": "Set key/values in postgresql.conf." } ] }, { "name": "postgresql_psql", "doc": "", "properties": [ { "name": "command", "doc": "The SQL command to execute via psql." } ], "parameters": [ { "name": "name", "doc": "An arbitrary tag for your own reference; the name of the message." }, { "name": "unless", "doc": "An optional SQL command to execute prior to the main :command; this is generally intended to be used for idempotency, to check for the existence of an object in the database to determine whether or not the main SQL command needs to be executed at all." }, { "name": "db", "doc": "The name of the database to execute the SQL command against." }, { "name": "search_path", "doc": "The schema search path to use when executing the SQL command" }, { "name": "psql_path", "doc": "The path to psql executable." }, { "name": "psql_user", "doc": "The system user account under which the psql command should be executed." }, { "name": "psql_group", "doc": "The system user group account under which the psql command should be executed." }, { "name": "cwd", "doc": "The working directory under which the psql command should be executed." }, { "name": "refreshonly", "doc": "If 'true', then the SQL will only be executed via a notify/subscribe event. Valid values are `true`, `false`." } ], "providers": [ { "name": "ruby", "doc": "" } ] } ], "checksums": { "Changelog": "3bff00e6b5ac42cd8055ee8d7337c4ff", "Gemfile": "d29b809bd75c2aa7c160e45e66483d8c", "Gemfile.lock": "9c04244f3ad5b505c9f36daf40a5677f", "LICENSE": "746fe83ebbf8970af0a9ea13962293e9", "Modulefile": "6a824d502980df77edf9d414b5e3e2f2", "NOTICE": "d8ffc52f00e00877b45d2b77e709f69e", "README.md": "049d45d3aa128c29e16e9a0dcf67517f", "Rakefile": "7e458ced5c7b798430ee6371f860057e", "files/RPM-GPG-KEY-PGDG": "78b5db170d33f80ad5a47863a7476b22", "files/validate_postgresql_connection.sh": "20301932819f035492a30880f5bf335a", "lib/puppet/parser/functions/postgresql_acls_to_resources_hash.rb": "d518a7959b950874820a3b0a7a324488", "lib/puppet/parser/functions/postgresql_escape.rb": "2e136fcd653ab38d831c5b40806d47d1", "lib/puppet/parser/functions/postgresql_password.rb": "820da02a888ab42357fe9bc2352b1c37", "lib/puppet/provider/postgresql_conf/parsed.rb": "9c198422c0558faab1bedc00b68cfe45", "lib/puppet/provider/postgresql_psql/ruby.rb": "506a07dc159de91fe212133103b9dcff", "lib/puppet/type/postgresql_conf.rb": "4f333138a3689f9768e7fe4bc3cde9fd", "lib/puppet/type/postgresql_psql.rb": "2c1270cfed4ffb2971059846a57cf983", "manifests/client.pp": "f9bc3a578017fe8eb881de2255bdc023", "manifests/globals.pp": "64d9cdb6894ba6334992e9365a1e2096", "manifests/lib/devel.pp": "94ae7eac3acf1dd3072d481eca4d2d7f", "manifests/lib/java.pp": "6e4a2187c2b4caecad8098b46e99c8e0", "manifests/lib/python.pp": "90736f86301c4c6401ec1180c176b616", "manifests/params.pp": "109138ba7df4ad7da71b302a20f33b29", "manifests/repo/apt_postgresql_org.pp": "ef7012ea3c5429bea11b1114183d32c3", "manifests/repo/yum_postgresql_org.pp": "e0c445f877cdb39774b735417c967d1d", "manifests/repo.pp": "a18a5cb760dbb1e10bdd83730300c1fe", "manifests/server/config.pp": "a05f4aeb3f09b2e5e9ee8b9467519afb", "manifests/server/config_entry.pp": "a3823efa15fe96535335bd7b722fef9a", "manifests/server/contrib.pp": "3112bd1edbed51b68e1402027f9d53b1", "manifests/server/database.pp": "ebf356e8cadf5bef884e5597fd60724e", "manifests/server/database_grant.pp": "66e5470bb932b087b540c444ee49941b", "manifests/server/db.pp": "f35e4974ffee6136e2de1a3edc9cbf21", "manifests/server/firewall.pp": "98632b073511a00926908c6951851052", "manifests/server/grant.pp": "81c8d6b64a6b938fe57346ede5cdfeb7", "manifests/server/initdb.pp": "91e27eaf448817c0f904e5267816a16a", "manifests/server/install.pp": "8520e3a86c74e0587a46c4548097bab3", "manifests/server/passwd.pp": "96214f099cfb97d361f9bdc0734baf38", "manifests/server/pg_hba_rule.pp": "01a1bf9503f908531af9990909d8ba45", "manifests/server/plperl.pp": "d6a2e2f0c93c7b543e9db64202c2e48d", "manifests/server/reload.pp": "d62c048c8f25c167d266e99e36c0f227", "manifests/server/role.pp": "43eeda8b6a40b587d688e2ce33c4e780", "manifests/server/service.pp": "e1896d429a032c4522201e9048d204db", "manifests/server/table_grant.pp": "bbc864f0ad8545837cf7782d1f7a1755", "manifests/server/tablespace.pp": "beda12859757f7f677a711304dfd5185", "manifests/server.pp": "d147bf997967eeb428c6e681dbe89d67", "manifests/validate_db_connection.pp": "be61434836f7d25cc184126a91b2e3e6", "spec/spec_helper.rb": "d4e4a9a154ada34e7f13b0d8ece0f5db", "spec/spec_helper_system.rb": "ecedca722f54627ef2c5f8a0da5f2163", "spec/system/client_spec.rb": "b477056c567ecc479a3bbc6e283df7ba", "spec/system/common_patterns_spec.rb": "696033dd862db23f45e86b2099e47810", "spec/system/contrib_spec.rb": "326208830a51cf74841bae361709863a", "spec/system/lib/devel_spec.rb": "5e69579d3e2e4f854640e3afb1122162", "spec/system/lib/java_spec.rb": "e88f705ae328f8a830ae027fca35a474", "spec/system/lib/python_spec.rb": "2690f7530f806fa52cbedbb2c86988e6", "spec/system/postgresql_psql_spec.rb": "6dd5c8ec1e0f493143fa2b89b044ee3d", "spec/system/server/config_entry_spec.rb": "0a8a3c42efad84ab7aca367b8c3e8160", "spec/system/server/database_grant_spec.rb": "f5736d6ac16ad1d2ed5f9f3442e3dda4", "spec/system/server/database_spec.rb": "5405572c72b39d72d7975da02eef8569", "spec/system/server/db_spec.rb": "5a6fcf61718af48e2b1fb79ba040da93", "spec/system/server/grant_spec.rb": "fc629944a71faa1d871f3d3a7e4e4a83", "spec/system/server/pg_hba_rule_spec.rb": "ff0c8c772ed60f8667dd2531029830b9", "spec/system/server/plperl_spec.rb": "cd54753b2c8d5e4aaad13daeb8b61e7a", "spec/system/server/role_spec.rb": "5b566002ba577f737d4e2a7b3fccb221", "spec/system/server/table_grant_spec.rb": "260490ebb6c8b9b9f73551fb4eca8ea5", "spec/system/server/tablespace_spec.rb": "48fed176f821c77d24366d70e9d15ff2", "spec/system/server_spec.rb": "e93f4a14e5916eac7961e8d5215e16e2", "spec/system/validate_db_connection_spec.rb": "1a454b555c6f0539d7e6e47e177a68cf", "spec/unit/classes/client_spec.rb": "b26438da8906e68d17e568252c1e43b5", "spec/unit/classes/globals_spec.rb": "952cba1463ca000e288cbfd56ec8c771", "spec/unit/classes/lib/devel_spec.rb": "f660eb0afe4fa75e999ab192e39b58d8", "spec/unit/classes/lib/java_spec.rb": "bdb60c3b379a3788b3bf1f6c29b31c0a", "spec/unit/classes/lib/python_spec.rb": "677c763c1a43a0e33ef7e6e819ec9f0a", "spec/unit/classes/params_spec.rb": "2661b999fc13cd3368b54549f3267be0", "spec/unit/classes/repo_spec.rb": "a24b152315c86146881b6a39a7a22cd0", "spec/unit/classes/server/contrib_spec.rb": "16528171ee3e058c06c5fea454dc9dbc", "spec/unit/classes/server/initdb_spec.rb": "7f17f9cc6091c9e9ff789dc2f1653bff", "spec/unit/classes/server/plperl_spec.rb": "120e0280679b21b4348dd992f39f83b3", "spec/unit/classes/server_spec.rb": "244a793964c16cb3f4d819998e8f07a4", "spec/unit/defines/server/config_entry_spec.rb": "cc2d9d0e4508d745f85c3446ccf76eb4", "spec/unit/defines/server/database_grant_spec.rb": "e09254037c042efa5a29ba8d777c882f", "spec/unit/defines/server/database_spec.rb": "090e9cf334843a4dc8b3f4eadce0109b", "spec/unit/defines/server/db_spec.rb": "9f2181b0df771f4c6adf089b788adf42", "spec/unit/defines/server/grant_spec.rb": "b8d8f46c7c4539747ee0b797a3a1834f", "spec/unit/defines/server/pg_hba_rule_spec.rb": "3ed69d689bf28b56a030c543e7ce6775", "spec/unit/defines/server/role_spec.rb": "fdb53fa637ccd79f8231e15383099137", "spec/unit/defines/server/table_grant_spec.rb": "bb794a0b15dc74e8c8fa5d4878fd3c79", "spec/unit/defines/server/tablespace_spec.rb": "68e7b9a193475491c58485debf1be220", "spec/unit/defines/validate_db_connection_spec.rb": "88e57a8f780d381d75fe062f1178e1ce", "spec/unit/functions/postgresql_acls_to_resources_hash_spec.rb": "e7740c3cd2110e2fcebab8356012267c", "spec/unit/functions/postgresql_escape_spec.rb": "6e52e4f3ca56491f8ba2d1490a5fd1ad", "spec/unit/functions/postgresql_password_spec.rb": "76034569a5ff627073c5e6ff69176ac3", "spec/unit/provider/postgresql_conf/parsed_spec.rb": "7295501a413d8cf99df6f40ea50a36fc", "spec/unit/puppet/provider/postgresql_psql/ruby_spec.rb": "deef7a3f574269889e7d050a55e847f4", "spec/unit/puppet/type/postgresql_psql_spec.rb": "2af5b74f7f4b89ff246818cd79488b3e", "spec/unit/type/postgresql_conf_spec.rb": "76f460e0dfc90a1f38c407e5a0d4f463", "templates/pg_hba_rule.conf": "13b46eecdfd359eddff71fa485ef2f54" } }puppetlabs-postgresql-3.2.0/Modulefile000644 000765 000024 00000000761 12236260460 020713 0ustar00apenneystaff000000 000000 name 'puppetlabs-postgresql' version '3.2.0' source 'git://github.com/puppetlabs/puppet-postgresql.git' author 'Inkling/Puppet Labs' description 'PostgreSQL defined resource types' summary 'PostgreSQL defined resource types' license 'ASL 2.0' project_page 'https://github.com/puppetlabs/puppet-postgresql' dependency 'puppetlabs/stdlib', '>=3.2.0 <5.0.0' dependency 'puppetlabs/firewall', '>= 0.0.4' dependency 'puppetlabs/apt', '>=1.1.0 <2.0.0' dependency 'puppetlabs/concat', '>= 1.0.0 <2.0.0' puppetlabs-postgresql-3.2.0/NOTICE000644 000765 000024 00000000656 12236260460 017612 0ustar00apenneystaff000000 000000 Puppetlabs postgresql module Copyright 2012 Inkling Systems Inc Copyright 2012-2013 Puppet Labs Inc Copyright 2012-2013 Camptocamp SA. This product includes software developed by: The Puppet Labs Inc (http://www.puppetlabs.com/). This product includes also software developed by: Camptocamp SA (http://www.camptocamp.com/) This product includes also software developed by: Inkling Systems Inc (https://www.inkling.com/) puppetlabs-postgresql-3.2.0/Rakefile000644 000765 000024 00000000341 12236260460 020342 0ustar00apenneystaff000000 000000 require 'rubygems' require 'bundler/setup' Bundler.require :default require 'puppetlabs_spec_helper/rake_tasks' require 'rspec-system/rake_task' require 'puppet-lint/tasks/puppet-lint' task :default do sh %{rake -T} end puppetlabs-postgresql-3.2.0/README.md000644 000765 000024 00000115453 12236260460 020167 0ustar00apenneystaff000000 000000 postgresql ========== Table of Contents ----------------- 1. [Overview - What is the PostgreSQL module?](#overview) 2. [Module Description - What does the module do?](#module-description) 3. [Setup - The basics of getting started with PostgreSQL module](#setup) 4. [Usage - How to use the module for various tasks](#usage) 5. [Upgrading - Guide for upgrading from older revisions of this module](#upgrading) 6. [Reference - The classes, defines,functions and facts available in this module](#reference) 7. [Limitations - OS compatibility, etc.](#limitations) 8. [Development - Guide for contributing to the module](#development) 9. [Disclaimer - Licensing information](#disclaimer) 10. [Transfer Notice - Notice of authorship change](#transfer-notice) 11. [Contributors - List of module contributors](#contributors) Overview -------- The PostgreSQL module allows you to easily manage postgres databases with Puppet. Module Description ------------------- PostgreSQL is a high-performance, free, open-source relational database server. The postgresql module allows you to manage PostgreSQL packages and services on several operating systems, while also supporting basic management of PostgreSQL databases and users. The module offers support for managing firewall for postgres ports on RedHat-based distros, as well as support for basic management of common security settings. Setup ----- **What puppetlabs-PostgreSQL affects:** * package/service/configuration files for PostgreSQL * listened-to ports * system firewall (optional) * IP and mask (optional) **Introductory Questions** The postgresql module offers many security configuration settings. Before getting started, you will want to consider: * Do you want/need to allow remote connections? * If yes, what about TCP connections? * Would you prefer to work around your current firewall settings or overwrite some of them? * How restrictive do you want the database superuser's permissions to be? Your answers to these questions will determine which of the module's parameters you'll want to specify values for. ###Configuring the server The main configuration you'll need to do will be around the `postgresql::server` class. The default parameters are reasonable, but fairly restrictive regarding permissions for who can connect and from where. To manage a PostgreSQL server with sane defaults: class { 'postgresql::server': } For a more customized configuration: class { 'postgresql::server': ip_mask_deny_postgres_user => '0.0.0.0/32', ip_mask_allow_all_users => '0.0.0.0/0', listen_addresses => '*', ipv4acls => ['hostssl all johndoe 192.168.0.0/24 cert'], manage_firewall => true, postgres_password => 'TPSrep0rt!', } Once you've completed your configuration of `postgresql::server`, you can test out your settings from the command line: $ psql -h localhost -U postgres $ psql -h my.postgres.server -U If you get an error message from these commands, it means that your permissions are set in a way that restricts access from where you're trying to connect. That might be a good thing or a bad thing, depending on your goals. For more details about server configuration parameters consult the [PostgreSQL Runtime Configuration docs](http://www.postgresql.org/docs/9.2/static/runtime-config.html). Usage ----- ###Creating a database There are many ways to set up a postgres database using the `postgresql::server::db` class. For instance, to set up a database for PuppetDB: class { 'postgresql::server': } postgresql::server::db { 'mydatabasename': user => 'mydatabaseuser', password => postgresql_password('mydatabaseuser', 'mypassword'), } ###Managing users, roles and permissions To manage users, roles and permissions: class { 'postgresql::server': } postgresql::server::role { 'marmot': password_hash => postgresql_password('marmot', 'mypasswd'), } postgresql::server::database_grant { 'test1': privilege => 'ALL', db => 'test1', role => 'marmot', } postgresql::server::table_grant { 'my_table of test2': privilege => 'ALL', table => 'my_table', db => 'test2', role => 'marmot', } In this example, you would grant ALL privileges on the test1 database and on the `my_table` table of the test2 database to the user or group specified by dan. At this point, you would just need to plunk these database name/username/password values into your PuppetDB config files, and you are good to go. Upgrading --------- ###Upgrading from 2.x to version 3 *Note:* if you are upgrading for 2.x, you *must* read this, as just about everything has changed. Version 3 was a major rewrite to fix some internal dependency issues, and to make the new Public API more clear. As a consequence a lot of things have changed for version 3 and older revisions that we will try to outline here. ####Server specific objects now moved under `postgresql::server::` namespace To restructure server specific elements under the `postgresql::server::` namespaces the following objects were renamed as such: * `postgresql::database` -> `postgresql::server::database` * `postgresql::database_grant` -> `postgresql::server::database_grant` * `postgresql::db` -> `postgresql::server::db` * `postgresql::grant` -> `postgresql::server::grant` * `postgresql::pg_hba_rule` -> `postgresql::server::pg_hba_rule` * `postgresql::plperl` -> `postgresql::server::plperl` * `postgresql::contrib` -> `postgresql::server::contrib` * `postgresql::role` -> `postgresql::server::role` * `postgresql::table_grant` -> `postgresql::server::table_grant` * `postgresql::tablespace` -> `postgresql::server::tablespace` ####New `postgresql::server::config_entry` resource for managing configuration Previously we used the `file_line` resource to modify `postgresql.conf`. This new revision now adds a new resource named `postgresql::server::config_entry` for managing this file. For example: postgresql::server::config_entry { 'check_function_bodies': value => 'off', } If you were using `file_line` for this purpose, you should change to this new methodology. ####`postgresql_puppet_extras.conf` has been removed Now that we have a methodology for managing `postgresql.conf`, and due to concerns over the file management methodology using an `exec { 'touch ...': }` as a way to create an empty file the existing postgresql\_puppet\_extras.conf file is no longer managed by this module. If you wish to recreate this methodology yourself, use this pattern: class { 'postgresql::server': } $extras = "/tmp/include.conf" file { $extras: content => 'max_connections = 123', notify => Class['postgresql::server::service'], }-> postgresql::server::config_entry { 'include': value => $extras, } ####All uses of the parameter `charset` changed to `encoding` Since PostgreSQL uses the terminology `encoding` not `charset` the parameter has been made consisent across all classes and resources. ####The `postgresql` base class is no longer how you set globals The old global override pattern was less then optimal so it has been fixed, however we decided to demark this properly by specifying these overrides in the class `postgresql::globals`. Consult the documentation for this class now to see what options are available. Also, some parameter elements have been moved between this and the `postgresql::server` class where it made sense. ####`config_hash` parameter collapsed for the `postgresql::server` class Because the `config_hash` was really passing data through to what was in effect an internal class (`postgresql::config`). And since we don't want this kind of internal exposure the parameters were collapsed up into the `postgresql::server` class directly. ####Lots of changes to 'private' or 'undocumented' classes If you were using these before, these have changed names. You should only use what is documented in this README.md, and if you don't have what you need you should raise a patch to add that feature to a public API. All internal classes now have a comment at the top indicating them as private to make sure the message is clear that they are not supported as Public API. ####`pg_hba_conf_defaults` parameter included to turn off default pg\_hba rules The defaults should be good enough for most cases (if not raise a bug) but if you simply need an escape hatch, this setting will turn off the defaults. If you want to do this, it may affect the rest of the module so make sure you replace the rules with something that continues operation. ####`postgresql::database_user` has now been removed Use `postgresql::server::role` instead. ####`postgresql::psql` resource has now been removed Use `postgresql_psql` instead. In the future we may recreate this as a wrapper to add extra capability, but it will not match the old behaviour. ####`postgresql_default_version` fact has now been removed It didn't make sense to have this logic in a fact any more, the logic has been moved into `postgresql::params`. ####`ripienaar/concat` is no longer used, instead we use `puppetlabs/concat` The older concat module is now deprecated and moved into the `puppetlabs/concat` namespace. Functionality is more or less identical, but you may need to intervene during the installing of this package - as both use the same `concat` namespace. Reference --------- The postgresql module comes with many options for configuring the server. While you are unlikely to use all of the below settings, they allow you a decent amount of control over your security settings. Classes: * [postgresql::client](#class-postgresqlclient) * [postgresql::globals](#class-postgresqlglobals) * [postgresql::lib::devel](#class-postgresqllibdevel) * [postgresql::lib::java](#class-postgresqllibjava) * [postgresql::lib::python](#class-postgresqllibpython) * [postgresql::server](#class-postgresqlserver) * [postgresql::server::plperl](#class-postgresqlserverplperl) * [postgresql::server::contrib](#class-postgresqlservercontrib) Resources: * [postgresql::server::config_entry](#resource-postgresqlserverconfigentry) * [postgresql::server::db](#resource-postgresqlserverdb) * [postgresql::server::database](#resource-postgresqlserverdatabase) * [postgresql::server::database_grant](#resource-postgresqlserverdatabasegrant) * [postgresql::server::pg_hba_rule](#resource-postgresqlserverpghbarule) * [postgresql::server::role](#resource-postgresqlserverrole) * [postgresql::server::table_grant](#resource-postgresqlservertablegrant) * [postgresql::server::tablespace](#resource-postgresqlservertablespace) * [postgresql::validate_db_connection](#resource-postgresqlvalidatedbconnection) Functions: * [postgresql\_password](#function-postgresqlpassword) * [postgresql\_acls\_to\_resources\_hash](#function-postgresqlaclstoresourceshashaclarray-id-orderoffset) ###Class: postgresql::globals *Note:* most server specific defaults should be overriden in the `postgresql::server` class. This class should only be used if you are using a non-standard OS or if you are changing elements such as `version` or `manage_package_repo` that can only be changed here. This class allows you to configure the main settings for this module in a global way, to be used by the other classes and defined resources. On its own it does nothing. For example, if you wanted to overwrite the default `locale` and `encoding` for all classes you could use the following combination: class { 'postgresql::globals': encoding => 'UTF8', locale => 'en_NG', }-> class { 'postgresql::server': } That would make the `encoding` and `locale` the default for all classes and defined resources in this module. If you want to use the upstream PostgreSQL packaging, and be specific about the version you wish to download, you could use something like this: class { 'postgresql::globals': manage_package_repo => true, version => '9.2', }-> class { 'postgresql::server': } ####`client_package_name` This setting can be used to override the default postgresql client package name. If not specified, the module will use whatever package name is the default for your OS distro. ####`server_package_name` This setting can be used to override the default postgresql server package name. If not specified, the module will use whatever package name is the default for your OS distro. ####`contrib_package_name` This setting can be used to override the default postgresql contrib package name. If not specified, the module will use whatever package name is the default for your OS distro. ####`devel_package_name` This setting can be used to override the default postgresql devel package name. If not specified, the module will use whatever package name is the default for your OS distro. ####`java_package_name` This setting can be used to override the default postgresql java package name. If not specified, the module will use whatever package name is the default for your OS distro. ####`plperl_package_name` This setting can be used to override the default postgresql PL/perl package name. If not specified, the module will use whatever package name is the default for your OS distro. ####`python_package_name` This setting can be used to override the default postgresql Python package name. If not specified, the module will use whatever package name is the default for your OS distro. ####`service_name` This setting can be used to override the default postgresql service provider. If not specified, the module will use whatever service name is the default for your OS distro. ####`service_status` This setting can be used to override the default status check command for your PostgreSQL service. If not specified, the module will use whatever service name is the default for your OS distro. ####`default_database` This setting is used to specify the name of the default database to connect with. On most systems this will be "postgres". ####`initdb_path` Path to the `initdb` command. ####`createdb_path` Path to the `createdb` command. ####`psql_path` Path to the `psql` command. ####`pg_hba_conf_path` Path to your `pg\_hba.conf` file. ####`postgresql_conf_path` Path to your `postgresql.conf` file. ####`pg_hba_conf_defaults` If false, disables the defaults supplied with the module for `pg\_hba.conf`. This is useful if you disagree with the defaults and wish to override them yourself. Be sure that your changes of course align with the rest of the module, as some access is required to perform basic `psql` operations for example. ####`datadir` This setting can be used to override the default postgresql data directory for the target platform. If not specified, the module will use whatever directory is the default for your OS distro. ####`confdir` This setting can be used to override the default postgresql configuration directory for the target platform. If not specified, the module will use whatever directory is the default for your OS distro. ####`bindir` This setting can be used to override the default postgresql binaries directory for the target platform. If not specified, the module will use whatever directory is the default for your OS distro. ####`user` This setting can be used to override the default postgresql super user and owner of postgresql related files in the file system. If not specified, the module will use the user name 'postgres'. ####`group` This setting can be used to override the default postgresql user group to be used for related files in the file system. If not specified, the module will use the group name 'postgres'. ####`version` The version of PostgreSQL to install/manage. This is a simple way of providing a specific version such as '9.2' or '8.4' for example. Defaults to your operating system default. ####`needs_initdb` This setting can be used to explicitly call the initdb operation after server package is installed and before the postgresql service is started. If not specified, the module will decide whether to call initdb or not depending on your OS distro. ####`encoding` This will set the default encoding encoding for all databases created with this module. On certain operating systems this will be used during the `template1` initialization as well so it becomes a default outside of the module as well. Defaults to the operating system default. ####`locale` This will set the default database locale for all databases created with this module. On certain operating systems this will be used during the `template1` initialization as well so it becomes a default outside of the module as well. Defaults to `undef` which is effectively `C`. ####`firewall_supported` This allows you to override the automated detection to see if your OS supports the `firewall` module. ####`manage_package_repo` If `true` this will setup the official PostgreSQL repositories on your host. Defaults to `false`. ###Class: postgresql::server The following list are options that you can set in the `config_hash` parameter of `postgresql::server`. ####`ensure` This value default to `present`. When set to `absent` it will remove all packages, configuration and data so use this with extreme caution. ####`version` This will set the version of the PostgreSQL software to install. Defaults to your operating systems default. ####`postgres_password` This value defaults to `undef`, meaning the super user account in the postgres database is a user called `postgres` and this account does not have a password. If you provide this setting, the module will set the password for the `postgres` user to your specified value. ####`package_name` The name of the package to use for installing the server software. Defaults to the default for your OS distro. ####`package_ensure` Value to pass through to the `package` resource when creating the server instance. Defaults to `undef`. ####`plperl_package_name` This sets the default package name for the PL/Perl extension. Defaults to utilising the operating system default. ####`service_name` This setting can be used to override the default postgresql service name. If not specified, the module will use whatever service name is the default for your OS distro. ####`service_name` This setting can be used to override the default postgresql service provider. If not specified, the module will use whatever service name is the default for your OS distro. ####`service_status` This setting can be used to override the default status check command for your PostgreSQL service. If not specified, the module will use whatever service name is the default for your OS distro. ####`default_database` This setting is used to specify the name of the default database to connect with. On most systems this will be "postgres". ####`listen_addresses` This value defaults to `localhost`, meaning the postgres server will only accept connections from localhost. If you'd like to be able to connect to postgres from remote machines, you can override this setting. A value of `*` will tell postgres to accept connections from any remote machine. Alternately, you can specify a comma-separated list of hostnames or IP addresses. (For more info, have a look at the `postgresql.conf` file from your system's postgres package). ####`ip_mask_deny_postgres_user` This value defaults to `0.0.0.0/0`. Sometimes it can be useful to block the superuser account from remote connections if you are allowing other database users to connect remotely. Set this to an IP and mask for which you want to deny connections by the postgres superuser account. So, e.g., the default value of `0.0.0.0/0` will match any remote IP and deny access, so the postgres user won't be able to connect remotely at all. Conversely, a value of `0.0.0.0/32` would not match any remote IP, and thus the deny rule will not be applied and the postgres user will be allowed to connect. ####`ip_mask_allow_all_users` This value defaults to `127.0.0.1/32`. By default, Postgres does not allow any database user accounts to connect via TCP from remote machines. If you'd like to allow them to, you can override this setting. You might set it to `0.0.0.0/0` to allow database users to connect from any remote machine, or `192.168.0.0/16` to allow connections from any machine on your local 192.168 subnet. ####`ipv4acls` List of strings for access control for connection method, users, databases, IPv4 addresses; see [postgresql documentation](http://www.postgresql.org/docs/9.2/static/auth-pg-hba-conf.html) about `pg_hba.conf` for information (please note that the link will take you to documentation for the most recent version of Postgres, however links for earlier versions can be found on that page). ####`ipv6acls` List of strings for access control for connection method, users, databases, IPv6 addresses; see [postgresql documentation](http://www.postgresql.org/docs/9.2/static/auth-pg-hba-conf.html) about `pg_hba.conf` for information (please note that the link will take you to documentation for the most recent version of Postgres, however links for earlier versions can be found on that page). ####`inidb_path` Path to the `initdb` command. ####`createdb_path` Path to the `createdb` command. ####`psql_path` Path to the `psql` command. ####`pg_hba_conf_path` Path to your `pg\_hba.conf` file. ####`postgresql_conf_path` Path to your `postgresql.conf` file. ####`pg_hba_conf_defaults` If false, disables the defaults supplied with the module for `pg\_hba.conf`. This is useful if you di sagree with the defaults and wish to override them yourself. Be sure that your changes of course alig n with the rest of the module, as some access is required to perform basic `psql` operations for exam ple. ####`user` This setting can be used to override the default postgresql super user and owner of postgresql related files in the file system. If not specified, the module will use the user name 'postgres'. ####`group` This setting can be used to override the default postgresql user group to be used for related files in the file system. If not specified, the module will use the group name 'postgres'. ####`needs_initdb` This setting can be used to explicitly call the initdb operation after server package is installed and before the postgresql service is started. If not specified, the module will decide whether to call initdb or not depending on your OS distro. ####`encoding` This will set the default encoding encoding for all databases created with this module. On certain operating systems this will be used during the `template1` initialization as well so it becomes a default outside of the module as well. Defaults to the operating system default. ####`locale` This will set the default database locale for all databases created with this module. On certain operating systems this will be used during the `template1` initialization as well so it becomes a default outside of the module as well. Defaults to `undef` which is effectively `C`. ####`manage_firewall` This value defaults to `false`. Many distros ship with a fairly restrictive firewall configuration which will block the port that postgres tries to listen on. If you'd like for the puppet module to open this port for you (using the [puppetlabs-firewall](http://forge.puppetlabs.com/puppetlabs/firewall) module), change this value to true. Check the documentation for `puppetlabs/firewall` to ensure the rest of the global setup is applied, to ensure things like persistence and global rules are set correctly. ####`manage_pg_hba_conf` This value defaults to `true`. Whether or not manage the pg_hba.conf. If set to `true`, puppet will overwrite this file. If set to `false`, puppet will not modify the file. ###Class: postgresql::client This class installs postgresql client software. Alter the following parameters if you have a custom version you would like to install (Note: don't forget to make sure to add any necessary yum or apt repositories if specifying a custom version): ####`package_name` The name of the postgresql client package. ####`package_ensure` The ensure parameter passed on to postgresql client package resource. ###Class: postgresql::server::contrib Installs the postgresql contrib package. ####`package_name` The name of the postgresql client package. ####`package_ensure` The ensure parameter passed on to postgresql contrib package resource. ###Class: postgresql::lib::devel Installs the packages containing the development libraries for PostgreSQL. ####`package_ensure` Override for the `ensure` parameter during package installation. Defaults to `present`. ####`package_name` Overrides the default package name for the distribution you are installing to. Defaults to `postgresql-devel` or `postgresql-devel` depending on your distro. ###Class: postgresql::lib::java This class installs postgresql bindings for Java (JDBC). Alter the following parameters if you have a custom version you would like to install (Note: don't forget to make sure to add any necessary yum or apt repositories if specifying a custom version): ####`package_name` The name of the postgresql java package. ####`package_ensure` The ensure parameter passed on to postgresql java package resource. ###Class: postgresql::lib::python This class installs the postgresql Python libraries. For customer requirements you can customise the following parameters: ####`package_name` The name of the postgresql python package. ####`package_ensure` The ensure parameter passed on to postgresql python package resource. ###Class: postgresql::server::plperl This class installs the PL/Perl procedural language for postgresql. ####`package_name` The name of the postgresql PL/Perl package. ####`package_ensure` The ensure parameter passed on to postgresql PL/Perl package resource. ###Resource: postgresql::server::config\_entry This resource can be used to modify your `postgresql.conf` configuration file. Each resource maps to a line inside your `postgresql.conf` file, for example: postgresql::server::config_entry { 'check_function_bodies': value => 'off', } ####`namevar` Name of the setting to change. ####`ensure` Set to `absent` to remove an entry. ####`value` Value for the setting. ###Resource: postgresql::server::db This is a convenience resource that creates a database, user and assigns necessary permissions in one go. For example, to create a database called `test1` with a corresponding user of the same name, you can use: postgresql::server::db { 'test1': user => 'test1', password => 'test1', } ####`namevar` The namevar for the resource designates the name of the database. ####`user` User to create and assign access to the database upon creation. Mandatory. ####`password` Password for the created user. Mandatory. ####`encoding` Override the character set during creation of the database. Defaults to the default defined during installation. ####`locale` Override the locale during creation of the database. Defaults to the default defined during installation. ####`grant` Grant permissions during creation. Defaults to `ALL`. ####`tablespace` The name of the tablespace to allocate this database to. If not specifies, it defaults to the PostgreSQL default. ####`istemplate` Define database as a template. Defaults to `false`. ###Resource: postgresql::server::database This defined type can be used to create a database with no users and no permissions, which is a rare use case. ####`namevar` The name of the database to create. ####`dbname` The name of the database, defaults to the namevar. ####`owner` Name of the database user who should be set as the owner of the database. Defaults to the $user variable set in `postgresql::server` or `postgresql::globals`. ####`tablespace` Tablespace for where to create this database. Defaults to the defaults defined during PostgreSQL installation. ####`encoding` Override the character set during creation of the database. Defaults to the default defined during installation. ####`locale` Override the locale during creation of the database. Defaults to the default defined during installation. ####`istemplate` Define database as a template. Defaults to `false`. ###Resource: postgresql::server::database\_grant This defined type manages grant based access privileges for users, wrapping the `postgresql::server::database_grant` for database specific permissions. Consult the PostgreSQL documentation for `grant` for more information. ####`namevar` Used to uniquely identify this resource, but functionality not used during grant. ####`privilege` Can be one of `SELECT`, `TEMPORARY`, `TEMP`, `CONNECT`. `ALL` is used as a synonym for `CREATE`. If you need to add multiple privileges, a space delimited string can be used. ####`db` Database to grant access to. ####`role` Role or user whom you are granting access for. ####`psql_db` Database to execute the grant against. This should not ordinarily be changed from the default, which is `postgres`. ####`psql_user` OS user for running `psql`. Defaults to the default user for the module, usually `postgres`. ###Resource: postgresql::server::pg\_hba\_rule This defined type allows you to create an access rule for `pg_hba.conf`. For more details see the [PostgreSQL documentation](http://www.postgresql.org/docs/8.2/static/auth-pg-hba-conf.html). For example: postgresql::server::pg_hba_rule { 'allow application network to access app database': description => "Open up postgresql for access from 200.1.2.0/24", type => 'host', database => 'app', user => 'app', address => '200.1.2.0/24', auth_method => 'md5', } This would create a ruleset in `pg_hba.conf` similar to: # Rule Name: allow application network to access app database # Description: Open up postgresql for access from 200.1.2.0/24 # Order: 150 host app app 200.1.2.0/24 md5 ####`namevar` A unique identifier or short description for this rule. The namevar doesn't provide any functional usage, but it is stored in the comments of the produced `pg_hba.conf` so the originating resource can be identified. ####`description` A longer description for this rule if required. Defaults to `none`. This description is placed in the comments above the rule in `pg_hba.conf`. ####`type` The type of rule, this is usually one of: `local`, `host`, `hostssl` or `hostnossl`. ####`database` A comma separated list of databases that this rule matches. ####`user` A comma separated list of database users that this rule matches. ####`address` If the type is not 'local' you can provide a CIDR based address here for rule matching. ####`auth_method` The `auth_method` is described further in the `pg_hba.conf` documentation, but it provides the method that is used for authentication for the connection that this rule matches. ####`auth_option` For certain `auth_method` settings there are extra options that can be passed. Consult the PostgreSQL `pg_hba.conf` documentation for further details. ####`order` An order for placing the rule in `pg_hba.conf`. Defaults to `150`. ####`target` This provides the target for the rule, and is generally an internal only property. Use with caution. ###Resource: postgresql::server::role This resource creates a role or user in PostgreSQL. ####`namevar` The role name to create. ####`password_hash` The hash to use during password creation. If the password is not already pre-encrypted in a format that PostgreSQL supports, use the `postgresql_password` function to provide an MD5 hash here, for example: postgresql::role { "myusername": password_hash => postgresql_password('myusername', 'mypassword'), } ####`createdb` Whether to grant the ability to create new databases with this role. Defaults to `false`. ####`createrole` Whether to grant the ability to create new roles with this role. Defaults to `false`. ####`login` Whether to grant login capability for the new role. Defaults to `false`. ####`superuser` Whether to grant super user capability for the new role. Defaults to `false`. ####`replication` If `true` provides replication capabilities for this role. Defaults to `false`. ####`connection_limit` Specifies how many concurrent connections the role can make. Defaults to `-1` meaning no limit. ####`username` The username of the role to create, defaults to `namevar`. ###Resource: postgresql::server::table\_grant This defined type manages grant based access privileges for users. Consult the PostgreSQL documentation for `grant` for more information. ####`namevar` Used to uniquely identify this resource, but functionality not used during grant. ####`privilege` Can be one of `SELECT`, `INSERT`, `UPDATE`, `REFERENCES`. `ALL` is used as a synonym for `CREATE`. If you need to add multiple privileges, a space delimited string can be used. ####`table` Table to grant access on. ####`db` Database of table. ####`role` Role or user whom you are granting access for. ####`psql_db` Database to execute the grant against. This should not ordinarily be changed from the default, which is `postgres`. ####`psql_user` OS user for running `psql`. Defaults to the default user for the module, usually `postgres`. ###Resource: postgresql::server::tablespace This defined type can be used to create a tablespace. For example: postgresql::tablespace { 'tablespace1': location => '/srv/space1', } It will create the location if necessary, assigning it the same permissions as your PostgreSQL server. ####`namevar` The tablespace name to create. ####`location` The path to locate this tablespace. ####`owner` The default owner of the tablespace. ####`spcname` Name of the tablespace. Defaults to `namevar`. ###Resource: postgresql::validate\_db\_connection This resource can be utilised inside composite manifests to validate that a client has a valid connection with a remote PostgreSQL database. It can be ran from any node where the PostgreSQL client software is installed to validate connectivity before commencing other dependent tasks in your Puppet manifests, so it is often used when chained to other tasks such as: starting an application server, performing a database migration. Example usage: postgresql::validate_db_connection { 'validate my postgres connection': database_host => 'my.postgres.host', database_username => 'mydbuser', database_password => 'mydbpassword', database_name => 'mydbname', }-> exec { 'rake db:migrate': cwd => '/opt/myrubyapp', } ####`namevar` Uniquely identify this resource, but functionally does nothing. ####`database_host` The hostname of the database you wish to test. Defaults to 'undef' which generally uses the designated local unix socket. ####`database_port` Port to use when connecting. Default to 'undef' which generally defaults to 5432 depending on your PostgreSQL packaging. ####`database_name` The name of the database you wish to test. Defaults to 'postgres'. ####`database_username` Username to connect with. Defaults to 'undef', which when using a unix socket and ident auth will be the user you are running as. If the host is remote you must provide a username. ####`database_password` Password to connect with. Can be left blank, but that is not recommended. ####`run_as` The user to run the `psql` command with for authenticiation. This is important when trying to connect to a database locally using Unix sockets and `ident` authentication. It is not needed for remote testing. ####`sleep` Upon failure, sets the number of seconds to sleep for before trying again. ####`tries` Upon failure, sets the number of attempts before giving up and failing the resource. ####`create_db_first` This will ensure the database is created before running the test. This only really works if your test is local. Defaults to `true`. ###Function: postgresql\_password If you need to generate a postgres encrypted password, use `postgresql_password`. You can call it from your production manifests if you don't mind them containing the clear text versions of your passwords, or you can call it from the command line and then copy and paste the encrypted password into your manifest: $ puppet apply --execute 'notify { "test": message => postgresql_password("username", "password") }' ###Function: postgresql\_acls\_to\_resources\_hash(acl\_array, id, order\_offset) This internal function converts a list of `pg_hba.conf` based acls (passed in as an array of strings) to a format compatible with the `postgresql::pg_hba_rule` resource. **This function should only be used internally by the module**. Limitations ------------ Works with versions of PostgreSQL from 8.1 through 9.2. Current it is only actively tested with the following operating systems: * Debian 6.x and 7.x * Centos 5.x and 6.x * Ubuntu 10.04 and 12.04 Although patches are welcome for making it work with other OS distros, it is considered best effort. Development ------------ Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can't access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing) ### Tests There are two types of tests distributed with the module. Unit tests with rspec-puppet and system tests using rspec-system. For unit testing, make sure you have: * rake * bundler Install the necessary gems: bundle install --path=vendor And then run the unit tests: bundle exec rake spec The unit tests are ran in Travis-CI as well, if you want to see the results of your own tests regsiter the service hook through Travis-CI via the accounts section for your Github clone of this project. If you want to run the system tests, make sure you also have: * vagrant > 1.2.x * Virtualbox > 4.2.10 Then run the tests using: bundle exec rake spec:system To run the tests on different operating systems, see the sets available in .nodeset.yml and run the specific set with the following syntax: RSPEC_SET=debian-607-x64 bundle exec rake spec:system Transfer Notice ---------------- This Puppet module was originally authored by Inkling Systems. The maintainer preferred that Puppet Labs take ownership of the module for future improvement and maintenance as Puppet Labs is using it in the PuppetDB module. Existing pull requests and issues were transferred over, please fork and continue to contribute here instead of Inkling. Previously: [https://github.com/inkling/puppet-postgresql](https://github.com/inkling/puppet-postgresql) Contributors ------------ * Andrew Moon * [Kenn Knowles](https://github.com/kennknowles) ([@kennknowles](https://twitter.com/KennKnowles)) * Adrien Thebo * Albert Koch * Andreas Ntaflos * Bret Comnes * Brett Porter * Chris Price * dharwood * Etienne Pelletier * Florin Broasca * Henrik * Hunter Haugen * Jari Bakken * Jordi Boggiano * Ken Barber * nzakaria * Richard Arends * Spenser Gilliland * stormcrow * William Van Hevelingen puppetlabs-postgresql-3.2.0/spec/000755 000765 000024 00000000000 12236260460 017631 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/templates/000755 000765 000024 00000000000 12236260460 020675 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/templates/pg_hba_rule.conf000644 000765 000024 00000000246 12236260460 024015 0ustar00apenneystaff000000 000000 # Rule Name: <%=@name%> # Description: <%=@description%> # Order: <%=@order%> <%=@type%> <%=@database%> <%=@user%> <%=@address%> <%=@auth_method%> <%=@auth_option%> puppetlabs-postgresql-3.2.0/spec/fixtures/000755 000765 000024 00000000000 12236260460 021502 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/spec_helper.rb000644 000765 000024 00000001361 12236260460 022450 0ustar00apenneystaff000000 000000 require 'puppetlabs_spec_helper/module_spec_helper' RSpec.configure do |c| c.mock_with :rspec do |mock| mock.syntax = [:expect, :should] end c.include PuppetlabsSpec::Files c.before :each do # Ensure that we don't accidentally cache facts and environment # between test cases. Facter::Util::Loader.any_instance.stubs(:load_all) Facter.clear Facter.clear_messages # Store any environment variables away to be restored later @old_env = {} ENV.each_key {|k| @old_env[k] = ENV[k]} end c.after :each do PuppetlabsSpec::Files.cleanup end end # Convenience helper for returning parameters for a type from the # catalogue. def param(type, title, param) param_value(catalogue, type, title, param) end puppetlabs-postgresql-3.2.0/spec/spec_helper_system.rb000644 000765 000024 00000003235 12236260460 024056 0ustar00apenneystaff000000 000000 require 'rspec-system/spec_helper' require 'rspec-system-puppet/helpers' require 'rspec-system-serverspec/helpers' require 'tempfile' include Serverspec::Helper::RSpecSystem include Serverspec::Helper::DetectOS class String # Provide ability to remove indentation from strings, for the purpose of # left justifying heredoc blocks. def unindent gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "") end end module LocalHelpers include RSpecSystem::Util def psql(psql_cmd, user = 'postgres', &block) psql = "psql #{psql_cmd}" shell("su #{shellescape(user)} -c #{shellescape(psql)}", &block) end end include RSpecSystemPuppet::Helpers RSpec.configure do |c| # Project root for the firewall code proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) # Enable colour in Jenkins c.tty = true # Include in our local helpers c.include ::LocalHelpers # Puppet helpers c.include RSpecSystemPuppet::Helpers c.extend RSpecSystemPuppet::Helpers # This is where we 'setup' the nodes before running our tests c.before :suite do # Install puppet puppet_install # Copy this module into the module path of the test node puppet_module_install(:source => proj_root, :module_name => 'postgresql') shell('puppet module install puppetlabs/stdlib') shell('puppet module install puppetlabs/firewall') shell('puppet module install puppetlabs/apt') shell('puppet module install puppetlabs/concat') file = Tempfile.new('foo') begin file.write(<<-EOS) --- :logger: noop EOS file.close rcp(:sp => file.path, :dp => '/etc/puppet/hiera.yaml') ensure file.unlink end end end puppetlabs-postgresql-3.2.0/spec/system/000755 000765 000024 00000000000 12236260460 021155 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/000755 000765 000024 00000000000 12236260460 020610 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/classes/000755 000765 000024 00000000000 12236260460 022245 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/defines/000755 000765 000024 00000000000 12236260460 022225 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/functions/000755 000765 000024 00000000000 12236260460 022620 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/provider/000755 000765 000024 00000000000 12236260460 022442 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/puppet/000755 000765 000024 00000000000 12236260460 022125 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/type/000755 000765 000024 00000000000 12236260460 021571 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/type/postgresql_conf_spec.rb000644 000765 000024 00000003241 12236260460 026340 0ustar00apenneystaff000000 000000 #! /usr/bin/env ruby require 'spec_helper' describe Puppet::Type.type(:postgresql_conf) do before do @provider_class = described_class.provide(:simple) { mk_resource_methods } @provider_class.stubs(:suitable?).returns true described_class.stubs(:defaultprovider).returns @provider_class end describe "namevar validation" do it "should have :name as its namevar" do described_class.key_attributes.should == [:name] end it "should not invalid names" do expect { described_class.new(:name => 'foo bar') }.to raise_error(Puppet::Error, /Invalid value/) end it "should allow dots in names" do expect { described_class.new(:name => 'foo.bar') }.to_not raise_error end end describe "when validating attributes" do [:name, :provider].each do |param| it "should have a #{param} parameter" do described_class.attrtype(param).should == :param end end [:value, :target].each do |property| it "should have a #{property} property" do described_class.attrtype(property).should == :property end end end describe "when validating values" do describe "ensure" do it "should support present as a value for ensure" do expect { described_class.new(:name => 'foo', :ensure => :present) }.to_not raise_error end it "should support absent as a value for ensure" do expect { described_class.new(:name => 'foo', :ensure => :absent) }.to_not raise_error end it "should not support other values" do expect { described_class.new(:name => 'foo', :ensure => :foo) }.to raise_error(Puppet::Error, /Invalid value/) end end end end puppetlabs-postgresql-3.2.0/spec/unit/puppet/provider/000755 000765 000024 00000000000 12236260460 023757 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/puppet/type/000755 000765 000024 00000000000 12236260460 023106 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/puppet/type/postgresql_psql_spec.rb000644 000765 000024 00000005677 12236260460 027726 0ustar00apenneystaff000000 000000 require 'spec_helper' describe Puppet::Type.type(:postgresql_psql), "when validating attributes" do [:name, :unless, :db, :psql_path, :psql_user, :psql_group].each do |attr| it "should have a #{attr} parameter" do expect(Puppet::Type.type(:postgresql_psql).attrtype(attr)).to eq(:param) end end [:command].each do |attr| it "should have a #{attr} property" do expect(Puppet::Type.type(:postgresql_psql).attrtype(attr)).to eq(:property) end end end describe Puppet::Type.type(:postgresql_psql), :unless => Puppet.features.microsoft_windows? do subject do Puppet::Type.type(:postgresql_psql).new({:name => 'rspec'}.merge attributes) end describe "available attributes" do { :name => "rspec", :command => "SELECT stuff", :unless => "SELECT other,stuff", :db => "postgres", :psql_path => "/bin/false", :psql_user => "postgres", :psql_group => "postgres", :cwd => "/var/lib", :refreshonly => :true, :search_path => [ "schema1", "schema2"] }.each do |attr, value| context attr do let(:attributes) do { attr => value } end its([attr]) { should == value } end end context "default values" do let(:attributes) do {} end its([:psql_path]) { should eq("psql") } its([:psql_user]) { should eq("postgres") } its([:psql_group]) { should eq("postgres") } its([:cwd]) { should eq("/tmp") } its(:refreshonly?) { should be_false } end end describe "#refreshonly" do [true, :true].each do |refreshonly| context "=> #{refreshonly.inspect}" do let(:attributes) do { :refreshonly => refreshonly } end it "has a value of true" do expect(subject.refreshonly?).to be_true end it "will not enforce command on sync because refresh() will be called" do expect(subject.provider).to_not receive(:command=) subject.property(:command).sync end end end [false, :false].each do |refreshonly| context "=> #{refreshonly.inspect}" do let(:attributes) do { :refreshonly => refreshonly } end it "has a value of false" do expect(subject.refreshonly?).to be_false end it "will enforce command on sync because refresh() will not be called" do expect(subject.provider).to receive(:command=) subject.property(:command).sync end end end end ## If we refresh the resource, the command should always be run regardless of ## refreshonly describe "when responding to refresh" do [true, :true, false, :false].each do |refreshonly| context "with refreshonly => #{refreshonly.inspect}" do let(:attributes) do { :refreshonly => refreshonly } end it "will enforce command on sync" do expect(subject.provider).to receive(:command=) subject.refresh end end end end end puppetlabs-postgresql-3.2.0/spec/unit/puppet/provider/postgresql_psql/000755 000765 000024 00000000000 12236260460 027221 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/puppet/provider/postgresql_psql/ruby_spec.rb000644 000765 000024 00000011404 12236260460 031541 0ustar00apenneystaff000000 000000 require 'spec_helper' describe Puppet::Type.type(:postgresql_psql).provider(:ruby) do let(:name) { 'rspec psql test' } let(:resource) do Puppet::Type.type(:postgresql_psql).new({ :name => name, :provider => :ruby }.merge attributes) end let(:provider) { resource.provider } context("#run_sql_command") do describe "with default attributes" do let(:attributes) do { :db => 'spec_db' } end it "executes with the given psql_path on the given DB" do expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with( ['psql', '-d', attributes[:db], '-t', '-c', 'SELECT something'], 'postgres', 'postgres' ) provider.run_sql_command("SELECT something") end end describe "with psql_path and db" do let(:attributes) do { :psql_path => '/opt/postgres/psql', :psql_user => 'spec_user', :psql_group => 'spec_group', :cwd => '/spec', :db => 'spec_db' } end it "executes with the given psql_path on the given DB" do expect(Dir).to receive(:chdir).with(attributes[:cwd]).and_yield expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with( [attributes[:psql_path], '-d', attributes[:db], '-t', '-c', 'SELECT something'], attributes[:psql_user], attributes[:psql_group] ) provider.run_sql_command("SELECT something") end end describe "with search_path string" do let(:attributes) do { :search_path => "schema1" } end it "executes with the given search_path" do expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with( ['psql', '-t', '-c', 'set search_path to schema1; SELECT something'], 'postgres', 'postgres' ) provider.run_sql_command("SELECT something") end end describe "with search_path array" do let(:attributes) do { :search_path => ['schema1','schema2'], } end it "executes with the given search_path" do expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with( ['psql', '-t', '-c', 'set search_path to schema1,schema2; SELECT something'], 'postgres', 'postgres' ) provider.run_sql_command("SELECT something") end end end context("#command") do context "when unless is specified" do [:true, :false, true, false].each do |refresh| context "and refreshonly is #{refresh}" do let(:attributes) { { :command => 'SELECT something', :db => 'spec_db', :unless => 'SELECT something', :refreshonly => refresh } } it "does not fail when the status is successful" do expect(provider).to receive(:run_unless_sql_command).and_return ["1 row returned", 0] provider.command end it "returns the given command when rows are returned" do expect(provider).to receive(:run_unless_sql_command).and_return ["1 row returned", 0] expect(provider.command).to eq("SELECT something") end it "does not return the given command when no rows are returned" do expect(provider).to receive(:run_unless_sql_command).and_return ["0 rows returned", 0] expect(provider.command).to_not eq("SELECT something") end it "raises an error when the sql command fails" do allow(provider).to receive(:run_unless_sql_command).and_return ["Something went wrong", 1] expect { provider.command }.to raise_error(Puppet::Error, /Something went wrong/) end end end end context "when unless is not specified" do context "and refreshonly is true" do let(:attributes) do { :command => 'SELECT something', :db => 'spec_db', :refreshonly => :true } end it "does not run unless sql command" do expect(provider).to_not receive(:run_unless_sql_command) provider.command end it "returns the given command do disable sync" do expect(provider.command).to eq("SELECT something") end end context "and refreshonly is false" do let(:attributes) do { :command => 'SELECT something', :db => 'spec_db', :refreshonly => :false } end it "does not run unless sql command" do expect(provider).to_not receive(:run_unless_sql_command) provider.command end it "does not return the command so as to enable sync" do expect(provider.command).to_not eq("SELECT something") end end end end end puppetlabs-postgresql-3.2.0/spec/unit/provider/postgresql_conf/000755 000765 000024 00000000000 12236260460 025652 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/provider/postgresql_conf/parsed_spec.rb000644 000765 000024 00000007525 12236260460 030500 0ustar00apenneystaff000000 000000 require 'spec_helper' require "tempfile" provider_class = Puppet::Type.type(:postgresql_conf).provider(:parsed) describe provider_class do let(:title) { 'postgresql_conf' } let(:provider) { conf_class = Puppet::Type.type(:postgresql_conf) provider = conf_class.provider(:parsed) conffile = tmpfilename('postgresql.conf') provider.any_instance.stubs(:target).returns conffile provider } before do end after :each do provider.initvars end describe "simple configuration that should be allowed" do it "should parse a simple ini line" do provider.parse_line("listen_addreses = '*'").should == { :name=>"listen_addreses", :value=>"*", :comment=>nil, :record_type=>:parsed } end it "should parse a simple ini line (2)" do provider.parse_line(" listen_addreses = '*'").should == { :name=>"listen_addreses", :value=>"*", :comment=>nil, :record_type=>:parsed } end it "should parse a simple ini line (3)" do provider.parse_line("listen_addreses = '*' # dont mind me").should == { :name=>"listen_addreses", :value=>"*", :comment=>"dont mind me", :record_type=>:parsed } end it "should parse a comment" do provider.parse_line("# dont mind me").should == { :line=>"# dont mind me", :record_type=>:comment } end it "should parse a comment (2)" do provider.parse_line(" \t# dont mind me").should == { :line=>" \t# dont mind me", :record_type=>:comment } end it "should allow includes" do provider.parse_line("include puppetextra").should == { :name=>"include", :value=>"puppetextra", :comment=>nil, :record_type=>:parsed } end it "should allow numbers thorugh without quotes" do provider.parse_line("wal_keep_segments = 32").should == { :name=>"wal_keep_segments", :value=>"32", :comment=>nil, :record_type=>:parsed } end it "should allow blanks thorugh " do provider.parse_line("").should == { :line=>"", :record_type=>:blank } end it "should parse keys with dots " do provider.parse_line("auto_explain.log_min_duration = 1ms").should == { :name => "auto_explain.log_min_duration", :value => "1ms", :comment => nil, :record_type => :parsed } end end describe "configuration that should be set" do it "should set comment lines" do provider.to_line({ :line=>"# dont mind me", :record_type=>:comment }).should == '# dont mind me' end it "should set blank lines" do provider.to_line({ :line=>"", :record_type=>:blank }).should == '' end it "should set simple configuration" do provider.to_line({:name=>"listen_addresses", :value=>"*", :comment=>nil, :record_type=>:parsed }).should == "listen_addresses = '*'" end it "should set simple configuration with period in name" do provider.to_line({:name => "auto_explain.log_min_duration", :value => '100ms', :comment => nil, :record_type => :parsed }).should == "auto_explain.log_min_duration = 100ms" end it "should set simple configuration even with comments" do provider.to_line({:name=>"listen_addresses", :value=>"*", :comment=>'dont mind me', :record_type=>:parsed }).should == "listen_addresses = '*' # dont mind me" end it 'should quote includes' do provider.to_line( {:name=>"include", :value=>"puppetextra", :comment=>nil, :record_type=>:parsed }).should == "include 'puppetextra'" end it 'should quote multiple words' do provider.to_line( {:name=>"archive_command", :value=>"rsync up", :comment=>nil, :record_type=>:parsed }).should == "archive_command = 'rsync up'" end it 'shouldn\'t quote numbers' do provider.to_line( {:name=>"wal_segments", :value=>"32", :comment=>nil, :record_type=>:parsed }).should == "wal_segments = 32" end end end puppetlabs-postgresql-3.2.0/spec/unit/functions/postgresql_acls_to_resources_hash_spec.rb000644 000765 000024 00000007506 12236260460 033173 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do context 'individual transform tests' do it do input = 'local all postgres ident' result = { "postgresql class generated rule test 0"=>{ "type"=>"local", "database"=>"all", "user"=>"postgres", "auth_method"=>"ident", "order"=>"100", }, } should run.with_params([input], 'test', 100).and_return(result) end it do input = 'local all root ident' result = { "postgresql class generated rule test 0"=>{ "type"=>"local", "database"=>"all", "user"=>"root", "auth_method"=>"ident", "order"=>"100", }, } should run.with_params([input], 'test', 100).and_return(result) end it do input_array = [ 'local all all ident', ] result = { "postgresql class generated rule test 0"=>{ "type"=>"local", "database"=>"all", "user"=>"all", "auth_method"=>"ident", "order"=>"100", }, } should run.with_params(input_array, 'test', 100).and_return(result) end it do input = 'host all all 127.0.0.1/32 md5' result = { "postgresql class generated rule test 0"=>{ "type"=>"host", "database"=>"all", "user"=>"all", "address"=>"127.0.0.1/32", "auth_method"=>"md5", "order"=>"100", }, } should run.with_params([input], 'test', 100).and_return(result) end it do input = 'host all all 0.0.0.0/0 md5' result = { "postgresql class generated rule test 0"=>{ "type"=>"host", "database"=>"all", "user"=>"all", "address"=>"0.0.0.0/0", "auth_method"=>"md5", "order"=>"100", }, } should run.with_params([input], 'test', 100).and_return(result) end it do input = 'host all all ::1/128 md5' result = { "postgresql class generated rule test 0"=>{ "type"=>"host", "database"=>"all", "user"=>"all", "address"=>"::1/128", "auth_method"=>"md5", "order"=>"100", }, } should run.with_params([input], 'test', 100).and_return(result) end it do input = 'host all all 1.1.1.1 255.255.255.0 md5' result = { "postgresql class generated rule test 0"=>{ "type"=>"host", "database"=>"all", "user"=>"all", "address"=>"1.1.1.1 255.255.255.0", "auth_method"=>"md5", "order"=>"100", }, } should run.with_params([input], 'test', 100).and_return(result) end it do input = 'host all all 1.1.1.1 255.255.255.0 ldap ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net"' result = { "postgresql class generated rule test 0"=>{ "type"=>"host", "database"=>"all", "user"=>"all", "address"=>"1.1.1.1 255.255.255.0", "auth_method"=>"ldap", "auth_option"=>"ldapserver=ldap.example.net ldapprefix=\"cn=\" ldapsuffix=\", dc=example, dc=net\"", "order"=>"100", }, } should run.with_params([input], 'test', 100).and_return(result) end end it 'should return an empty hash when input is empty array' do should run.with_params([], 'test', 100).and_return({}) end end puppetlabs-postgresql-3.2.0/spec/unit/functions/postgresql_escape_spec.rb000644 000765 000024 00000000441 12236260460 027701 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql_escape', :type => :puppet_function do it { should run.with_params('foo'). and_return('$$foo$$') } end describe 'postgresql_escape', :type => :puppet_function do it { should run.with_params('fo$$o'). and_return('$ed$fo$$o$ed$') } end puppetlabs-postgresql-3.2.0/spec/unit/functions/postgresql_password_spec.rb000644 000765 000024 00000000275 12236260460 030310 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql_password', :type => :puppet_function do it { should run.with_params('foo', 'bar'). and_return('md596948aad3fcae80c08a35c9b5958cd89') } end puppetlabs-postgresql-3.2.0/spec/unit/defines/server/000755 000765 000024 00000000000 12236260460 023533 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/defines/validate_db_connection_spec.rb000644 000765 000024 00000001462 12236260460 030244 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::validate_db_connection', :type => :define do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end let :title do 'test' end describe 'should work with only default parameters' do it { should contain_postgresql__validate_db_connection('test') } end describe 'should work with all parameters' do let :params do { :database_host => 'test', :database_name => 'test', :database_password => 'test', :database_username => 'test', :database_port => 5432, :run_as => 'postgresq', :sleep => 4, :tries => 30, } end it { should contain_postgresql__validate_db_connection('test') } end end puppetlabs-postgresql-3.2.0/spec/unit/defines/server/config_entry_spec.rb000644 000765 000024 00000000737 12236260460 027567 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::config_entry', :type => :define do let :facts do { :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.4', } end let(:title) { 'config_entry'} let :target do tmpfilename('postgresql_conf') end context "syntax check" do let(:params) { { :ensure => 'present'} } it { should contain_postgresql__server__config_entry('config_entry') } end end puppetlabs-postgresql-3.2.0/spec/unit/defines/server/database_grant_spec.rb000644 000765 000024 00000000775 12236260460 030042 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::database_grant', :type => :define do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end let :title do 'test' end let :params do { :privilege => 'ALL', :db => 'test', :role => 'test', } end it { should contain_postgresql__server__database_grant('test') } it { should contain_postgresql__server__grant('database:test') } end puppetlabs-postgresql-3.2.0/spec/unit/defines/server/database_spec.rb000644 000765 000024 00000000615 12236260460 026640 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::database', :type => :define do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end let :title do 'test' end it { should contain_postgresql__server__database('test') } it { should contain_postgresql_psql("Check for existence of db 'test'") } end puppetlabs-postgresql-3.2.0/spec/unit/defines/server/db_spec.rb000644 000765 000024 00000001210 12236260460 025451 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::db', :type => :define do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end let :title do 'test' end let :params do { :user => 'test', :password => 'test', :owner => 'tester', } end it { should contain_postgresql__server__db('test') } it { should contain_postgresql__server__database('test').with_owner('tester') } it { should contain_postgresql__server__role('test') } it { should contain_postgresql__server__database_grant('GRANT test - ALL - test') } end puppetlabs-postgresql-3.2.0/spec/unit/defines/server/grant_spec.rb000644 000765 000024 00000000615 12236260460 026207 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::grant', :type => :define do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end let :title do 'test' end let :params do { :db => 'test', :role => 'test', } end it { should contain_postgresql__server__grant('test') } end puppetlabs-postgresql-3.2.0/spec/unit/defines/server/pg_hba_rule_spec.rb000644 000765 000024 00000007616 12236260460 027353 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::pg_hba_rule', :type => :define do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', :concat_basedir => tmpfilename('pg_hba'), } end let :title do 'test' end let :target do tmpfilename('pg_hba_rule') end context 'test template 1' do let :params do { :type => 'host', :database => 'all', :user => 'all', :address => '1.1.1.1/24', :auth_method => 'md5', :target => target, } end it do content = param('concat::fragment', 'pg_hba_rule_test', 'content') content.should =~ /host\s+all\s+all\s+1\.1\.1\.1\/24\s+md5/ end end context 'test template 2' do let :params do { :type => 'local', :database => 'all', :user => 'all', :auth_method => 'ident', :target => target, } end it do content = param('concat::fragment', 'pg_hba_rule_test', 'content') content.should =~ /local\s+all\s+all\s+ident/ end end context 'test template 3' do let :params do { :type => 'host', :database => 'all', :user => 'all', :address => '0.0.0.0/0', :auth_method => 'ldap', :auth_option => 'foo=bar', :target => target, } end it do content = param('concat::fragment', 'pg_hba_rule_test', 'content') content.should =~ /host\s+all\s+all\s+0\.0\.0\.0\/0\s+ldap\s+foo=bar/ end end context 'validation' do context 'validate type test 1' do let :params do { :type => 'invalid', :database => 'all', :user => 'all', :address => '0.0.0.0/0', :auth_method => 'ldap', :target => target, } end it 'should fail parsing when type is not valid' do expect {subject}.to raise_error(Puppet::Error, /The type you specified \[invalid\] must be one of/) end end context 'validate auth_method' do let :params do { :type => 'local', :database => 'all', :user => 'all', :address => '0.0.0.0/0', :auth_method => 'invalid', :target => target, } end it 'should fail parsing when auth_method is not valid' do expect {subject}.to raise_error(Puppet::Error, /The auth_method you specified \[invalid\] must be one of/) end end context 'validate unsupported auth_method' do let :pre_condition do <<-EOS class { 'postgresql::globals': version => '9.0', } class { 'postgresql::server': } EOS end let :params do { :type => 'local', :database => 'all', :user => 'all', :address => '0.0.0.0/0', :auth_method => 'peer', :target => target, } end it 'should fail parsing when auth_method is not valid' do expect {subject}.to raise_error(Puppet::Error, /The auth_method you specified \[peer\] must be one of: trust, reject, md5, sha1, password, gss, sspi, krb5, ident, ldap, radius, cert, pam/) end end context 'validate supported auth_method' do let :pre_condition do <<-EOS class { 'postgresql::globals': version => '9.2', } class { 'postgresql::server': } EOS end let :params do { :type => 'local', :database => 'all', :user => 'all', :address => '0.0.0.0/0', :auth_method => 'peer', :target => target, } end it do content = param('concat::fragment', 'pg_hba_rule_test', 'content') content.should =~ /local\s+all\s+all\s+0\.0\.0\.0\/0\s+peer/ end end end end puppetlabs-postgresql-3.2.0/spec/unit/defines/server/role_spec.rb000644 000765 000024 00000000577 12236260460 026044 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::role', :type => :define do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end let :title do 'test' end let :params do { :password_hash => 'test', } end it { should contain_postgresql__server__role('test') } end puppetlabs-postgresql-3.2.0/spec/unit/defines/server/table_grant_spec.rb000644 000765 000024 00000001013 12236260460 027347 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::table_grant', :type => :define do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end let :title do 'test' end let :params do { :privilege => 'ALL', :db => 'test', :role => 'test', :table => 'foo', } end it { should contain_postgresql__server__table_grant('test') } it { should contain_postgresql__server__grant('table:test') } end puppetlabs-postgresql-3.2.0/spec/unit/defines/server/tablespace_spec.rb000644 000765 000024 00000000617 12236260460 027201 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::tablespace', :type => :define do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end let :title do 'test' end let :params do { :location => '/srv/data/foo', } end it { should contain_postgresql__server__tablespace('test') } end puppetlabs-postgresql-3.2.0/spec/unit/classes/client_spec.rb000644 000765 000024 00000001403 12236260460 025060 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::client', :type => :class do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end describe 'with parameters' do let :params do { :package_ensure => 'absent', :package_name => 'mypackage', } end it 'should modify package' do should contain_package("postgresql-client").with({ :ensure => 'absent', :name => 'mypackage', :tag => 'postgresql', }) end end describe 'with no parameters' do it 'should create package with postgresql tag' do should contain_package('postgresql-client').with({ :tag => 'postgresql', }) end end end puppetlabs-postgresql-3.2.0/spec/unit/classes/globals_spec.rb000644 000765 000024 00000001103 12236260460 025222 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::globals', :type => :class do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end describe 'with no parameters' do it 'should work' do should include_class("postgresql::globals") end end describe 'manage_package_repo => true' do let(:params) do { :manage_package_repo => true, } end it 'should pull in class postgresql::repo' do should include_class("postgresql::repo") end end end puppetlabs-postgresql-3.2.0/spec/unit/classes/lib/000755 000765 000024 00000000000 12236260460 023013 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/classes/params_spec.rb000644 000765 000024 00000000414 12236260460 025066 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::params', :type => :class do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end it { should include_class("postgresql::params") } end puppetlabs-postgresql-3.2.0/spec/unit/classes/repo_spec.rb000644 000765 000024 00000000603 12236260460 024550 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::repo', :type => :class do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end describe 'with no parameters' do it 'should instantiate apt_postgresql_org class' do should include_class('postgresql::repo::apt_postgresql_org') end end end puppetlabs-postgresql-3.2.0/spec/unit/classes/server/000755 000765 000024 00000000000 12236260460 023553 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/unit/classes/server_spec.rb000644 000765 000024 00000003715 12236260460 025120 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server', :type => :class do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', :concat_basedir => tmpfilename('server'), :kernel => 'Linux', } end describe 'with no parameters' do it { should include_class("postgresql::params") } it { should include_class("postgresql::server") } it 'should validate connection' do should contain_postgresql__validate_db_connection('validate_service_is_running') end end describe 'manage_firewall => true' do let(:params) do { :manage_firewall => true, :ensure => true, } end it 'should create firewall rule' do should contain_firewall("5432 accept - postgres") end end describe 'ensure => absent' do let(:params) do { :ensure => 'absent', :datadir => '/my/path', } end it 'should make package purged' do should contain_package('postgresql-server').with({ :ensure => 'purged', }) end it 'stop the service' do should contain_service('postgresqld').with({ :ensure => false, }) end it 'should remove datadir' do should contain_file('/my/path').with({ :ensure => 'absent', }) end end describe 'package_ensure => absent' do let(:params) do { :package_ensure => 'absent', } end it 'should remove the package' do should contain_package('postgresql-server').with({ :ensure => 'purged', }) end it 'should still enable the service' do should contain_service('postgresqld').with({ :ensure => true, }) end end describe 'needs_initdb => true' do let(:params) do { :needs_initdb => true, } end it 'should contain proper initdb exec' do should contain_exec('postgresql_initdb') end end end puppetlabs-postgresql-3.2.0/spec/unit/classes/server/contrib_spec.rb000644 000765 000024 00000001663 12236260460 026560 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::contrib', :type => :class do let :pre_condition do "class { 'postgresql::server': }" end let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', :kernel => 'Linux', :concat_basedir => tmpfilename('contrib'), } end describe 'with parameters' do let(:params) do { :package_name => 'mypackage', :package_ensure => 'absent', } end it 'should create package with correct params' do should contain_package('postgresql-contrib').with({ :ensure => 'absent', :name => 'mypackage', :tag => 'postgresql', }) end end describe 'with no parameters' do it 'should create package with postgresql tag' do should contain_package('postgresql-contrib').with({ :tag => 'postgresql', }) end end end puppetlabs-postgresql-3.2.0/spec/unit/classes/server/initdb_spec.rb000644 000765 000024 00000001340 12236260460 026361 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::initdb', :type => :class do let (:pre_condition) do "include postgresql::server" end describe 'on RedHat' do let :facts do { :osfamily => 'RedHat', :operatingsystem => 'CentOS', :operatingsystemrelease => '6.0', :concat_basedir => tmpfilename('server'), } end it { should contain_file('/var/lib/pgsql/data').with_ensure('directory') } end describe 'on Amazon' do let :facts do { :osfamily => 'RedHat', :operatingsystem => 'Amazon', :concat_basedir => tmpfilename('server'), } end it { should contain_file('/var/lib/pgsql9/data').with_ensure('directory') } end endpuppetlabs-postgresql-3.2.0/spec/unit/classes/server/plperl_spec.rb000644 000765 000024 00000002064 12236260460 026412 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::server::plperl', :type => :class do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', :kernel => 'Linux', :concat_basedir => tmpfilename('plperl'), } end let :pre_condition do "class { 'postgresql::server': }" end describe 'with no parameters' do it { should include_class("postgresql::server::plperl") } it 'should create package' do should contain_package('postgresql-plperl').with({ :ensure => 'present', :tag => 'postgresql', }) end end describe 'with parameters' do let :params do { :package_ensure => 'absent', :package_name => 'mypackage', } end it { should include_class("postgresql::server::plperl") } it 'should create package with correct params' do should contain_package('postgresql-plperl').with({ :ensure => 'absent', :name => 'mypackage', :tag => 'postgresql', }) end end end puppetlabs-postgresql-3.2.0/spec/unit/classes/lib/devel_spec.rb000644 000765 000024 00000000424 12236260460 025451 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::lib::devel', :type => :class do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end it { should include_class("postgresql::lib::devel") } end puppetlabs-postgresql-3.2.0/spec/unit/classes/lib/java_spec.rb000644 000765 000024 00000001737 12236260460 025303 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::lib::java', :type => :class do describe 'on a debian based os' do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end it { should contain_package('postgresql-jdbc').with( :name => 'libpostgresql-jdbc-java', :ensure => 'present' )} end describe 'on a redhat based os' do let :facts do { :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.4', } end it { should contain_package('postgresql-jdbc').with( :name => 'postgresql-jdbc', :ensure => 'present' )} describe 'when parameters are supplied' do let :params do {:package_ensure => 'latest', :package_name => 'somepackage'} end it { should contain_package('postgresql-jdbc').with( :name => 'somepackage', :ensure => 'latest' )} end end end puppetlabs-postgresql-3.2.0/spec/unit/classes/lib/python_spec.rb000644 000765 000024 00000001273 12236260460 025676 0ustar00apenneystaff000000 000000 require 'spec_helper' describe 'postgresql::lib::python', :type => :class do describe 'on a redhat based os' do let :facts do { :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.4', } end it { should contain_package('python-psycopg2').with( :name => 'python-psycopg2', :ensure => 'present' )} end describe 'on a debian based os' do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', } end it { should contain_package('python-psycopg2').with( :name => 'python-psycopg2', :ensure => 'present' )} end end puppetlabs-postgresql-3.2.0/spec/system/client_spec.rb000644 000765 000024 00000000756 12236260460 024002 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::client:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::client': package_ensure => purged }") do |r| r.exit_code.should_not == 1 end end it 'test loading class with no parameters' do pp = <<-EOS.unindent class { 'postgresql::client': } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end end end puppetlabs-postgresql-3.2.0/spec/system/common_patterns_spec.rb000644 000765 000024 00000002603 12236260460 025725 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'common patterns:' do describe 'postgresql.conf include pattern' do after :all do pp = <<-EOS.unindent class { 'postgresql::server': ensure => absent } file { '/tmp/include.conf': ensure => absent } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 end end it "should support an 'include' directive at the end of postgresql.conf" do pending('no support for include directive with centos 5/postgresql 8.1', :if => (node.facts['osfamily'] == 'RedHat' and node.facts['lsbmajdistrelease'] == '5')) pp = <<-EOS.unindent class { 'postgresql::server': } $extras = "/etc/postgresql-include.conf" file { $extras: content => 'max_connections = 123', seltype => 'postgresql_db_t', seluser => 'system_u', notify => Class['postgresql::server::service'], } postgresql::server::config_entry { 'include': value => $extras, require => File[$extras], } EOS puppet_apply(pp) do |r| r.exit_code.should == 2 r.refresh r.exit_code.should == 0 end psql('--command="show max_connections" -t') do |r| r.stdout.should =~ /123/ r.stderr.should == '' r.exit_code.should == 0 end end end end puppetlabs-postgresql-3.2.0/spec/system/contrib_spec.rb000644 000765 000024 00000001376 12236260460 024163 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::server::contrib:' do after :all do # Cleanup after tests have ran, remove both contrib and server as contrib # pulls in the server based packages. pp = <<-EOS.unindent class { 'postgresql::server': ensure => absent, } class { 'postgresql::server::contrib': package_ensure => purged, } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 end end it 'test loading class with no parameters' do pp = <<-EOS.unindent class { 'postgresql::server': } class { 'postgresql::server::contrib': } EOS puppet_apply(pp) do |r| r.exit_code.should == 2 r.refresh r.exit_code.should == 0 end end end puppetlabs-postgresql-3.2.0/spec/system/lib/000755 000765 000024 00000000000 12236260460 021723 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/system/postgresql_psql_spec.rb000644 000765 000024 00000002352 12236260460 025760 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql_psql:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'should run some SQL when the unless query returns no rows' do pp = <<-EOS.unindent class { 'postgresql::server': } postgresql_psql { 'foobar': db => 'postgres', psql_user => 'postgres', command => 'select 1', unless => 'select 1 where 1=2', require => Class['postgresql::server'], } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 2 end end it 'should not run SQL when the unless query returns rows' do pp = <<-EOS.unindent class { 'postgresql::server': } postgresql_psql { 'foobar': db => 'postgres', psql_user => 'postgres', command => 'select * from pg_database limit 1', unless => 'select 1 where 1=1', require => Class['postgresql::server'], } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end end end puppetlabs-postgresql-3.2.0/spec/system/server/000755 000765 000024 00000000000 12236260460 022463 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/system/server_spec.rb000644 000765 000024 00000013326 12236260460 024027 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'server:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'test loading class with no parameters' do pp = <<-EOS.unindent class { 'postgresql::server': } EOS puppet_apply(pp) do |r| r.exit_code.should == 2 r.refresh r.exit_code.should == 0 end end describe port(5432) do it { should be_listening } end describe 'setting postgres password' do it 'should install and successfully adjust the password' do pp = <<-EOS.unindent class { 'postgresql::server': postgres_password => 'foobarbaz', ip_mask_deny_postgres_user => '0.0.0.0/32', } EOS puppet_apply(pp) do |r| [0,2].should include(r.exit_code) r.stdout.should =~ /\[set_postgres_postgrespw\]\/returns: executed successfully/ r.refresh r.exit_code.should == 0 end pp = <<-EOS.unindent class { 'postgresql::server': postgres_password => 'TPSR$$eports!', ip_mask_deny_postgres_user => '0.0.0.0/32', } EOS puppet_apply(pp) do |r| [0,2].should include(r.exit_code) r.stdout.should =~ /\[set_postgres_postgrespw\]\/returns: executed successfully/ r.refresh r.exit_code.should == 0 end end end end describe 'server without defaults:' do before :all do puppet_apply(<<-EOS.unindent) if($::operatingsystem =~ /Debian|Ubuntu/) { # Need to make sure the correct utf8 locale is ready for our # non-standard tests file { '/etc/locale.gen': content => "en_US ISO-8859-1\nen_NG UTF-8\nen_US UTF-8\n", }~> exec { '/usr/sbin/locale-gen': logoutput => true, refreshonly => true, } } EOS end context 'test installing non-default version of postgresql' do after :all do psql('--command="drop database postgresql_test_db" postgres') pp = <<-EOS.unindent class { 'postgresql::globals': ensure => absent, manage_package_repo => true, version => '9.3', } class { 'postgresql::server': ensure => absent, } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 end end it 'perform installation and create a db' do pp = <<-EOS.unindent class { "postgresql::globals": version => "9.3", manage_package_repo => true, encoding => 'UTF8', locale => 'en_US.UTF-8', } class { "postgresql::server": } postgresql::server::db { "postgresql_test_db": user => "foo1", password => postgresql_password('foo1', 'foo1'), } postgresql::server::config_entry { 'port': value => '5432', } EOS puppet_apply(pp) do |r| r.exit_code.should == 2 r.refresh r.exit_code.should == 0 end psql('postgresql_test_db --command="select datname from pg_database limit 1"') do |r| r.exit_code.should == 0 end end describe port(5432) do it { should be_listening } end end unless ((node.facts['osfamily'] == 'RedHat' and node.facts['lsbmajdistrelease'] == '5') || node.facts['osfamily'] == 'Debian') context 'override locale and encoding' do after :each do puppet_apply "class { 'postgresql::server': ensure => absent }" do |r| r.exit_code.should_not == 1 end end it 'perform installation with different locale and encoding' do pp = <<-EOS.unindent class { 'postgresql::server': locale => 'en_NG', encoding => 'UTF8', } EOS puppet_apply(pp) do |r| r.exit_code.should == 2 r.refresh r.exit_code.should == 0 end # Remove db first, if it exists for some reason shell('su postgres -c "dropdb test1"') shell('su postgres -c "createdb test1"') shell('su postgres -c \'psql -c "show lc_ctype" test1\'') do |r| r.stdout.should =~ /en_NG/ end shell('su postgres -c \'psql -c "show lc_collate" test1\'') do |r| r.stdout.should =~ /en_NG/ end end end end end describe 'server with firewall:' do after :all do puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end context 'test installing postgresql with firewall management on' do it 'perform installation and make sure it is idempotent' do pending('no support for firewall with fedora', :if => (node.facts['operatingsystem'] == 'Fedora')) pp = <<-EOS.unindent class { 'firewall': } class { "postgresql::server": manage_firewall => true, } EOS puppet_apply(pp) do |r| r.exit_code.should == 2 r.refresh r.exit_code.should == 0 end end end end describe 'server without pg_hba.conf:' do after :all do puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end context 'test installing postgresql without pg_hba.conf management on' do it 'perform installation and make sure it is idempotent' do pp = <<-EOS.unindent class { "postgresql::server": manage_pg_hba_conf => false, } EOS puppet_apply(pp) do |r| r.exit_code.should == 2 r.refresh r.exit_code.should == 0 end end end end puppetlabs-postgresql-3.2.0/spec/system/validate_db_connection_spec.rb000644 000765 000024 00000004625 12236260460 027200 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::validate_db_connection:' do before :all do # Setup postgresql server and a sample database for tests to use. pp = <<-EOS.unindent $db = 'foo' class { 'postgresql::server': } postgresql::server::db { $db: user => $db, password => postgresql_password($db, $db), } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 end end after :all do # Remove postgresql server after all tests have ran. puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'should run puppet with no changes declared if socket connectivity works' do pp = <<-EOS.unindent postgresql::validate_db_connection { 'foo': database_name => 'foo', run_as => 'postgres', } EOS puppet_apply(pp) do |r| r.exit_code.should == 0 end end it 'should keep retrying if database is down' do # So first we shut the db down, then background a startup routine with a # sleep 10 in front of it. That way rspec-system should continue while # the pause and db startup happens in the background. shell("/etc/init.d/postgresql* stop") shell('nohup bash -c "sleep 10; /etc/init.d/postgresql* start" > /dev/null 2>&1 &') pp = <<-EOS.unindent postgresql::validate_db_connection { 'foo': database_name => 'foo', tries => 30, sleep => 1, run_as => 'postgres', } EOS puppet_apply(pp) do |r| r.exit_code.should == 0 end end it 'should run puppet with no changes declared if db ip connectivity works' do pp = <<-EOS.unindent postgresql::validate_db_connection { 'foo': database_host => 'localhost', database_name => 'foo', database_username => 'foo', database_password => 'foo', } EOS puppet_apply(pp) do |r| r.exit_code.should == 0 end end it 'should fail catalogue if database connectivity fails' do pp = <<-EOS.unindent postgresql::validate_db_connection { 'foobarbaz': database_host => 'localhost', database_name => 'foobarbaz', database_username => 'foobarbaz', database_password => 'foobarbaz', } EOS puppet_apply(pp) do |r| r.exit_code.should == 4 end end end puppetlabs-postgresql-3.2.0/spec/system/server/config_entry_spec.rb000644 000765 000024 00000001417 12236260460 026513 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::server::config_entry:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'should change setting and reflect it in show all' do pp = <<-EOS.unindent class { 'postgresql::server': } postgresql::server::config_entry { 'check_function_bodies': value => 'off', } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end psql('--command="show all" postgres') do |r| r.stdout.should =~ /check_function_bodies.+off/ r.stderr.should be_empty r.exit_code.should == 0 end end end puppetlabs-postgresql-3.2.0/spec/system/server/database_grant_spec.rb000644 000765 000024 00000002730 12236260460 026763 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::server::database_grant:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'should grant access so a user can create objects in a database' do begin pp = <<-EOS.unindent $db = 'postgres' $user = 'psql_grant_tester' $password = 'psql_grant_pw' class { 'postgresql::server': } # Since we are not testing pg_hba or any of that, make a local user for ident auth user { $user: ensure => present, } postgresql::server::role { $user: password_hash => postgresql_password($user, $password), } postgresql::server::database { $db: } postgresql::server::database_grant { 'grant create test': privilege => 'CREATE', db => $db, role => $user, } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end # Check that the user can create a table in the database psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r| r.stdout.should =~ /CREATE TABLE/ r.stderr.should == '' r.exit_code.should == 0 end ensure psql('--command="drop table foo" postgres', 'psql_grant_tester') end end end puppetlabs-postgresql-3.2.0/spec/system/server/database_spec.rb000644 000765 000024 00000001624 12236260460 025571 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::server::database:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'should idempotently create a db that we can connect to' do begin pp = <<-EOS.unindent $db = 'postgresql_test_db' class { 'postgresql::server': } postgresql::server::database { $db: } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end psql('--command="select datname from pg_database" postgresql_test_db') do |r| r.stdout.should =~ /postgresql_test_db/ r.stderr.should be_empty r.exit_code.should == 0 end ensure psql('--command="drop database postgresql_test_db" postgres') end end end puppetlabs-postgresql-3.2.0/spec/system/server/db_spec.rb000644 000765 000024 00000007425 12236260460 024417 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::server::db' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'should idempotently create a db that we can connect to' do begin pp = <<-EOS.unindent $db = 'postgresql_test_db' class { 'postgresql::server': } postgresql::server::db { $db: user => $db, password => postgresql_password($db, $db), } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end psql('--command="select datname from pg_database" postgresql_test_db') do |r| r.stdout.should =~ /postgresql_test_db/ r.stderr.should be_empty r.exit_code.should == 0 end ensure psql('--command="drop database postgresql_test_db" postgres') end end it 'should take a locale parameter' do pending('no support for locale parameter with centos 5', :if => (node.facts['osfamily'] == 'RedHat' and node.facts['lsbmajdistrelease'] == '5')) begin pp = <<-EOS.unindent class { 'postgresql::server': } if($::operatingsystem == 'Debian') { # Need to make sure the correct locale is installed first file { '/etc/locale.gen': content => "en_US ISO-8859-1\nen_NG UTF-8\n", }~> exec { '/usr/sbin/locale-gen': logoutput => true, refreshonly => true, } } postgresql::server::db { 'test1': user => 'test1', password => postgresql_password('test1', 'test1'), encoding => 'UTF8', locale => 'en_NG', } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end psql('-c "show lc_ctype" test1') do |r| r.stdout.should =~ /en_NG/ end psql('-c "show lc_collate" test1') do |r| r.stdout.should =~ /en_NG/ end ensure psql('--command="drop database test1" postgres') end end it 'should take an istemplate parameter' do begin pp = <<-EOS.unindent $db = 'template2' class { 'postgresql::server': } postgresql::server::db { $db: user => $db, password => postgresql_password($db, $db), istemplate => true, } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end psql('--command="select datname from pg_database" template2') do |r| r.stdout.should =~ /template2/ r.stderr.should be_empty r.exit_code.should == 0 end ensure psql('--command="drop database template2" postgres') do |r| r.stdout.should be_empty r.stderr.should =~ /cannot drop a template database/ r.exit_code.should_not == 0 end end end it 'should update istemplate parameter' do begin pp = <<-EOS.unindent $db = 'template2' class { 'postgresql::server': } postgresql::server::db { $db: user => $db, password => postgresql_password($db, $db), istemplate => false, } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end psql('--command="select datname from pg_database" template2') do |r| r.stdout.should =~ /template2/ r.stderr.should be_empty r.exit_code.should == 0 end ensure psql('--command="drop database template2" postgres') do |r| r.exit_code.should == 0 end end end end puppetlabs-postgresql-3.2.0/spec/system/server/grant_spec.rb000644 000765 000024 00000002751 12236260460 025142 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::server::grant:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'should grant access so a user can create in a database' do begin pp = <<-EOS.unindent $db = 'postgres' $user = 'psql_grant_tester' $password = 'psql_grant_pw' class { 'postgresql::server': } # Since we are not testing pg_hba or any of that, make a local user for ident auth user { $user: ensure => present, } postgresql::server::role { $user: password_hash => postgresql_password($user, $password), } postgresql::server::database { $db: } postgresql::server::grant { 'grant create test': object_type => 'database', privilege => 'CREATE', db => $db, role => $user, } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end # Check that the user can create a table in the database psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r| r.stdout.should =~ /CREATE TABLE/ r.stderr.should == '' r.exit_code.should == 0 end ensure psql('--command="drop table foo" postgres', 'psql_grant_tester') end end end puppetlabs-postgresql-3.2.0/spec/system/server/pg_hba_rule_spec.rb000644 000765 000024 00000004344 12236260460 026276 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::server::pg_hba_rule:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'should create a ruleset in pg_hba.conf' do pp = <<-EOS.unindent class { 'postgresql::server': } postgresql::server::pg_hba_rule { "allow application network to access app database": type => "host", database => "app", user => "app", address => "200.1.2.0/24", auth_method => md5, } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 end puppet_apply(pp) do |r| r.exit_code.should be_zero end shell("grep '200.1.2.0/24' /etc/postgresql/*/*/pg_hba.conf || grep '200.1.2.0/24' /var/lib/pgsql/data/pg_hba.conf") do |r| r.exit_code.should be_zero end end it 'should create a ruleset in pg_hba.conf that denies db access to db test1' do pp = <<-EOS.unindent class { 'postgresql::server': } postgresql::server::db { "test1": user => "test1", password => postgresql_password('test1', 'test1'), grant => "all", } postgresql::server::pg_hba_rule { "allow anyone to have access to db test1": type => "local", database => "test1", user => "test1", auth_method => reject, order => '001', } user { "test1": shell => "/bin/bash", managehome => true, } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 end shell('su - test1 -c \'psql -U test1 -c "\q" test1\'') do |r| r.exit_code.should == 2 end end it 'should fail catalogue if postgresql::server::manage_pga_conf is disabled' do pp = <<-EOS.unindent class { 'postgresql::server': manage_pg_hba_conf => false, } postgresql::server::pg_hba_rule { 'foo': type => "local", database => "test1", user => "test1", auth_method => reject, order => '001', } EOS puppet_apply(pp) do |r| r.exit_code.should == 1 end end end puppetlabs-postgresql-3.2.0/spec/system/server/plperl_spec.rb000644 000765 000024 00000001442 12236260460 025321 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'server plperl:' do after :all do # Cleanup after tests have ran pp = <<-EOS.unindent class { 'postgresql::server': ensure => absent } class { 'postgresql::server::plperl': package_ensure => purged } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 end end it 'test loading class with no parameters' do pending('no support for plperl with default version on centos 5', :if => (node.facts['osfamily'] == 'RedHat' and node.facts['lsbmajdistrelease'] == '5')) pp = <<-EOS.unindent class { 'postgresql::server': } class { 'postgresql::server::plperl': } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end end end puppetlabs-postgresql-3.2.0/spec/system/server/role_spec.rb000644 000765 000024 00000005253 12236260460 024770 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::server::role:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'should idempotently create a user who can log in' do pp = <<-EOS.unindent $user = "postgresql_test_user" $password = "postgresql_test_password" class { 'postgresql::server': } # Since we are not testing pg_hba or any of that, make a local user for ident auth user { $user: ensure => present, } postgresql::server::role { $user: password_hash => postgresql_password($user, $password), } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end # Check that the user can log in psql('--command="select datname from pg_database" postgres', 'postgresql_test_user') do |r| r.stdout.should =~ /template1/ r.stderr.should == '' r.exit_code.should == 0 end end it 'should idempotently alter a user who can log in' do pp = <<-EOS.unindent $user = "postgresql_test_user" $password = "postgresql_test_password2" class { 'postgresql::server': } # Since we are not testing pg_hba or any of that, make a local user for ident auth user { $user: ensure => present, } postgresql::server::role { $user: password_hash => postgresql_password($user, $password), } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end # Check that the user can log in psql('--command="select datname from pg_database" postgres', 'postgresql_test_user') do |r| r.stdout.should =~ /template1/ r.stderr.should == '' r.exit_code.should == 0 end end it 'should idempotently create a user with a cleartext password' do pp = <<-EOS.unindent $user = "postgresql_test_user2" $password = "postgresql_test_password2" class { 'postgresql::server': } # Since we are not testing pg_hba or any of that, make a local user for ident auth user { $user: ensure => present, } postgresql::server::role { $user: password_hash => $password, } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end # Check that the user can log in psql('--command="select datname from pg_database" postgres', 'postgresql_test_user2') do |r| r.stdout.should =~ /template1/ r.stderr.should == '' r.exit_code.should == 0 end end end puppetlabs-postgresql-3.2.0/spec/system/server/table_grant_spec.rb000644 000765 000024 00000004145 12236260460 026310 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::server::table_grant:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'should grant access so a user can insert in a table' do begin pp = <<-EOS.unindent $db = 'table_grant' $user = 'psql_grant_tester' $password = 'psql_table_pw' class { 'postgresql::server': } # Since we are not testing pg_hba or any of that, make a local user for ident auth user { $user: ensure => present, } postgresql::server::role { $user: password_hash => postgresql_password($user, $password), } postgresql::server::database { $db: } # Create a rule for the user postgresql::server::pg_hba_rule { "allow ${user}": type => 'local', database => $db, user => $user, auth_method => 'ident', order => 1, } postgresql_psql { 'Create testing table': command => 'CREATE TABLE "test_table" (field integer NOT NULL)', db => $db, unless => "SELECT * FROM pg_tables WHERE tablename = 'test_table'", require => Postgresql::Server::Database[$db], } postgresql::server::table_grant { 'grant insert test': privilege => 'INSERT', table => 'test_table', db => $db, role => $user, require => Postgresql_psql['Create testing table'], } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end ## Check that the user can create a table in the database psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r| r.stdout.should =~ /CREATE TABLE/ r.stderr.should be_empty r.exit_code.should == 0 end ensure psql('--command="drop table foo" postgres', 'psql_grant_tester') end end end puppetlabs-postgresql-3.2.0/spec/system/server/tablespace_spec.rb000644 000765 000024 00000004657 12236260460 026141 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::server::tablespace:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::server': ensure => absent }") do |r| r.exit_code.should_not == 1 end end it 'should idempotently create tablespaces and databases that are using them' do pp = <<-EOS.unindent class { 'postgresql::server': } file { '/tmp/pg_tablespaces': ensure => 'directory', owner => 'postgres', group => 'postgres', mode => '0700', }~> # This works around rubies that lack Selinux support, I'm looking at you RHEL5 exec { "chcon -u system_u -r object_r -t postgresql_db_t /tmp/pg_tablespaces": refreshonly => true, path => "/bin:/usr/bin", onlyif => "which chcon", before => File["/tmp/pg_tablespaces/space1", "/tmp/pg_tablespaces/space2"] } postgresql::server::tablespace { 'tablespace1': location => '/tmp/pg_tablespaces/space1', } postgresql::server::database { 'tablespacedb1': encoding => 'utf8', tablespace => 'tablespace1', } postgresql::server::db { 'tablespacedb2': user => 'dbuser2', password => postgresql_password('dbuser2', 'dbuser2'), tablespace => 'tablespace1', } postgresql::server::role { 'spcuser': password_hash => postgresql_password('spcuser', 'spcuser'), } postgresql::server::tablespace { 'tablespace2': location => '/tmp/pg_tablespaces/space2', owner => 'spcuser', } postgresql::server::database { 'tablespacedb3': encoding => 'utf8', tablespace => 'tablespace2', } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end # Check that databases use correct tablespaces psql('--command="select ts.spcname from pg_database db, pg_tablespace ts where db.dattablespace = ts.oid and db.datname = \'"\'tablespacedb1\'"\'"') do |r| r.stdout.should =~ /tablespace1/ r.stderr.should == '' r.exit_code.should == 0 end psql('--command="select ts.spcname from pg_database db, pg_tablespace ts where db.dattablespace = ts.oid and db.datname = \'"\'tablespacedb3\'"\'"') do |r| r.stdout.should =~ /tablespace2/ r.stderr.should == '' r.exit_code.should == 0 end end end puppetlabs-postgresql-3.2.0/spec/system/lib/devel_spec.rb000644 000765 000024 00000000772 12236260460 024367 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::lib::devel:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::lib::devel': package_ensure => purged }") do |r| r.exit_code.should_not == 1 end end it 'test loading class with no parameters' do pp = <<-EOS.unindent class { 'postgresql::lib::devel': } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end end end puppetlabs-postgresql-3.2.0/spec/system/lib/java_spec.rb000644 000765 000024 00000001301 12236260460 024176 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::lib::java:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::lib::java': package_ensure => purged }") do |r| r.exit_code.should_not == 1 end end it 'test loading class with no parameters' do pending('libpostgresql-java-jdbc not available natively for Ubuntu 10.04 and Debian 6', :if => (node.facts['osfamily'] == 'Debian' and ['6', '10'].include?(node.facts['lsbmajdistrelease']))) pp = <<-EOS.unindent class { 'postgresql::lib::java': } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end end end puppetlabs-postgresql-3.2.0/spec/system/lib/python_spec.rb000644 000765 000024 00000001222 12236260460 024600 0ustar00apenneystaff000000 000000 require 'spec_helper_system' describe 'postgresql::lib::python:' do after :all do # Cleanup after tests have ran puppet_apply("class { 'postgresql::lib::python': package_ensure => purged }") do |r| r.exit_code.should_not == 1 end end it 'test loading class with no parameters' do pending('psycopg2 not available natively for centos 5', :if => (node.facts['osfamily'] == 'RedHat' and node.facts['lsbmajdistrelease'] == '5')) pp = <<-EOS.unindent class { 'postgresql::lib::python': } EOS puppet_apply(pp) do |r| r.exit_code.should_not == 1 r.refresh r.exit_code.should == 0 end end end puppetlabs-postgresql-3.2.0/spec/fixtures/manifests/000755 000765 000024 00000000000 12236260460 023473 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/spec/fixtures/modules/000755 000765 000024 00000000000 12236260460 023152 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/manifests/client.pp000644 000765 000024 00000001405 12236260460 022507 0ustar00apenneystaff000000 000000 # Install client cli tool. See README.md for more details. class postgresql::client ( $package_name = $postgresql::params::client_package_name, $package_ensure = 'present' ) inherits postgresql::params { validate_string($package_name) package { 'postgresql-client': ensure => $package_ensure, name => $package_name, tag => 'postgresql', } $file_ensure = $package_ensure ? { 'present' => 'file', true => 'file', 'absent' => 'absent', false => 'absent', default => 'file', } file { "/usr/local/bin/validate_postgresql_connection.sh": ensure => $file_ensure, source => "puppet:///modules/postgresql/validate_postgresql_connection.sh", owner => 0, group => 0, mode => 0755, } } puppetlabs-postgresql-3.2.0/manifests/globals.pp000644 000765 000024 00000005000 12236260460 022647 0ustar00apenneystaff000000 000000 # Class for setting cross-class global overrides. See README.md for more # details. class postgresql::globals ( $ensure = undef, $client_package_name = undef, $server_package_name = undef, $contrib_package_name = undef, $devel_package_name = undef, $java_package_name = undef, $plperl_package_name = undef, $python_package_name = undef, $service_name = undef, $service_provider = undef, $service_status = undef, $default_database = undef, $initdb_path = undef, $createdb_path = undef, $psql_path = undef, $pg_hba_conf_path = undef, $postgresql_conf_path = undef, $pg_hba_conf_defaults = undef, $datadir = undef, $confdir = undef, $bindir = undef, $user = undef, $group = undef, $version = undef, $needs_initdb = undef, $encoding = undef, $locale = undef, $manage_firewall = undef, $manage_pg_hba_conf = undef, $firewall_supported = undef, $manage_package_repo = undef ) { # We are determining this here, because it is needed by the package repo # class. $default_version = $::osfamily ? { /^(RedHat|Linux)/ => $::operatingsystem ? { 'Fedora' => $::operatingsystemrelease ? { /^(18|19|20)$/ => '9.2', /^(17)$/ => '9.1', default => undef, }, 'Amazon' => '9.2', default => $::operatingsystemrelease ? { /^6\./ => '8.4', /^5\./ => '8.1', default => undef, }, }, 'Debian' => $::operatingsystem ? { 'Debian' => $::operatingsystemrelease ? { /^6\./ => '8.4', /^(wheezy|7\.)/ => '9.1', default => undef, }, 'Ubuntu' => $::operatingsystemrelease ? { /^(14.04)$/ => '9.3', /^(11.10|12.04|12.10|13.04|13.10)$/ => '9.1', /^(10.04|10.10|11.04)$/ => '8.4', default => undef, }, default => undef, }, 'Archlinux' => $::operatingsystem ? { /Archlinux/ => '9.2', default => '9.2', }, default => undef, } $globals_version = pick($version, $default_version, 'unknown') if($globals_version == 'unknown') { fail('No preferred version defined or automatically detected.') } # Setup of the repo only makes sense globally, so we are doing this here. if($manage_package_repo) { class { 'postgresql::repo': ensure => $ensure, version => $globals_version } } } puppetlabs-postgresql-3.2.0/manifests/lib/000755 000765 000024 00000000000 12236260460 021436 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/manifests/params.pp000644 000765 000024 00000017425 12236260460 022525 0ustar00apenneystaff000000 000000 # PRIVATE CLASS: do not use directly class postgresql::params inherits postgresql::globals { $ensure = true $version = $globals_version $listen_addresses = 'localhost' $ip_mask_deny_postgres_user = '0.0.0.0/0' $ip_mask_allow_all_users = '127.0.0.1/32' $ipv4acls = [] $ipv6acls = [] $user = pick($user, 'postgres') $group = pick($group, 'postgres') $encoding = $encoding $locale = $locale $service_provider = $service_provider $manage_firewall = $manage_firewall $manage_pg_hba_conf = pick($manage_pg_hba_conf, true) # Amazon Linux's OS Family is 'Linux', operating system 'Amazon'. case $::osfamily { 'RedHat', 'Linux': { $needs_initdb = pick($needs_initdb, true) $firewall_supported = pick($firewall_supported, true) if $version == $default_version { $client_package_name = pick($client_package_name, 'postgresql') $server_package_name = pick($server_package_name, 'postgresql-server') $contrib_package_name = pick($contrib_package_name,'postgresql-contrib') $devel_package_name = pick($devel_package_name, 'postgresql-devel') $java_package_name = pick($java_package_name, 'postgresql-jdbc') $plperl_package_name = pick($plperl_package_name, 'postgresql-plperl') $service_name = pick($service_name, 'postgresql') $bindir = pick($bindir, '/usr/bin') $datadir = $::operatingsystem ? { 'Amazon' => pick($datadir, '/var/lib/pgsql9/data'), default => pick($datadir, '/var/lib/pgsql/data'), } $confdir = pick($confdir, $datadir) } else { $version_parts = split($version, '[.]') $package_version = "${version_parts[0]}${version_parts[1]}" $client_package_name = pick($client_package_name, "postgresql${package_version}") $server_package_name = pick($server_package_name, "postgresql${package_version}-server") $contrib_package_name = pick($contrib_package_name,"postgresql${package_version}-contrib") $devel_package_name = pick($devel_package_name, "postgresql${package_version}-devel") $java_package_name = pick($java_package_name, "postgresql${package_version}-jdbc") $plperl_package_name = pick($plperl_package_name, "postgresql${package_version}-plperl") $service_name = pick($service_name, "postgresql-${version}") $bindir = pick($bindir, "/usr/pgsql-${version}/bin") $datadir = $::operatingsystem ? { 'Amazon' => pick($datadir, "/var/lib/pgsql9/${version}/data"), default => pick($datadir, "/var/lib/pgsql/${version}/data"), } $confdir = pick($confdir, $datadir) } $psql_path = pick($psql_path, "${bindir}/psql") $service_status = $service_status $python_package_name = pick($python_package_name, 'python-psycopg2') } 'Archlinux': { # Based on the existing version of the firewall module, this is normally # true for Archlinux, but archlinux users want more control. # so they can set it themself $firewall_supported = pick($firewall_supported, true) $needs_initdb = pick($needs_initdb, true) # Archlinux doesn't have a client-package but has a libs package which # pulls in postgresql server $client_package_name = pick($client_package_name, 'postgresql') $server_package_name = pick($server_package_name, 'postgresql-libs') $java_package_name = pick($java_package_name, 'postgresql-jdbc') # Archlinux doesn't have develop packages $devel_package_name = pick($devel_package_name, 'postgresql-devel') # Archlinux does have postgresql-contrib but it isn't maintained $contrib_package_name = pick($contrib_package_name,'undef') # Archlinux postgresql package provides plperl $plperl_package_name = pick($plperl_package_name, 'undef') $service_name = pick($service_name, 'postgresql') $bindir = pick($bindir, '/usr/bin') $datadir = pick($datadir, '/var/lib/postgres/data') $confdir = pick($confdir, $datadir) $psql_path = pick($psql_path, "${bindir}/psql") $service_status = $service_status $python_package_name = pick($python_package_name, 'python-psycopg2') } 'Debian': { if $manage_package_repo == true { $needs_initdb = pick($needs_initdb, true) $service_name = pick($service_name, 'postgresql') } else { $needs_initdb = pick($needs_initdb, false) $service_name = $::operatingsystem ? { 'Debian' => pick($service_name, 'postgresql'), 'Ubuntu' => $::lsbmajdistrelease ? { '10' => pick($service_name, "postgresql-${version}"), default => pick($service_name, 'postgresql'), }, default => undef } } $client_package_name = pick($client_package_name, "postgresql-client-${version}") $server_package_name = pick($server_package_name, "postgresql-${version}") $contrib_package_name = pick($contrib_package_name, "postgresql-contrib-${version}") $devel_package_name = pick($devel_package_name, 'libpq-dev') $java_package_name = pick($java_package_name, 'libpostgresql-jdbc-java') $plperl_package_name = pick($plperl_package_name, "postgresql-plperl-${version}") $python_package_name = pick($python_package_name, 'python-psycopg2') $bindir = pick($bindir, "/usr/lib/postgresql/${version}/bin") $datadir = pick($datadir, "/var/lib/postgresql/${version}/main") $confdir = pick($confdir, "/etc/postgresql/${version}/main") $service_status = pick($service_status, "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+|online'") $psql_path = pick($psql_path, "/usr/bin/psql") $firewall_supported = pick($firewall_supported, true) } default: { # Based on the existing version of the firewall module, this is normally # false for other OS, but this allows an escape hatch to override it. $firewall_supported = pick($firewall_supported, false) $psql_path = pick($psql_path, "${bindir}/psql") # Since we can't determine defaults on our own, we rely on users setting # parameters with the postgresql::globals class. Here we are checking # that the mandatory minimum is set for the module to operate. $err_prefix = "Module ${module_name} does not provide defaults for osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}; please specify a value for ${module_name}::globals::" if ($needs_initdb == undef) { fail("${err_prefix}needs_initdb") } if ($service_name == undef) { fail("${err_prefix}service_name") } if ($client_package_name == undef) { fail("${err_prefix}client_package_name") } if ($server_package_name == undef) { fail("${err_prefix}server_package_name") } if ($bindir == undef) { fail("${err_prefix}bindir") } if ($datadir == undef) { fail("${err_prefix}datadir") } if ($confdir == undef) { fail("${err_prefix}confdir") } } } $initdb_path = pick($initdb_path, "${bindir}/initdb") $createdb_path = pick($createdb_path, "${bindir}/createdb") $pg_hba_conf_path = pick($pg_hba_conf_path, "${confdir}/pg_hba.conf") $pg_hba_conf_defaults = pick($pg_hba_conf_defaults, true) $postgresql_conf_path = pick($postgresql_conf_path, "${confdir}/postgresql.conf") $default_database = pick($default_database, 'postgres') } puppetlabs-postgresql-3.2.0/manifests/repo/000755 000765 000024 00000000000 12236260460 021635 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/manifests/repo.pp000644 000765 000024 00000001354 12236260460 022201 0ustar00apenneystaff000000 000000 # PRIVATE CLASS: do not use directly class postgresql::repo ( $ensure = $postgresql::params::ensure, $version = undef ) inherits postgresql::params { case $::osfamily { 'RedHat', 'Linux': { if $version == undef { fail("The parameter 'version' for 'postgresql::repo' is undefined. You must always define it when osfamily == Redhat or Linux") } class { 'postgresql::repo::yum_postgresql_org': } } 'Debian': { class { 'postgresql::repo::apt_postgresql_org': } } default: { fail("Unsupported managed repository for osfamily: ${::osfamily}, operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports managing repos for osfamily RedHat and Debian") } } } puppetlabs-postgresql-3.2.0/manifests/server/000755 000765 000024 00000000000 12236260460 022176 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/manifests/server.pp000644 000765 000024 00000005505 12236260460 022544 0ustar00apenneystaff000000 000000 # This installs a PostgreSQL server. See README.md for more details. class postgresql::server ( $ensure = $postgresql::params::ensure, $version = $postgresql::params::version, $postgres_password = undef, $package_name = $postgresql::params::server_package_name, $package_ensure = $ensure, $plperl_package_name = $postgresql::params::plperl_package_name, $service_name = $postgresql::params::service_name, $service_provider = $postgresql::params::service_provider, $service_status = $postgresql::params::service_status, $default_database = $postgresql::params::default_database, $listen_addresses = $postgresql::params::listen_addresses, $ip_mask_deny_postgres_user = $postgresql::params::ip_mask_deny_postgres_user, $ip_mask_allow_all_users = $postgresql::params::ip_mask_allow_all_users, $ipv4acls = $postgresql::params::ipv4acls, $ipv6acls = $postgresql::params::ipv6acls, $initdb_path = $postgresql::params::initdb_path, $createdb_path = $postgresql::params::createdb_path, $psql_path = $postgresql::params::psql_path, $pg_hba_conf_path = $postgresql::params::pg_hba_conf_path, $postgresql_conf_path = $postgresql::params::postgresql_conf_path, $datadir = $postgresql::params::datadir, $pg_hba_conf_defaults = $postgresql::params::pg_hba_conf_defaults, $user = $postgresql::params::user, $group = $postgresql::params::group, $needs_initdb = $postgresql::params::needs_initdb, $encoding = $postgresql::params::encoding, $locale = $postgresql::params::locale, $manage_firewall = $postgresql::params::manage_firewall, $manage_pg_hba_conf = $postgresql::params::manage_pg_hba_conf, $firewall_supported = $postgresql::params::firewall_supported ) inherits postgresql::params { $pg = 'postgresql::server' if ($ensure == 'present' or $ensure == true) { # Reload has its own ordering, specified by other defines class { "${pg}::reload": require => Class["${pg}::install"] } anchor { "${pg}::start": }-> class { "${pg}::install": }-> class { "${pg}::initdb": }-> class { "${pg}::config": }-> class { "${pg}::service": }-> class { "${pg}::passwd": }-> class { "${pg}::firewall": }-> anchor { "${pg}::end": } } else { anchor { "${pg}::start": }-> class { "${pg}::firewall": }-> class { "${pg}::passwd": }-> class { "${pg}::service": }-> class { "${pg}::install": }-> class { "${pg}::initdb": }-> class { "${pg}::config": }-> anchor { "${pg}::end": } } } puppetlabs-postgresql-3.2.0/manifests/validate_db_connection.pp000644 000765 000024 00000005177 12236260460 025720 0ustar00apenneystaff000000 000000 # This type validates that a successful postgres connection can be established # between the node on which this resource is run and a specified postgres # instance (host/port/user/password/database name). # # See README.md for more details. define postgresql::validate_db_connection( $database_host = undef, $database_name = undef, $database_password = undef, $database_username = undef, $database_port = undef, $run_as = undef, $sleep = 2, $tries = 10, $create_db_first = true ) { require postgresql::client include postgresql::params $psql_path = $postgresql::params::psql_path $cmd_init = "${psql_path} --tuples-only --quiet " $cmd_host = $database_host ? { default => "-h ${database_host} ", undef => "", } $cmd_user = $database_username ? { default => "-U ${database_username} ", undef => "", } $cmd_port = $database_port ? { default => "-p ${database_port} ", undef => "", } $cmd_dbname = $database_name ? { default => "--dbname ${database_name} ", undef => "--dbname ${postgresql::params::default_database} ", } $env = $database_password ? { default => "PGPASSWORD=${database_password}", undef => undef, } $cmd = join([$cmd_init, $cmd_host, $cmd_user, $cmd_port, $cmd_dbname]) $validate_cmd = "/usr/local/bin/validate_postgresql_connection.sh ${sleep} ${tries} '${cmd}'" # This is more of a safety valve, we add a little extra to compensate for the # time it takes to run each psql command. $timeout = (($sleep + 2) * $tries) $exec_name = "validate postgres connection for ${database_host}/${database_name}" exec { $exec_name: command => "echo 'Unable to connect to defined database using: ${cmd}' && false", unless => $validate_cmd, cwd => '/tmp', environment => $env, logoutput => 'on_failure', user => $run_as, path => '/bin', timeout => $timeout, require => Package['postgresql-client'], } # This is a little bit of puppet magic. What we want to do here is make # sure that if the validation and the database instance creation are being # applied on the same machine, then the database resource is applied *before* # the validation resource. Otherwise, the validation is guaranteed to fail # on the first run. # # We accomplish this by using Puppet's resource collection syntax to search # for the Database resource in our current catalog; if it exists, the # appropriate relationship is created here. if($create_db_first) { Postgresql::Server::Database<|title == $database_name|> -> Exec[$exec_name] } } puppetlabs-postgresql-3.2.0/manifests/server/.grant.pp.swp000644 000765 000024 00000030000 12236260460 024531 0ustar00apenneystaff000000 000000 b0VIM 7.4KRw5apenneyAshleys-MacBook-Pro.local~apenney/modules/puppetlabs-postgresql/manifests/server/grant.pp 3210#"! UtpQadaQiL6 f? y h L = ,  E + a 2   d  < _9 lN4}yx4gca`} } Postgresql::Server::Database[$db]->Postgresql_psql[$grant_cmd] if($db != undef and defined(Postgresql::Server::Database[$db])) { } Postgresql::Server::Role[$role]->Postgresql_psql[$grant_cmd] if($role != undef and defined(Postgresql::Server::Role[$role])) { } require => Class['postgresql::server'] unless => "SELECT 1 WHERE ${unless_function}('${role}', '${object_name}', '${unless_privilege}')", psql_path => $psql_path, psql_group => $group, psql_user => $psql_user, db => $on_db, postgresql_psql { $grant_cmd: $grant_cmd = "GRANT ${_privilege} ON ${_object_type} \"${object_name}\" TO \"${role}\"" } default => $_privilege, 'ALL' => 'CREATE', $unless_privilege = $_privilege ? { # then they have "ALL". (I told you that it was terrible!) # just going to assume that if they have "CREATE" privileges on a database, # probably need to wait until we port this over to ruby, so, for now, we're # it entails, and loop over them to check them. That sort of thing will # hard-code a mapping between 'ALL' and the list of actual privileges that # recognize 'ALL' as a valid privilege name. So we probably need to # we need a way to test for it--and has_database_privilege does not # TODO: this is a terrible hack; if they pass "ALL" as the desired privilege, } } fail("Missing privilege validation for object type ${_object_type}") default: { } $on_db = $db $unless_function = 'has_table_privilege' 'ALL','ALL PRIVILEGES') validate_string($_privilege,'SELECT','INSERT','UPDATE','REFERENCES', 'TABLE': { } $on_db = $psql_db $unless_function = 'has_database_privilege' 'ALL PRIVILEGES') validate_string($_privilege,'CREATE','CONNECT','TEMPORARY','TEMP','ALL', 'DATABASE': { case $_object_type { ## Validate that the object type's privilege is acceptable ) #'VIEW', #'TABLESPACE', 'TABLE', #'SEQUENCE', #'SCHEMA', #'PROCEDURAL LANGUAGE', #'FUNCTION', #'FOREIGN DATA WRAPPER', #'FOREIGN SERVER', 'DATABASE', #'COLUMN', validate_string($_object_type, ## Validate that the object type is known $_privilege = upcase($privilege) $_object_type = upcase($object_type) ## Munge the input values $psql_path = $postgresql::server::psql_path $group = $postgresql::server::group) { $psql_user = $postgresql::server::user $psql_db = $postgresql::server::user, $object_name = $db, $object_type = 'database', $privilege = undef, $db, $role,define postgresql::server::grant (# Define for granting permissions to roles. See README.md for more details.puppetlabs-postgresql-3.2.0/manifests/server/config.pp000644 000765 000024 00000010104 12236260460 024000 0ustar00apenneystaff000000 000000 # PRIVATE CLASS: do not call directly class postgresql::server::config { $ensure = $postgresql::server::ensure $ip_mask_deny_postgres_user = $postgresql::server::ip_mask_deny_postgres_user $ip_mask_allow_all_users = $postgresql::server::ip_mask_allow_all_users $listen_addresses = $postgresql::server::listen_addresses $ipv4acls = $postgresql::server::ipv4acls $ipv6acls = $postgresql::server::ipv6acls $pg_hba_conf_path = $postgresql::server::pg_hba_conf_path $postgresql_conf_path = $postgresql::server::postgresql_conf_path $pg_hba_conf_defaults = $postgresql::server::pg_hba_conf_defaults $user = $postgresql::server::user $group = $postgresql::server::group $version = $postgresql::server::version $manage_pg_hba_conf = $postgresql::server::manage_pg_hba_conf File { owner => $user, group => $group, } if ($ensure == 'present' or $ensure == true) { if ($manage_pg_hba_conf == true) { # Prepare the main pg_hba file concat { $pg_hba_conf_path: owner => 0, group => $group, mode => '0640', warn => true, notify => Class['postgresql::server::reload'], } if $pg_hba_conf_defaults { Postgresql::Server::Pg_hba_rule { database => 'all', user => 'all', } # Lets setup the base rules $local_auth_option = $version ? { '8.1' => 'sameuser', default => undef, } postgresql::server::pg_hba_rule { 'local access as postgres user': type => 'local', user => $user, auth_method => 'ident', auth_option => $local_auth_option, order => '001', } postgresql::server::pg_hba_rule { 'local access to database with same name': type => 'local', auth_method => 'ident', auth_option => $local_auth_option, order => '002', } postgresql::server::pg_hba_rule { 'allow localhost TCP access to postgresql user': type => 'host', user => $user, address => '127.0.0.1/32', auth_method => 'md5', order => '003', } postgresql::server::pg_hba_rule { 'deny access to postgresql user': type => 'host', user => $user, address => $ip_mask_deny_postgres_user, auth_method => 'reject', order => '004', } # ipv4acls are passed as an array of rule strings, here we transform # them into a resources hash, and pass the result to create_resources $ipv4acl_resources = postgresql_acls_to_resources_hash($ipv4acls, 'ipv4acls', 10) create_resources('postgresql::server::pg_hba_rule', $ipv4acl_resources) postgresql::server::pg_hba_rule { 'allow access to all users': type => 'host', address => $ip_mask_allow_all_users, auth_method => 'md5', order => '100', } postgresql::server::pg_hba_rule { 'allow access to ipv6 localhost': type => 'host', address => '::1/128', auth_method => 'md5', order => '101', } # ipv6acls are passed as an array of rule strings, here we transform # them into a resources hash, and pass the result to create_resources $ipv6acl_resources = postgresql_acls_to_resources_hash($ipv6acls, 'ipv6acls', 102) create_resources('postgresql::server::pg_hba_rule', $ipv6acl_resources) } } # We must set a "listen_addresses" line in the postgresql.conf if we # want to allow any connections from remote hosts. postgresql::server::config_entry { 'listen_addresses': value => $listen_addresses, } } else { file { $pg_hba_conf_path: ensure => absent, } file { $postgresql_conf_path: ensure => absent, } } } puppetlabs-postgresql-3.2.0/manifests/server/config_entry.pp000644 000765 000024 00000002672 12236260460 025234 0ustar00apenneystaff000000 000000 # Manage a postgresql.conf entry. See README.md for more details. define postgresql::server::config_entry ( $ensure = 'present', $value = undef, $path = false ) { $postgresql_conf_path = $postgresql::server::postgresql_conf_path $target = $path ? { false => $postgresql_conf_path, default => $path, } case $name { /data_directory|hba_file|ident_file|include|listen_addresses|port|max_connections|superuser_reserved_connections|unix_socket_directory|unix_socket_group|unix_socket_permissions|bonjour|bonjour_name|ssl|ssl_ciphers|shared_buffers|max_prepared_transactions|max_files_per_process|shared_preload_libraries|wal_level|wal_buffers|archive_mode|max_wal_senders|hot_standby|logging_collector|silent_mode|track_activity_query_size|autovacuum_max_workers|autovacuum_freeze_max_age|max_locks_per_transaction|max_pred_locks_per_transaction|restart_after_crash/: { Postgresql_conf { notify => Class['postgresql::server::service'], before => Class['postgresql::server::reload'], } } default: { Postgresql_conf { notify => Class['postgresql::server::reload'], } } } case $ensure { /present|absent/: { postgresql_conf { $name: ensure => $ensure, target => $target, value => $value, require => Class['postgresql::server::initdb'], } } default: { fail("Unknown value for ensure '${ensure}'.") } } } puppetlabs-postgresql-3.2.0/manifests/server/contrib.pp000644 000765 000024 00000001647 12236260460 024207 0ustar00apenneystaff000000 000000 # Install the contrib postgresql packaging. See README.md for more details. class postgresql::server::contrib ( $package_name = $postgresql::params::contrib_package_name, $package_ensure = 'present' ) inherits postgresql::params { validate_string($package_name) package { 'postgresql-contrib': ensure => $package_ensure, name => $package_name, tag => 'postgresql', } if($package_ensure == 'present' or $package_ensure == true) { anchor { 'postgresql::server::contrib::start': }-> Class['postgresql::server::install']-> Package['postgresql-contrib']-> Class['postgresql::server::service']-> anchor { 'postgresql::server::contrib::end': } } else { anchor { 'postgresql::server::contrib::start': }-> Class['postgresql::server::service']-> Package['postgresql-contrib']-> Class['postgresql::server::install']-> anchor { 'postgresql::server::contrib::end': } } } puppetlabs-postgresql-3.2.0/manifests/server/database.pp000644 000765 000024 00000004736 12236260460 024315 0ustar00apenneystaff000000 000000 # Define for creating a database. See README.md for more details. define postgresql::server::database( $dbname = $title, $owner = $postgresql::server::user, $tablespace = undef, $encoding = $postgresql::server::encoding, $locale = $postgresql::server::locale, $istemplate = false ) { $createdb_path = $postgresql::server::createdb_path $user = $postgresql::server::user $group = $postgresql::server::group $psql_path = $postgresql::server::psql_path $version = $postgresql::server::version # Set the defaults for the postgresql_psql resource Postgresql_psql { psql_user => $user, psql_group => $group, psql_path => $psql_path, } # Optionally set the locale switch. Older versions of createdb may not accept # --locale, so if the parameter is undefined its safer not to pass it. if ($version != '8.1') { $locale_option = $locale ? { undef => '', default => "--locale=${locale} ", } $public_revoke_privilege = 'CONNECT' } else { $locale_option = '' $public_revoke_privilege = 'ALL' } $encoding_option = $encoding ? { undef => '', default => "--encoding '${encoding}' ", } $tablespace_option = $tablespace ? { undef => '', default => "--tablespace='${tablespace}' ", } $createdb_command = "${createdb_path} --owner='${owner}' --template=template0 ${encoding_option}${locale_option}${tablespace_option} '${dbname}'" postgresql_psql { "Check for existence of db '${dbname}'": command => 'SELECT 1', unless => "SELECT datname FROM pg_database WHERE datname='${dbname}'", require => Class['postgresql::server::service'] }~> exec { $createdb_command : refreshonly => true, user => $user, logoutput => on_failure, }~> # This will prevent users from connecting to the database unless they've been # granted privileges. postgresql_psql {"REVOKE ${public_revoke_privilege} ON DATABASE \"${dbname}\" FROM public": db => $user, refreshonly => true, } Exec [ $createdb_command ]-> postgresql_psql {"UPDATE pg_database SET datistemplate = ${istemplate} WHERE datname = '${dbname}'": unless => "SELECT datname FROM pg_database WHERE datname = '${dbname}' AND datistemplate = ${istemplate}", } # Build up dependencies on tablespace if($tablespace != undef and defined(Postgresql::Server::Tablespace[$tablespace])) { Postgresql::Server::Tablespace[$tablespace]->Exec[$createdb_command] } } puppetlabs-postgresql-3.2.0/manifests/server/database_grant.pp000644 000765 000024 00000000657 12236260460 025506 0ustar00apenneystaff000000 000000 # Manage a database grant. See README.md for more details. define postgresql::server::database_grant( $privilege, $db, $role, $psql_db = undef, $psql_user = undef ) { postgresql::server::grant { "database:${name}": role => $role, db => $db, privilege => $privilege, object_type => 'DATABASE', object_name => $db, psql_db => $psql_db, psql_user => $psql_user, } } puppetlabs-postgresql-3.2.0/manifests/server/db.pp000644 000765 000024 00000001774 12236260460 023135 0ustar00apenneystaff000000 000000 # Define for conveniently creating a role, database and assigning the correct # permissions. See README.md for more details. define postgresql::server::db ( $user, $password, $encoding = $postgresql::server::encoding, $locale = $postgresql::server::locale, $grant = 'ALL', $tablespace = undef, $istemplate = false, $owner = undef ) { postgresql::server::database { $name: encoding => $encoding, tablespace => $tablespace, locale => $locale, istemplate => $istemplate, owner => $owner, } if ! defined(Postgresql::Server::Role[$user]) { postgresql::server::role { $user: password_hash => $password, } } postgresql::server::database_grant { "GRANT ${user} - ${grant} - ${name}": privilege => $grant, db => $name, role => $user, } if($tablespace != undef and defined(Postgresql::Server::Tablespace[$tablespace])) { Postgresql::Server::Tablespace[$tablespace]->Postgresql::Server::Database[$name] } } puppetlabs-postgresql-3.2.0/manifests/server/firewall.pp000644 000765 000024 00000001162 12236260460 024344 0ustar00apenneystaff000000 000000 # PRIVATE CLASS: do not use directly class postgresql::server::firewall { $ensure = $postgresql::server::ensure $manage_firewall = $postgresql::server::manage_firewall $firewall_supported = $postgresql::server::firewall_supported if ($manage_firewall and $firewall_supported) { if ($ensure == 'present' or $ensure == true) { # TODO: get rid of hard-coded port firewall { '5432 accept - postgres': port => '5432', proto => 'tcp', action => 'accept', } } else { firewall { '5432 accept - postgres': ensure => absent, } } } } puppetlabs-postgresql-3.2.0/manifests/server/grant.pp000644 000765 000024 00000005237 12236260460 023661 0ustar00apenneystaff000000 000000 # Define for granting permissions to roles. See README.md for more details. define postgresql::server::grant ( $role, $db, $privilege = undef, $object_type = 'database', $object_name = $db, $psql_db = $postgresql::server::user, $psql_user = $postgresql::server::user ) { $group = $postgresql::server::group $psql_path = $postgresql::server::psql_path ## Munge the input values $_object_type = upcase($object_type) $_privilege = upcase($privilege) ## Validate that the object type is known validate_string($_object_type, #'COLUMN', 'DATABASE', #'FOREIGN SERVER', #'FOREIGN DATA WRAPPER', #'FUNCTION', #'PROCEDURAL LANGUAGE', #'SCHEMA', #'SEQUENCE', 'TABLE', #'TABLESPACE', #'VIEW', ) ## Validate that the object type's privilege is acceptable case $_object_type { 'DATABASE': { validate_string($_privilege,'CREATE','CONNECT','TEMPORARY','TEMP','ALL', 'ALL PRIVILEGES') $unless_function = 'has_database_privilege' $on_db = $psql_db } 'TABLE': { validate_string($_privilege,'SELECT','INSERT','UPDATE','REFERENCES', 'ALL','ALL PRIVILEGES') $unless_function = 'has_table_privilege' $on_db = $db } default: { fail("Missing privilege validation for object type ${_object_type}") } } # TODO: this is a terrible hack; if they pass "ALL" as the desired privilege, # we need a way to test for it--and has_database_privilege does not # recognize 'ALL' as a valid privilege name. So we probably need to # hard-code a mapping between 'ALL' and the list of actual privileges that # it entails, and loop over them to check them. That sort of thing will # probably need to wait until we port this over to ruby, so, for now, we're # just going to assume that if they have "CREATE" privileges on a database, # then they have "ALL". (I told you that it was terrible!) $unless_privilege = $_privilege ? { 'ALL' => 'CREATE', default => $_privilege, } $grant_cmd = "GRANT ${_privilege} ON ${_object_type} \"${object_name}\" TO \"${role}\"" postgresql_psql { $grant_cmd: db => $on_db, psql_user => $psql_user, psql_group => $group, psql_path => $psql_path, unless => "SELECT 1 WHERE ${unless_function}('${role}', '${object_name}', '${unless_privilege}')", require => Class['postgresql::server'] } if($role != undef and defined(Postgresql::Server::Role[$role])) { Postgresql::Server::Role[$role]->Postgresql_psql[$grant_cmd] } if($db != undef and defined(Postgresql::Server::Database[$db])) { Postgresql::Server::Database[$db]->Postgresql_psql[$grant_cmd] } } puppetlabs-postgresql-3.2.0/manifests/server/initdb.pp000644 000765 000024 00000003325 12236260460 024013 0ustar00apenneystaff000000 000000 # PRIVATE CLASS: do not call directly class postgresql::server::initdb { $ensure = $postgresql::server::ensure $needs_initdb = $postgresql::server::needs_initdb $initdb_path = $postgresql::server::initdb_path $datadir = $postgresql::server::datadir $encoding = $postgresql::server::encoding $locale = $postgresql::server::locale $group = $postgresql::server::group $user = $postgresql::server::user if($ensure == 'present' or $ensure == true) { # Make sure the data directory exists, and has the correct permissions. file { $datadir: ensure => directory, owner => $user, group => $group, mode => '0700', } if($needs_initdb) { # Build up the initdb command. # # We optionally add the locale switch if specified. Older versions of the # initdb command don't accept this switch. So if the user didn't pass the # parameter, lets not pass the switch at all. $ic_base = "${initdb_path} --encoding '${encoding}' --pgdata '${datadir}'" $initdb_command = $locale ? { undef => $ic_base, default => "${ic_base} --locale '${locale}'" } # This runs the initdb command, we use the existance of the PG_VERSION # file to ensure we don't keep running this command. exec { 'postgresql_initdb': command => $initdb_command, creates => "${datadir}/PG_VERSION", user => $user, group => $group, logoutput => on_failure, before => File[$datadir], } } } else { # Purge data directory if ensure => absent file { $datadir: ensure => absent, recurse => true, force => true, } } } puppetlabs-postgresql-3.2.0/manifests/server/install.pp000644 000765 000024 00000003465 12236260460 024215 0ustar00apenneystaff000000 000000 # PRIVATE CLASS: do not call directly class postgresql::server::install { $package_ensure = $postgresql::server::package_ensure $package_name = $postgresql::server::package_name $client_package_name = $postgresql::server::client_package_name # This is necessary to ensure that the extra client package that was # installed automatically by the server package is removed and all # of its dependencies are removed also. Without this later installation # of the native Ubuntu packages will fail. if($::operatingsystem == 'Ubuntu' and $package_ensure == 'absent') { # This is an exec, because we want to invoke autoremove. # # An alternative would be to have a full list of packages, but that seemed # more problematic to maintain, not to mention the conflict with the # client class will create duplicate resources. exec { 'apt-get-autoremove-postgresql-client-XX': command => "apt-get autoremove --purge --yes ${client_package_name}", onlyif => "dpkg -l ${client_package_name} | grep -e '^ii'", logoutput => on_failure, path => '/usr/bin:/bin:/usr/sbin/:/sbin', } # This will clean up anything we miss exec { 'apt-get-autoremove-postgresql-client-brute': command => "dpkg -P postgresql*", onlyif => "dpkg -l postgresql* | grep -e '^ii'", logoutput => on_failure, path => '/usr/bin:/bin:/usr/sbin/:/sbin', } } $_package_ensure = $package_ensure ? { true => 'present', false => 'purged', 'absent' => 'purged', default => $package_ensure, } package { 'postgresql-server': ensure => $_package_ensure, name => $package_name, # This is searched for to create relationships with the package repos, be # careful about its removal tag => 'postgresql', } } puppetlabs-postgresql-3.2.0/manifests/server/passwd.pp000644 000765 000024 00000003052 12236260460 024040 0ustar00apenneystaff000000 000000 # PRIVATE CLASS: do not call directly class postgresql::server::passwd { $ensure = $postgresql::server::ensure $postgres_password = $postgresql::server::postgres_password $user = $postgresql::server::user $group = $postgresql::server::group if($ensure == 'present' or $ensure == true) { if ($postgres_password != undef) { # NOTE: this password-setting logic relies on the pg_hba.conf being # configured to allow the postgres system user to connect via psql # without specifying a password ('ident' or 'trust' security). This is # the default for pg_hba.conf. $escaped = postgresql_escape($postgres_password) $env = "env PGPASSWORD='${postgres_password}'" exec { 'set_postgres_postgrespw': # This command works w/no password because we run it as postgres system # user command => "psql -c 'ALTER ROLE \"${user}\" PASSWORD ${escaped}'", user => $user, group => $group, logoutput => true, cwd => '/tmp', # With this command we're passing -h to force TCP authentication, which # does require a password. We specify the password via the PGPASSWORD # environment variable. If the password is correct (current), this # command will exit with an exit code of 0, which will prevent the main # command from running. unless => "${env} psql -h localhost -c 'select 1' > /dev/null", path => '/usr/bin:/usr/local/bin:/bin', } } } } puppetlabs-postgresql-3.2.0/manifests/server/pg_hba_rule.pp000644 000765 000024 00000005153 12236260460 025012 0ustar00apenneystaff000000 000000 # This resource manages an individual rule that applies to the file defined in # $target. See README.md for more details. define postgresql::server::pg_hba_rule( $type, $database, $user, $auth_method, $address = undef, $description = 'none', $auth_option = undef, $order = '150', # Needed for testing primarily, support for multiple files is not really # working. $target = $postgresql::server::pg_hba_conf_path ) { if $postgresql::server::manage_pga_conf == false { fail('postgresql::server::manage_pga_conf has been disabled, so this resource is now unused and redundant, either enable that option or remove this resource from your manifests') } else { validate_re($type, '^(local|host|hostssl|hostnossl)$', "The type you specified [${type}] must be one of: local, host, hostssl, hostnosssl") if($type =~ /^host/ and $address == undef) { fail('You must specify an address property when type is host based') } $allowed_auth_methods = $postgresql::server::version ? { '9.3' => ['trust', 'reject', 'md5', 'sha1', 'password', 'gss', 'sspi', 'krb5', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam'], '9.2' => ['trust', 'reject', 'md5', 'sha1', 'password', 'gss', 'sspi', 'krb5', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam'], '9.1' => ['trust', 'reject', 'md5', 'sha1', 'password', 'gss', 'sspi', 'krb5', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam'], '9.0' => ['trust', 'reject', 'md5', 'sha1', 'password', 'gss', 'sspi', 'krb5', 'ident', 'ldap', 'radius', 'cert', 'pam'], '8.4' => ['trust', 'reject', 'md5', 'sha1', 'password', 'gss', 'sspi', 'krb5', 'ident', 'ldap', 'cert', 'pam'], '8.3' => ['trust', 'reject', 'md5', 'sha1', 'crypt', 'password', 'gss', 'sspi', 'krb5', 'ident', 'ldap', 'pam'], '8.2' => ['trust', 'reject', 'md5', 'crypt', 'password', 'krb5', 'ident', 'ldap', 'pam'], '8.1' => ['trust', 'reject', 'md5', 'crypt', 'password', 'krb5', 'ident', 'pam'], default => ['trust', 'reject', 'md5', 'password', 'gss', 'sspi', 'krb5', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam', 'crypt'] } $auth_method_regex = join(['^(', join($allowed_auth_methods, '|'), ')$'],'') validate_re($auth_method, $auth_method_regex, join(["The auth_method you specified [${auth_method}] must be one of: ", join($allowed_auth_methods, ', ')],'')) # Create a rule fragment $fragname = "pg_hba_rule_${name}" concat::fragment { $fragname: target => $target, content => template('postgresql/pg_hba_rule.conf'), order => $order, owner => $::id, mode => '0600', } } } puppetlabs-postgresql-3.2.0/manifests/server/plperl.pp000644 000765 000024 00000001574 12236260460 024044 0ustar00apenneystaff000000 000000 # This class installs the PL/Perl procedural language for postgresql. See # README.md for more details. class postgresql::server::plperl( $package_ensure = 'present', $package_name = $postgresql::server::plperl_package_name ) { package { 'postgresql-plperl': ensure => $package_ensure, name => $package_name, tag => 'postgresql', } if($package_ensure == 'present' or $package_ensure == true) { anchor { 'postgresql::server::plperl::start': }-> Class['postgresql::server::install']-> Package['postgresql-plperl']-> Class['postgresql::server::service']-> anchor { 'postgresql::server::plperl::end': } } else { anchor { 'postgresql::server::plperl::start': }-> Class['postgresql::server::service']-> Package['postgresql-plperl']-> Class['postgresql::server::install']-> anchor { 'postgresql::server::plperl::end': } } } puppetlabs-postgresql-3.2.0/manifests/server/reload.pp000644 000765 000024 00000000761 12236260460 024011 0ustar00apenneystaff000000 000000 # PRIVATE CLASS: do not use directly class postgresql::server::reload { $ensure = $postgresql::server::ensure $service_name = $postgresql::server::service_name $service_status = $postgresql::server::service_status if($ensure == 'present' or $ensure == true) { exec { 'postgresql_reload': path => '/usr/bin:/usr/sbin:/bin:/sbin', command => "service ${service_name} reload", onlyif => $service_status, refreshonly => true, } } } puppetlabs-postgresql-3.2.0/manifests/server/role.pp000644 000765 000024 00000006370 12236260460 023506 0ustar00apenneystaff000000 000000 # Define for creating a database role. See README.md for more information define postgresql::server::role( $password_hash = false, $createdb = false, $createrole = false, $db = $postgresql::server::user, $login = true, $superuser = false, $replication = false, $connection_limit = '-1', $username = $title ) { $psql_user = $postgresql::server::user $psql_group = $postgresql::server::group $psql_path = $postgresql::server::psql_path $version = $postgresql::server::version $login_sql = $login ? { true => 'LOGIN', default => 'NOLOGIN' } $createrole_sql = $createrole ? { true => 'CREATEROLE', default => 'NOCREATEROLE' } $createdb_sql = $createdb ? { true => 'CREATEDB', default => 'NOCREATEDB' } $superuser_sql = $superuser ? { true => 'SUPERUSER', default => 'NOSUPERUSER' } $replication_sql = $replication ? { true => 'REPLICATION', default => '' } if ($password_hash != false) { $password_sql = "ENCRYPTED PASSWORD '${password_hash}'" } else { $password_sql = '' } Postgresql_psql { db => $db, psql_user => $psql_user, psql_group => $psql_group, psql_path => $psql_path, require => [ Postgresql_psql["CREATE ROLE \"${username}\" ${password_sql} ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql} CONNECTION LIMIT ${connection_limit}"], Class['postgresql::server'] ], } postgresql_psql {"CREATE ROLE \"${username}\" ${password_sql} ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql} CONNECTION LIMIT ${connection_limit}": unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}'", require => Class['Postgresql::Server'], } postgresql_psql {"ALTER ROLE \"${username}\" ${superuser_sql}": unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolsuper=${superuser}", } postgresql_psql {"ALTER ROLE \"${username}\" ${createdb_sql}": unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolcreatedb=${createdb}", } postgresql_psql {"ALTER ROLE \"${username}\" ${createrole_sql}": unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolcreaterole=${createrole}", } postgresql_psql {"ALTER ROLE \"${username}\" ${login_sql}": unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolcanlogin=${login}", } if(versioncmp($version, '9.1') >= 0) { postgresql_psql {"ALTER ROLE \"${username}\" ${replication_sql}": unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolreplication=${replication}", } } postgresql_psql {"ALTER ROLE \"${username}\" CONNECTION LIMIT ${connection_limit}": unless => "SELECT rolname FROM pg_roles WHERE rolname='${username}' and rolconnlimit=${connection_limit}", } if $password_hash { if($password_hash =~ /^md5.+/) { $pwd_hash_sql = $password_hash } else { $pwd_md5 = md5("${password_hash}${username}") $pwd_hash_sql = "md5${pwd_md5}" } postgresql_psql {"ALTER ROLE \"${username}\" ${password_sql}": unless => "SELECT usename FROM pg_shadow WHERE usename='${username}' and passwd='${pwd_hash_sql}'", } } } puppetlabs-postgresql-3.2.0/manifests/server/service.pp000644 000765 000024 00000002446 12236260460 024205 0ustar00apenneystaff000000 000000 # PRIVATE CLASS: do not call directly class postgresql::server::service { $ensure = $postgresql::server::ensure $service_name = $postgresql::server::service_name $service_provider = $postgresql::server::service_provider $service_status = $postgresql::server::service_status $user = $postgresql::server::user $default_database = $postgresql::server::default_database $service_ensure = $ensure ? { present => true, absent => false, default => $ensure } service { 'postgresqld': ensure => $service_ensure, name => $service_name, enable => $service_ensure, provider => $service_provider, hasstatus => true, status => $service_status, } if($service_ensure) { # This blocks the class before continuing if chained correctly, making # sure the service really is 'up' before continuing. # # Without it, we may continue doing more work before the database is # prepared leading to a nasty race condition. postgresql::validate_db_connection { 'validate_service_is_running': run_as => $user, database_name => $default_database, sleep => 1, tries => 60, create_db_first => false, require => Service['postgresqld'], } } } puppetlabs-postgresql-3.2.0/manifests/server/table_grant.pp000644 000765 000024 00000000750 12236260460 025023 0ustar00apenneystaff000000 000000 # This resource wraps the grant resource to manage table grants specifically. # See README.md for more details. define postgresql::server::table_grant( $privilege, $table, $db, $role, $psql_db = undef, $psql_user = undef ) { postgresql::server::grant { "table:${name}": role => $role, db => $db, privilege => $privilege, object_type => 'TABLE', object_name => $table, psql_db => $psql_db, psql_user => $psql_user, } } puppetlabs-postgresql-3.2.0/manifests/server/tablespace.pp000644 000765 000024 00000002211 12236260460 024636 0ustar00apenneystaff000000 000000 # This module creates tablespace. See README.md for more details. define postgresql::server::tablespace( $location, $owner = undef, $spcname = $title ) { $user = $postgresql::server::user $group = $postgresql::server::group $psql_path = $postgresql::server::psql_path Postgresql_psql { psql_user => $user, psql_group => $group, psql_path => $psql_path, } if ($owner == undef) { $owner_section = '' } else { $owner_section = "OWNER \"${owner}\"" } $create_tablespace_command = "CREATE TABLESPACE \"${spcname}\" ${owner_section} LOCATION '${location}'" file { $location: ensure => directory, owner => $user, group => $group, mode => '0700', } $create_ts = "Create tablespace '${spcname}'" postgresql_psql { "Create tablespace '${spcname}'": command => $create_tablespace_command, unless => "SELECT spcname FROM pg_tablespace WHERE spcname='${spcname}'", require => [Class['postgresql::server'], File[$location]], } if($owner != undef and defined(Postgresql::Server::Role[$owner])) { Postgresql::Server::Role[$owner]->Postgresql_psql[$create_ts] } } puppetlabs-postgresql-3.2.0/manifests/repo/apt_postgresql_org.pp000644 000765 000024 00000001766 12236260460 026126 0ustar00apenneystaff000000 000000 # PRIVATE CLASS: do not use directly class postgresql::repo::apt_postgresql_org inherits postgresql::repo { if($ensure == 'present' or $ensure == true) { # Here we have tried to replicate the instructions on the PostgreSQL site: # # http://www.postgresql.org/download/linux/debian/ # apt::pin { 'apt.postgresql.org': originator => 'apt.postgresql.org', priority => 500, }-> apt::source { 'apt.postgresql.org': location => 'http://apt.postgresql.org/pub/repos/apt/', release => "${::lsbdistcodename}-pgdg", repos => "main ${version}", key => 'ACCC4CF8', key_source => 'http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc', include_src => false, } Apt::Source['apt.postgresql.org']->Package<|tag == 'postgresql'|> } else { apt::source { 'apt.postgresql.org': ensure => absent, } apt::pin { 'apt.postgresql.org': ensure => absent, } } } puppetlabs-postgresql-3.2.0/manifests/repo/yum_postgresql_org.pp000644 000765 000024 00000002245 12236260460 026145 0ustar00apenneystaff000000 000000 # PRIVATE CLASS: do not use directly class postgresql::repo::yum_postgresql_org inherits postgresql::repo { $version_parts = split($version, '[.]') $package_version = "${version_parts[0]}${version_parts[1]}" $gpg_key_path = "/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-${package_version}" if ($ensure == 'present' or $ensure == true) { file { $gpg_key_path: source => 'puppet:///modules/postgresql/RPM-GPG-KEY-PGDG', before => Yumrepo['yum.postgresql.org'] } if($::operatingsystem == 'Fedora') { $label1 = 'fedora' $label2 = $label1 } else { $label1 = 'redhat' $label2 = 'rhel' } yumrepo { 'yum.postgresql.org': descr => "PostgreSQL ${version} \$releasever - \$basearch", baseurl => "http://yum.postgresql.org/${version}/${label1}/${label2}-\$releasever-\$basearch", enabled => 1, gpgcheck => 1, gpgkey => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-${package_version}", } Yumrepo['yum.postgresql.org'] -> Package<|tag == 'postgresql'|> } else { yumrepo { 'yum.postgresql.org': enabled => absent, }-> file { $gpg_key_path: ensure => absent, } } } puppetlabs-postgresql-3.2.0/manifests/lib/devel.pp000644 000765 000024 00000000624 12236260460 023100 0ustar00apenneystaff000000 000000 # This class installs postgresql development libraries. See README.md for more # details. class postgresql::lib::devel( $package_name = $postgresql::params::devel_package_name, $package_ensure = 'present' ) inherits postgresql::params { validate_string($package_name) package { 'postgresql-devel': ensure => $package_ensure, name => $package_name, tag => 'postgresql', } } puppetlabs-postgresql-3.2.0/manifests/lib/java.pp000644 000765 000024 00000000564 12236260460 022725 0ustar00apenneystaff000000 000000 # This class installs the postgresql jdbc connector. See README.md for more # details. class postgresql::lib::java ( $package_name = $postgresql::params::java_package_name, $package_ensure = 'present' ) inherits postgresql::params { validate_string($package_name) package { 'postgresql-jdbc': ensure => $package_ensure, name => $package_name, } } puppetlabs-postgresql-3.2.0/manifests/lib/python.pp000644 000765 000024 00000000526 12236260460 023323 0ustar00apenneystaff000000 000000 # This class installs the python libs for postgresql. See README.md for more # details. class postgresql::lib::python( $package_name = $postgresql::params::python_package_name, $package_ensure = 'present' ) inherits postgresql::params { package { 'python-psycopg2': ensure => $package_ensure, name => $package_name, } } puppetlabs-postgresql-3.2.0/lib/puppet/000755 000765 000024 00000000000 12236260460 020762 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/lib/puppet/parser/000755 000765 000024 00000000000 12236260460 022256 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/lib/puppet/provider/000755 000765 000024 00000000000 12236260460 022614 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/lib/puppet/type/000755 000765 000024 00000000000 12236260460 021743 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/lib/puppet/type/postgresql_conf.rb000644 000765 000024 00000001221 12236260460 025474 0ustar00apenneystaff000000 000000 module Puppet newtype(:postgresql_conf) do @doc = "This type allows puppet to manage postgresql.conf parameters." ensurable newparam(:name) do desc "The postgresql parameter name to manage." isnamevar newvalues(/^[\w\.]+$/) end newproperty(:value) do desc "The value to set for this parameter." end newproperty(:target) do desc "The path to postgresql.conf" defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) @resource.class.defaultprovider.default_target else nil end } end end end puppetlabs-postgresql-3.2.0/lib/puppet/type/postgresql_psql.rb000644 000765 000024 00000005543 12236260460 025541 0ustar00apenneystaff000000 000000 Puppet::Type.newtype(:postgresql_psql) do newparam(:name) do desc "An arbitrary tag for your own reference; the name of the message." isnamevar end newproperty(:command) do desc 'The SQL command to execute via psql.' defaultto { @resource[:name] } def sync(refreshing = false) # We're overriding 'sync' here in order to do some magic # in support of providing a 'refreshonly' parameter. This # is kind of hacky because the logic for 'refreshonly' is # spread between the type and the provider, but this is # the least horrible way that I could determine to accomplish # it. # # Note that our overridden version of 'sync' takes a parameter, # 'refreshing', which the parent version doesn't take. This # allows us to call the sync method directly from the 'refresh' # method, and then inside of the body of 'sync' we can tell # whether or not we're refreshing. if (!@resource.refreshonly? || refreshing) # If we're not in 'refreshonly' mode, or we're not currently # refreshing, then we just call the parent method. super() else # If we get here, it means we're in 'refreshonly' mode and # we're not being called by the 'refresh' method, so we # just no-op. We'll be called again by the 'refresh' # method momentarily. nil end end end newparam(:unless) do desc "An optional SQL command to execute prior to the main :command; " + "this is generally intended to be used for idempotency, to check " + "for the existence of an object in the database to determine whether " + "or not the main SQL command needs to be executed at all." end newparam(:db) do desc "The name of the database to execute the SQL command against." end newparam(:search_path) do desc "The schema search path to use when executing the SQL command" end newparam(:psql_path) do desc "The path to psql executable." defaultto("psql") end newparam(:psql_user) do desc "The system user account under which the psql command should be executed." defaultto("postgres") end newparam(:psql_group) do desc "The system user group account under which the psql command should be executed." defaultto("postgres") end newparam(:cwd, :parent => Puppet::Parameter::Path) do desc "The working directory under which the psql command should be executed." defaultto("/tmp") end newparam(:refreshonly, :boolean => true) do desc "If 'true', then the SQL will only be executed via a notify/subscribe event." defaultto(:false) newvalues(:true, :false) end def refresh() # All of the magic for this type is attached to the ':command' property, so # we just need to sync it to accomplish a 'refresh'. self.property(:command).sync(true) end end puppetlabs-postgresql-3.2.0/lib/puppet/provider/postgresql_conf/000755 000765 000024 00000000000 12236260460 026024 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/lib/puppet/provider/postgresql_psql/000755 000765 000024 00000000000 12236260460 026056 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/lib/puppet/provider/postgresql_psql/ruby.rb000644 000765 000024 00000004432 12236260460 027367 0ustar00apenneystaff000000 000000 Puppet::Type.type(:postgresql_psql).provide(:ruby) do def command() if ((! resource[:unless]) or (resource[:unless].empty?)) if (resource.refreshonly?) # So, if there's no 'unless', and we're in "refreshonly" mode, # we need to return the target command here. If we don't, # then Puppet will generate an event indicating that this # property has changed. return resource[:command] end # if we're not in refreshonly mode, then we return nil, # which will cause Puppet to sync this property. This # is what we want if there is no 'unless' value specified. return nil end output, status = run_unless_sql_command(resource[:unless]) if status != 0 self.fail("Error evaluating 'unless' clause: '#{output}'") end result_count = output.strip.to_i if result_count > 0 # If the 'unless' query returned rows, then we don't want to execute # the 'command'. Returning the target 'command' here will cause # Puppet to treat this property as already being 'insync?', so it # won't call the setter to run the 'command' later. return resource[:command] end # Returning 'nil' here will cause Puppet to see this property # as out-of-sync, so it will call the setter later. nil end def command=(val) output, status = run_sql_command(val) if status != 0 self.fail("Error executing SQL; psql returned #{status}: '#{output}'") end end def run_unless_sql_command(sql) # for the 'unless' queries, we wrap the user's query in a 'SELECT COUNT', # which makes it easier to parse and process the output. run_sql_command('SELECT COUNT(*) FROM (' << sql << ') count') end def run_sql_command(sql) if resource[:search_path] sql = "set search_path to #{Array(resource[:search_path]).join(',')}; #{sql}" end command = [resource[:psql_path]] command.push("-d", resource[:db]) if resource[:db] command.push("-t", "-c", sql) if resource[:cwd] Dir.chdir resource[:cwd] do Puppet::Util::SUIDManager.run_and_capture(command, resource[:psql_user], resource[:psql_group]) end else Puppet::Util::SUIDManager.run_and_capture(command, resource[:psql_user], resource[:psql_group]) end end end puppetlabs-postgresql-3.2.0/lib/puppet/provider/postgresql_conf/parsed.rb000644 000765 000024 00000002252 12236260460 027630 0ustar00apenneystaff000000 000000 require 'puppet/provider/parsedfile' Puppet::Type.type(:postgresql_conf).provide( :parsed, :parent => Puppet::Provider::ParsedFile, :default_target => '/etc/postgresql.conf', :filetype => :flat ) do desc "Set key/values in postgresql.conf." text_line :comment, :match => /^\s*#/ text_line :blank, :match => /^\s*$/ record_line :parsed, :fields => %w{name value comment}, :optional => %w{comment}, :match => /^\s*([\w\.]+)\s*=?\s*(.*?)(?:\s*#\s*(.*))?\s*$/, :to_line => proc { |h| # simple string and numeric values don't need to be enclosed in quotes dontneedquote = h[:value].match(/^(\w+|[0-9.-]+)$/) dontneedequal = h[:name].match(/^(include|include_if_exists)$/i) str = h[:name].downcase # normalize case str += dontneedequal ? ' ' : ' = ' str += "'" unless dontneedquote && !dontneedequal str += h[:value] str += "'" unless dontneedquote && !dontneedequal str += " # #{h[:comment]}" unless (h[:comment].nil? or h[:comment] == :absent) str }, :post_parse => proc { |h| h[:name].downcase! # normalize case h[:value].gsub!(/(^'|'$)/, '') # strip out quotes } end puppetlabs-postgresql-3.2.0/lib/puppet/parser/functions/000755 000765 000024 00000000000 12236260460 024266 5ustar00apenneystaff000000 000000 puppetlabs-postgresql-3.2.0/lib/puppet/parser/functions/postgresql_acls_to_resources_hash.rb000644 000765 000024 00000005057 12236260460 033626 0ustar00apenneystaff000000 000000 module Puppet::Parser::Functions newfunction(:postgresql_acls_to_resources_hash, :type => :rvalue, :doc => <<-EOS This internal function translates the ipv(4|6)acls format into a resource suitable for create_resources. It is not intended to be used outside of the postgresql internal classes/defined resources. This function accepts an array of strings that are pg_hba.conf rules. It will return a hash that can be fed into create_resources to create multiple individual pg_hba_rule resources. The second parameter is an identifier that will be included in the namevar to provide uniqueness. It must be a string. The third parameter is an order offset, so you can start the order at an arbitrary starting point. EOS ) do |args| func_name = "postgresql_acls_to_resources_hash()" raise(Puppet::ParseError, "#{func_name}: Wrong number of arguments " + "given (#{args.size} for 3)") if args.size != 3 acls = args[0] raise(Puppet::ParseError, "#{func_name}: first argument must be an array") \ unless acls.instance_of? Array id = args[1] raise(Puppet::ParseError, "#{func_name}: second argument must be a string") \ unless id.instance_of? String offset = args[2].to_i raise(Puppet::ParseError, "#{func_name}: third argument must be a number") \ unless offset.instance_of? Fixnum resources = {} acls.each do |acl| index = acls.index(acl) parts = acl.split raise(Puppet::ParseError, "#{func_name}: acl line #{index} does not " + "have enough parts") unless parts.length >= 4 resource = { 'type' => parts[0], 'database' => parts[1], 'user' => parts[2], 'order' => format('%03d', offset + index), } if parts[0] == 'local' then resource['auth_method'] = parts[3] if parts.length > 4 then resource['auth_option'] = parts.last(parts.length - 4).join(" ") end else if parts[4] =~ /^\d/ resource['address'] = parts[3] + ' ' + parts[4] resource['auth_method'] = parts[5] if parts.length > 6 then resource['auth_option'] = parts.last(parts.length - 6).join(" ") end else resource['address'] = parts[3] resource['auth_method'] = parts[4] if parts.length > 5 then resource['auth_option'] = parts.last(parts.length - 5).join(" ") end end end resources["postgresql class generated rule #{id} #{index}"] = resource end resources end end puppetlabs-postgresql-3.2.0/lib/puppet/parser/functions/postgresql_escape.rb000644 000765 000024 00000001317 12236260460 030340 0ustar00apenneystaff000000 000000 require 'digest/md5' module Puppet::Parser::Functions newfunction(:postgresql_escape, :type => :rvalue, :doc => <<-EOS Safely escapes a string using $$ using a random tag which should be consistent EOS ) do |args| raise(Puppet::ParseError, "postgresql_escape(): Wrong number of arguments " + "given (#{args.size} for 1)") if args.size != 1 password = args[0] if password !~ /\$\$/ retval = "$$#{password}$$" else escape = Digest::MD5.hexdigest(password)[0..5].gsub(/\d/,'') until password !~ /#{escape}/ escape = Digest::MD5.hexdigest(escape)[0..5].gsub(/\d/,'') end retval = "$#{escape}$#{password}$#{escape}$" end retval end end puppetlabs-postgresql-3.2.0/lib/puppet/parser/functions/postgresql_password.rb000644 000765 000024 00000001035 12236260460 030737 0ustar00apenneystaff000000 000000 # hash a string as mysql's "PASSWORD()" function would do it require 'digest/md5' module Puppet::Parser::Functions newfunction(:postgresql_password, :type => :rvalue, :doc => <<-EOS Returns the postgresql password hash from the clear text username / password. EOS ) do |args| raise(Puppet::ParseError, "postgresql_password(): Wrong number of arguments " + "given (#{args.size} for 2)") if args.size != 2 username = args[0] password = args[1] 'md5' + Digest::MD5.hexdigest(password + username) end end puppetlabs-postgresql-3.2.0/files/RPM-GPG-KEY-PGDG000644 000765 000024 00000003276 12236260460 022152 0ustar00apenneystaff000000 000000 -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.4.7 (GNU/Linux) mQGiBEeD8koRBACC1VBRsUwGr9gxFFRho9kZpdRUjBJoPhkeOTvp9LzkdAQMFngr BFi6N0ov1kCX7LLwBmDG+JPR7N+XcH9YR1coSHpLVg+JNy2kFDd4zAyWxJafjZ3a 9zFg9Yx+0va1BJ2t4zVcmKS4aOfbgQ5KwIOWUujalQW5Y+Fw39Gn86qjbwCg5dIo tkM0l19h2sx50D027pV5aPsD/2c9pfcFTbMhB0CcKS836GH1qY+NCAdUwPs646ee Ex/k9Uy4qMwhl3HuCGGGa+N6Plyon7V0TzZuRGp/1742dE8IO+I/KLy2L1d1Fxrn XOTBZd8qe6nBwh12OMcKrsPBVBxn+iSkaG3ULsgOtx+HHLfa1/p22L5+GzGdxizr peBuA/90cCp+lYcEwdYaRoFVR501yDOTmmzBc1DrsyWP79QMEGzMqa393G0VnqXt L4pGmunq66Agw2EhPcIt3pDYiCmEt/obdVtSJH6BtmSDB/zYhbE8u3vLP3jfFDa9 KXxgtYj0NvuUVoRmxSKm8jtfmj1L7zoKNz3jl+Ba3L0WxIv4+bRBUG9zdGdyZVNR TCBSUE0gQnVpbGRpbmcgUHJvamVjdCA8cGdzcWxycG1zLWhhY2tlcnNAcGdmb3Vu ZHJ5Lm9yZz6IYAQTEQIAIAUCR4PySgIbIwYLCQgHAwIEFQIIAwQWAgMBAh4BAheA AAoJEB8W0uFELfD4jnkAoMqd6ZwwsgYHZ3hP9vt+DJt1uDW7AKDbRwP8ESKFhwdJ 8m91RPBeJW/tMLkCDQRHg/JKEAgA64+ZXgcERPYfZYo4p+yMTJAAa9aqnE3U4Ni6 ZMB57GPuEy8NfbNya+HiftO8hoozmJdcI6XFyRBCDUVCdZ8SE+PJdOx2FFqZVIu6 dKnr8ykhgLpNNEFDG3boK9UfLj/5lYQ3Y550Iym1QKOgyrJYeAp6sZ+Nx2PavsP3 nMFCSD67BqAbcLCVQN7a2dAUXfEbfXJjPHXTbo1/kxtzE+KCRTLdXEbSEe3nHO04 K/EgTBjeBUOxnciH5RylJ2oGy/v4xr9ed7R1jJtshsDKMdWApwoLlCBJ63jg/4T/ z/OtXmu4AvmWaJxaTl7fPf2GqSqqb6jLCrQAH7AIhXr9V0zPZwADBQgAlpptNQHl u7euIdIujFwwcxyQGfee6BG+3zaNSEHMVQMuc6bxuvYmgM9r7aki/b0YMfjJBk8v OJ3Eh1vDH/woJi2iJ13vQ21ot+1JP3fMd6NPR8/qEeDnmVXu7QAtlkmSKI9Rdnjz FFSUJrQPHnKsH4V4uvAM+njwYD+VFiwlBPTKNeL8cdBb4tPN2cdVJzoAp57wkZAN VA2tKxNsTJKBi8wukaLWX8+yPHiWCNWItvyB4WCEp/rZKG4A868NM5sZQMAabpLd l4fTiGu68OYgK9qUPZvhEAL2C1jPDVHPkLm+ZsD+90Pe66w9vB00cxXuHLzm8Pad GaCXCY8h3xi6VIhJBBgRAgAJBQJHg/JKAhsMAAoJEB8W0uFELfD4K4cAoJ4yug8y 1U0cZEiF5W25HDzMTtaDAKCaM1m3Cbd+AZ0NGWNg/VvIX9MsPA== =au6K -----END PGP PUBLIC KEY BLOCK----- puppetlabs-postgresql-3.2.0/files/validate_postgresql_connection.sh000644 000765 000024 00000000543 12236260460 026632 0ustar00apenneystaff000000 000000 #!/usr/bin/env bash # usage is: validate_db_connection 2 50 psql SLEEP=$1 TRIES=$2 PSQL=$3 STATE=1 for (( c=1; c<=$TRIES; c++ )) do echo $c if [ $c -gt 1 ] then echo 'sleeping' sleep $SLEEP fi /bin/echo "SELECT 1" | $PSQL STATE=$? if [ $STATE -eq 0 ] then exit 0 fi done echo 'Unable to connect to postgresql' exit 1