Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: modules/discourse/manifests/sitesetting.pp

Issue 9351210: Define Discourse admins and site settings in Puppet, separate private data from other settings (Closed)
Patch Set: Created Feb. 19, 2013, 3:08 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: modules/discourse/manifests/sitesetting.pp
===================================================================
new file mode 100644
--- /dev/null
+++ b/modules/discourse/manifests/sitesetting.pp
@@ -0,0 +1,36 @@
+define discourse::sitesetting(
+ $setting = $title,
+ $value = undef,
+ $type = 1,
+ $ensure = 'present'
+) {
+ # Attempt some escaping
+ $escaped_value = regsubst($value, '[\'\\]', '\\\1', 'G')
+ $escaped_setting = regsubst($setting, '[\'\\]', '\\\1', 'G')
+ $escaped_type = regsubst($type, '\D', '', 'G')
+
+ case $ensure {
+ default: {
+ err("unknown ensure value ${ensure}")
+ }
+ present: {
+ # This is apparently how you do a conditional INSERT in PostgreSQL - sorry
Felix Dahlke 2013/02/21 15:27:40 Looked a bit into this myself, your method is quit
+ $update_sql = "UPDATE site_settings SET value = '$escaped_value', data_type = $escaped_type WHERE name = '$escaped_setting' RETURNING 1"
+ $columns = "name, data_type, value, created_at, updated_at"
+ $values = "SELECT '$escaped_setting', $escaped_type, '$escaped_value', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP"
+
+ postgresql_psql {"WITH upd AS ($update_sql) INSERT INTO site_settings ($columns) $values WHERE NOT EXISTS (SELECT * FROM upd)":
+ db => 'discourse',
+ psql_user => 'discourse',
+ unless => 'SELECT false'
+ }
+ }
+ absent: {
+ postgresql_psql {"DELETE FROM site_settings WHERE name = '$escaped_setting'":
+ db => 'discourse',
+ psql_user => 'discourse',
+ unless => 'SELECT false'
+ }
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld