hiera-postgres-backend 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/hiera-postgres-backend.gemspec +1 -1
- data/lib/hiera/backend/postgres_backend.rb +13 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae0eae161bce8929542a785a6edf2c43391c88de
|
4
|
+
data.tar.gz: ededbec5f1d0b38538f5c0e33982cf20d3e3f942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d173d87da3823cb9772f287248d16b88cd44748260d89123258cbab74d78199a6dc92a0c7c71b06fee7f6f0cea72a9a82e145fb867a809249239b3c90007bd9
|
7
|
+
data.tar.gz: e1846468968bdb6e51192c810aa56f69304538e6932e6cf4729b7c8a5988e507bda02ea7286c42c73b61224b5d8617bbc2611d4a6ae33f481837497319954f56
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ This is a PostgreSQL backend for Hiera inspired by [hiera-mysql-backend](https:/
|
|
7
7
|
|
8
8
|
### What goes into the sql files.
|
9
9
|
|
10
|
-
The poorly named sql files are really yaml files where the key is the lookup key and the value is the SQL statement (it accepts interpolation)
|
10
|
+
The poorly named sql files are really yaml files where the key is the lookup key and the value is the SQL statement (it accepts interpolation).
|
11
11
|
|
12
12
|
Lets assume your _datadir_ is `/etc/puppet/hieradata/` and your hierarchy for hiera just have a common. hiera-postgresql-backend would look for /etc/puppet/hieradata/common.sql the common.sql would look like:
|
13
13
|
|
@@ -15,10 +15,13 @@ Lets assume your _datadir_ is `/etc/puppet/hieradata/` and your hierarchy for hi
|
|
15
15
|
---
|
16
16
|
applications: SELECT * FROM applications WHERE host='%{fqdn}';
|
17
17
|
coats: SELECT cut,name,type FROM coats WHERE color='brown';
|
18
|
+
default_query: SELECT dbhost, dbuser, dbpass FROM db_servers WHERE dbclient='%{fqdn}' and dbname='%{key}';
|
18
19
|
```
|
19
20
|
|
20
21
|
running `hiera applications` would run the query against the configured database.
|
21
22
|
|
23
|
+
The default_query key is special: it is in fact a default for anything in this hierarchy that is not specified with its own key. For example, running `hiera booksdb` would run default_query with the key variable in the query being interpolated as "booksdb".
|
24
|
+
|
22
25
|
|
23
26
|
### Using
|
24
27
|
|
@@ -36,11 +36,16 @@ class Hiera
|
|
36
36
|
|
37
37
|
Hiera.debug("data #{data.inspect}")
|
38
38
|
next if data.empty?
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
if data.include?(key)
|
40
|
+
Hiera.debug("Found #{key} in #{source}")
|
41
|
+
new_answer = Backend.parse_answer(data[key], scope, { 'key' => key } )
|
42
|
+
elsif data.include?('default_query')
|
43
|
+
Hiera.debug("Found default_query in #{source}")
|
44
|
+
new_answer = Backend.parse_answer(data['default_query'], scope, { 'key' => key } )
|
45
|
+
else
|
46
|
+
next
|
47
|
+
end
|
42
48
|
|
43
|
-
new_answer = Backend.parse_answer(data[key], scope)
|
44
49
|
case resolution_type
|
45
50
|
when :array
|
46
51
|
raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
|
@@ -68,10 +73,10 @@ class Hiera
|
|
68
73
|
pg_user = Config[:postgres][:user]
|
69
74
|
pg_pass = Config[:postgres][:pass]
|
70
75
|
pg_database = Config[:postgres][:database]
|
71
|
-
client =
|
72
|
-
|
73
|
-
|
74
|
-
|
76
|
+
client = PGconn.open(:host => pg_host,
|
77
|
+
:user => pg_user,
|
78
|
+
:password => pg_pass,
|
79
|
+
:dbname => pg_database)
|
75
80
|
begin
|
76
81
|
data = client.exec(query).to_a
|
77
82
|
Hiera.debug("PostgreSQL Query returned #{data.size} rows")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera-postgres-backend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|