hiera-postgres-backend 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 579e8f9d6c45cca95af59718d95f56e5fe6837d7
4
- data.tar.gz: 9207ad3377c7710fa02dc28cb356afa4e073f115
3
+ metadata.gz: ae0eae161bce8929542a785a6edf2c43391c88de
4
+ data.tar.gz: ededbec5f1d0b38538f5c0e33982cf20d3e3f942
5
5
  SHA512:
6
- metadata.gz: c9c9e91a44f9827794064ecc797c99d85b09cb20943122d1d5f28415deb4f4b19657d486cc405f3ea6d671026a1008134d4760819f52a5809b8e14fdae2ea350
7
- data.tar.gz: 608cb8a8ce53224f2ce9690fcc4217d6bce406e3d390e2440a0f33e9bab98642366eb6bf96c55ba763d3d5c2e0f0b70fa51679f814ad39a8cea03b5fe5e8498f
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
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "hiera-postgres-backend"
5
- gem.version = "0.0.3"
5
+ gem.version = "0.0.4"
6
6
  gem.authors = ["Adrian"]
7
7
  gem.email = ["adrianlzt@gmail.com"]
8
8
  gem.description = %q{Alternative PostgreSQL backend for hiera}
@@ -36,11 +36,16 @@ class Hiera
36
36
 
37
37
  Hiera.debug("data #{data.inspect}")
38
38
  next if data.empty?
39
- next unless data.include?(key)
40
-
41
- Hiera.debug("Found #{key} in #{source}")
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 = PG::Connection.new(:host => pg_host,
72
- :user => pg_user,
73
- :password => pg_pass,
74
- :dbname => pg_database)
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.3
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-01-06 00:00:00.000000000 Z
11
+ date: 2014-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg