hiera-mysql-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 +7 -0
- data/Gemfile.lock +4 -4
- data/README.md +9 -0
- data/hiera-mysql-backend.gemspec +1 -1
- data/lib/hiera/backend/mysql2_backend.rb +17 -12
- metadata +29 -28
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bed2f5ccd27f43d661e3b382d5b5b3add9c7f01f
|
4
|
+
data.tar.gz: de44292bef0ed41a782bc65bc25c222c5085ee05
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad9ca9fb6314f8a4aab540b7afb9609f9b3bc1c1ee6830d9b11be896b0f069c621586e61962c751344c1e8ef14f107f0852c3b9881d29045c2d98cfb1de7775f
|
7
|
+
data.tar.gz: a80ffa09404dc92db4b245700f4625b812fcec43c81795d2f309381448cac46f279af70aa861670efba062564b224985d940b980fcb16b19247ab78e9d129951
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hiera-mysql-backend (0.0.
|
4
|
+
hiera-mysql-backend (0.0.4)
|
5
5
|
hiera
|
6
6
|
mysql2
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
hiera (1.
|
11
|
+
hiera (1.3.1)
|
12
12
|
json_pure
|
13
|
-
json_pure (1.8.
|
14
|
-
mysql2 (0.3.
|
13
|
+
json_pure (1.8.1)
|
14
|
+
mysql2 (0.3.14)
|
15
15
|
rake (10.1.0)
|
16
16
|
|
17
17
|
PLATFORMS
|
data/README.md
CHANGED
@@ -18,10 +18,19 @@ Exception handling. hiera-mysql would cause a puppet run to fail if one of the q
|
|
18
18
|
|
19
19
|
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)
|
20
20
|
|
21
|
+
As of version 0.0.4 you can also add connection information to these sql files, this allows you to connect to different databases. This is optional if no connection information is found it will use the default defined in your hiera.yaml config.
|
22
|
+
|
21
23
|
Lets assume your _datadir_ is `/etc/puppet/hieradata/` and your hierarchy for hiera just have a common. hiera-mysql-backend would look for /etc/puppet/hieradata/common.sql the common.sql would look like:
|
22
24
|
|
23
25
|
```yaml
|
24
26
|
---
|
27
|
+
# This is optional, if not present it will use the default connection info from hiera.yaml
|
28
|
+
:dbconfig:
|
29
|
+
:host: database.example.com
|
30
|
+
:user: hieratest
|
31
|
+
:pass: sekret
|
32
|
+
:database: testhieradb
|
33
|
+
|
25
34
|
applications: SELECT * FROM applications WHERE host='%{fqdn}';
|
26
35
|
coats: SELECT cut,name,type FROM coats WHERE color='brown';
|
27
36
|
```
|
data/hiera-mysql-backend.gemspec
CHANGED
@@ -34,6 +34,19 @@ class Hiera
|
|
34
34
|
YAML.load(datafile)
|
35
35
|
end
|
36
36
|
|
37
|
+
mysql_host = data.fetch(:dbconfig, {}).fetch(:host, nil) || Config[:mysql2][:host]
|
38
|
+
mysql_user = data.fetch(:dbconfig, {}).fetch(:user, nil) || Config[:mysql2][:user]
|
39
|
+
mysql_pass = data.fetch(:dbconfig, {}).fetch(:pass, nil) || Config[:mysql2][:pass]
|
40
|
+
mysql_database = data.fetch(:dbconfig, {}).fetch(:database, nil) || Config[:mysql2][:database]
|
41
|
+
|
42
|
+
connection_hash = {
|
43
|
+
:host => mysql_host,
|
44
|
+
:username => mysql_user,
|
45
|
+
:password => mysql_pass,
|
46
|
+
:database => mysql_database,
|
47
|
+
:reconnect => true}
|
48
|
+
|
49
|
+
|
37
50
|
Hiera.debug("data #{data.inspect}")
|
38
51
|
next if data.empty?
|
39
52
|
next unless data.include?(key)
|
@@ -41,26 +54,18 @@ class Hiera
|
|
41
54
|
Hiera.debug("Found #{key} in #{source}")
|
42
55
|
|
43
56
|
new_answer = Backend.parse_answer(data[key], scope)
|
44
|
-
results = query(new_answer)
|
57
|
+
results = query(connection_hash, new_answer)
|
45
58
|
|
46
59
|
end
|
47
|
-
|
60
|
+
return results
|
48
61
|
end
|
49
62
|
|
50
63
|
|
51
|
-
def query(query)
|
64
|
+
def query(connection_hash, query)
|
52
65
|
Hiera.debug("Executing SQL Query: #{query}")
|
53
66
|
|
54
67
|
data=nil
|
55
|
-
|
56
|
-
mysql_user = Config[:mysql2][:user]
|
57
|
-
mysql_pass = Config[:mysql2][:pass]
|
58
|
-
mysql_database = Config[:mysql2][:database]
|
59
|
-
client = Mysql2::Client.new(:host => mysql_host,
|
60
|
-
:username => mysql_user,
|
61
|
-
:password => mysql_pass,
|
62
|
-
:database => mysql_database,
|
63
|
-
:reconnect => true)
|
68
|
+
client = Mysql2::Client.new(connection_hash)
|
64
69
|
begin
|
65
70
|
data = client.query(query).to_a
|
66
71
|
Hiera.debug("Mysql Query returned #{data.size} rows")
|
metadata
CHANGED
@@ -1,49 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera-mysql-backend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Telmo
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: mysql2
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: hiera
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rake
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
description: Alternative MySQL backend for hiera
|
48
56
|
email:
|
49
57
|
- telmox@gmail.com
|
@@ -51,7 +59,7 @@ executables: []
|
|
51
59
|
extensions: []
|
52
60
|
extra_rdoc_files: []
|
53
61
|
files:
|
54
|
-
- .gitignore
|
62
|
+
- ".gitignore"
|
55
63
|
- Gemfile
|
56
64
|
- Gemfile.lock
|
57
65
|
- LICENSE
|
@@ -61,32 +69,25 @@ files:
|
|
61
69
|
- lib/hiera/backend/mysql2_backend.rb
|
62
70
|
homepage: https://github.com/Telmo/hiera-mysql-backend
|
63
71
|
licenses: []
|
72
|
+
metadata: {}
|
64
73
|
post_install_message:
|
65
74
|
rdoc_options: []
|
66
75
|
require_paths:
|
67
76
|
- lib
|
68
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
78
|
requirements:
|
71
|
-
- -
|
79
|
+
- - ">="
|
72
80
|
- !ruby/object:Gem::Version
|
73
81
|
version: '0'
|
74
|
-
segments:
|
75
|
-
- 0
|
76
|
-
hash: 1582863243963958738
|
77
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
-
none: false
|
79
83
|
requirements:
|
80
|
-
- -
|
84
|
+
- - ">="
|
81
85
|
- !ruby/object:Gem::Version
|
82
86
|
version: '0'
|
83
|
-
segments:
|
84
|
-
- 0
|
85
|
-
hash: 1582863243963958738
|
86
87
|
requirements: []
|
87
88
|
rubyforge_project:
|
88
|
-
rubygems_version:
|
89
|
+
rubygems_version: 2.2.0
|
89
90
|
signing_key:
|
90
|
-
specification_version:
|
91
|
+
specification_version: 4
|
91
92
|
summary: Alternative MySQL backend for hiera
|
92
93
|
test_files: []
|