From 8b53003a16d1f80a6e3031a58f29b7bb60b264cd Mon Sep 17 00:00:00 2001 From: Tomas Pospisek Date: Tue, 9 Sep 2014 15:42:30 +0200 Subject: [PATCH 1/3] add __postgres_extension type --- .../type/__postgres_extension/gencode-remote | 39 ++++++++++++++ cdist/conf/type/__postgres_extension/man.text | 52 +++++++++++++++++++ .../parameter/default/state | 1 + .../__postgres_extension/parameter/optional | 1 + 4 files changed, 93 insertions(+) create mode 100755 cdist/conf/type/__postgres_extension/gencode-remote create mode 100644 cdist/conf/type/__postgres_extension/man.text create mode 100644 cdist/conf/type/__postgres_extension/parameter/default/state create mode 100644 cdist/conf/type/__postgres_extension/parameter/optional diff --git a/cdist/conf/type/__postgres_extension/gencode-remote b/cdist/conf/type/__postgres_extension/gencode-remote new file mode 100755 index 00000000..3408df86 --- /dev/null +++ b/cdist/conf/type/__postgres_extension/gencode-remote @@ -0,0 +1,39 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2013 Tomas Pospisek (tpo_deb at sourcepole.ch) +# +# This type was created by Tomas Pospisek based on the +#__postgres_role type by Steven Armstrong +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +dbname=$( echo "$__object_id" | cut -d":" -f1 ) +extension=$( echo "$__object_id" | cut -d":" -f2 ) + +state_should=$( cat "$__object/parameter/state" ) + +case "$state_should" in + present) + cmd="CREATE EXTENSION IF NOT EXISTS $extension" + echo "su - postgres -c 'psql -c \"$cmd\" \"$dbname\"'" + ;; + absent) + cmd="DROP EXTENSION IF EXISTS $extenstion" + echo "su - postgres -c 'psql -c \"$cmd\" \"$dbname\"'" + ;; +esac diff --git a/cdist/conf/type/__postgres_extension/man.text b/cdist/conf/type/__postgres_extension/man.text new file mode 100644 index 00000000..6d722d68 --- /dev/null +++ b/cdist/conf/type/__postgres_extension/man.text @@ -0,0 +1,52 @@ +cdist-type__postgres_extension(7) +================================= +Tomas Pospisek + + +NAME +---- +cdist-type__postgres_extension - manage postgres extensions + + +DESCRIPTION +----------- +This cdist type allows you to create or drop postgres extensions. + +The object you need to pass to __postgres_extension consists of +the database name and the extension name joined by a colon in the +following form: + + dbname:extension + +f.ex. + + rails_test:unaccent + + +OPTIONAL PARAMETERS +------------------- +state:: + Either "present" or "absent", defaults to "present" + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__postgres_extension rails_test:unaccent +__postgres_extension --present rails_test:unaccent +__postgres_extension --absent rails_test:unaccent +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__postgres_database(7) +- http://www.postgresql.org/docs/current/static/sql-createextension.html + + +COPYING +------- +Copyright \(C) 2014 Tomas Pospisek. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__postgres_extension/parameter/default/state b/cdist/conf/type/__postgres_extension/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__postgres_extension/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__postgres_extension/parameter/optional b/cdist/conf/type/__postgres_extension/parameter/optional new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__postgres_extension/parameter/optional @@ -0,0 +1 @@ +state From 60906c0228d8f844fd31a4434fd5969ae6fe77a3 Mon Sep 17 00:00:00 2001 From: Tomas Pospisek Date: Thu, 1 Dec 2016 09:27:56 +0100 Subject: [PATCH 2/3] rewrite man page in rst Only minimal changes needed. This was done to satisfy darko-poljak's request here: https://github.com/ungleich/cdist/pull/360#issuecomment-263491151 --- .../{man.text => man.rst} | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) rename cdist/conf/type/__postgres_extension/{man.text => man.rst} (58%) diff --git a/cdist/conf/type/__postgres_extension/man.text b/cdist/conf/type/__postgres_extension/man.rst similarity index 58% rename from cdist/conf/type/__postgres_extension/man.text rename to cdist/conf/type/__postgres_extension/man.rst index 6d722d68..39aa0837 100644 --- a/cdist/conf/type/__postgres_extension/man.text +++ b/cdist/conf/type/__postgres_extension/man.rst @@ -1,7 +1,5 @@ cdist-type__postgres_extension(7) ================================= -Tomas Pospisek - NAME ---- @@ -16,35 +14,42 @@ The object you need to pass to __postgres_extension consists of the database name and the extension name joined by a colon in the following form: +.. code-block:: + dbname:extension f.ex. +.. code-block:: + rails_test:unaccent OPTIONAL PARAMETERS ------------------- -state:: - Either "present" or "absent", defaults to "present" +state + either "present" or "absent", defaults to "present" EXAMPLES -------- --------------------------------------------------------------------------------- -__postgres_extension rails_test:unaccent -__postgres_extension --present rails_test:unaccent -__postgres_extension --absent rails_test:unaccent --------------------------------------------------------------------------------- +.. code-block:: sh + + __postgres_extension rails_test:unaccent + __postgres_extension --present rails_test:unaccent + __postgres_extension --absent rails_test:unaccent SEE ALSO -------- -- cdist-type(7) -- cdist-type__postgres_database(7) -- http://www.postgresql.org/docs/current/static/sql-createextension.html +:strong:`cdist-type`\ (7), :strong:`cdist-type__postgre_database`\ (7) +Postgres "Create Extension" documentation at: . + +AUTHOR +------- +Tomas Pospisek COPYING ------- From 267d8239c1b43a1485f5e2bbb1d8cc8bc040bfbc Mon Sep 17 00:00:00 2001 From: Tomas Pospisek Date: Thu, 1 Dec 2016 09:50:05 +0100 Subject: [PATCH 3/3] remove reference to cdist_type, use GPL3+ as requested by darko-poljak here: https://github.com/ungleich/cdist/pull/360#issuecomment-264110087 --- cdist/conf/type/__postgres_extension/man.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__postgres_extension/man.rst b/cdist/conf/type/__postgres_extension/man.rst index 39aa0837..ead51c83 100644 --- a/cdist/conf/type/__postgres_extension/man.rst +++ b/cdist/conf/type/__postgres_extension/man.rst @@ -43,7 +43,7 @@ EXAMPLES SEE ALSO -------- -:strong:`cdist-type`\ (7), :strong:`cdist-type__postgre_database`\ (7) +:strong:`cdist-type__postgre_database`\ (7) Postgres "Create Extension" documentation at: . @@ -53,5 +53,7 @@ Tomas Pospisek COPYING ------- -Copyright \(C) 2014 Tomas Pospisek. Free use of this software is -granted under the terms of the GNU General Public License version 3 (GPLv3). +Copyright \(C) 2014 Tomas Pospisek. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version.