ach_flattenmeta 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -1
- data/ach_flattenmeta.gemspec +1 -1
- data/lib/ach_flattenmeta/flattenmeta.rb +22 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bcdbc5f2be0ec39033d928401cbb57e8f07e88e4a4f5808222b6b366f9bad8e
|
4
|
+
data.tar.gz: 4f7dce1ed8b363d236e9bb420cb0b85b3441f0e9c449adf14de6640ea95a53fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04bc9856287cb72df3e70434500f26280671e39aba576defb7a5b89a1a219a5ff4d2d23e80b17b537a37f00f809233b400c585ee57f5dcd8de211a8604c8508e
|
7
|
+
data.tar.gz: fb9e81ada15fb9de6b8c5e99f5eb42e8fbf16f3d5194b62b472bcd33bed1b991d7ff15eec950f13e9de85708847b05bc746c0a789f6b20bae7916d36057ffba7
|
data/README.md
CHANGED
@@ -1 +1,58 @@
|
|
1
|
-
|
1
|
+
ach_flattenmeta gem
|
2
|
+
===================
|
3
|
+
|
4
|
+
This gem provides a class to read a config hash with metadata and return only the relevant config items for your platform and environment
|
5
|
+
based on the data in your metadata.
|
6
|
+
|
7
|
+
It is to be used in chef resources, to make the attribute system more usabled and to write "data driven" resources.
|
8
|
+
|
9
|
+
|
10
|
+
- FlattenMeta class
|
11
|
+
|
12
|
+
Generic class to read a config hash metadata and return only the relevant config items for your platform and environment based on a metadata hash
|
13
|
+
|
14
|
+
Example:
|
15
|
+
```
|
16
|
+
# Firewall rich rules
|
17
|
+
default['fw_richrules']['ach_base'] = {
|
18
|
+
'metadata': {
|
19
|
+
'platforms' => ['rhel7'],
|
20
|
+
'environments' => ['all'],
|
21
|
+
'priority' => ['99'],
|
22
|
+
'active' => true
|
23
|
+
},
|
24
|
+
'rule family="ipv4" source address="192.168.1.101/32" service name="https" accept limit value="1/m"': true
|
25
|
+
}
|
26
|
+
```
|
27
|
+
|
28
|
+
the keyword `all` can be used in the `platforms` and `environments` array to specify any platform/environment
|
29
|
+
|
30
|
+
A priority system is used to override values of existing config items, the lowest priority number equals the highest priority.
|
31
|
+
ach_base config items should default to prio value 99, application cookbooks should defaut to prio 50
|
32
|
+
|
33
|
+
If you want to totally disable a config key,value pair you have to define a new config hash with its `active` property in the meta hash set to false
|
34
|
+
|
35
|
+
Example:# ach_flattenmeta
|
36
|
+
Example:
|
37
|
+
```
|
38
|
+
default['ach_sysctl']['ach_base'] = {
|
39
|
+
'metadata' => {
|
40
|
+
'platform' => ['default'],
|
41
|
+
'environments' => ['default'],
|
42
|
+
'priority' => 99,
|
43
|
+
'active'=> true
|
44
|
+
},
|
45
|
+
'sunrpc.transports' => 'udp 32768',
|
46
|
+
'vm.nr_hugepages' => 0
|
47
|
+
}
|
48
|
+
|
49
|
+
default['ach_sysctl']['ach_base_override'] = {
|
50
|
+
'metadata' => {
|
51
|
+
'platform' => ['default'],
|
52
|
+
'environments' => ['default'],
|
53
|
+
'priority' => 99,
|
54
|
+
'active'=> false
|
55
|
+
},
|
56
|
+
'vm.nr_hugepages' => 0
|
57
|
+
}
|
58
|
+
```
|
data/ach_flattenmeta.gemspec
CHANGED
@@ -20,22 +20,27 @@ module AchFlattenMeta
|
|
20
20
|
private
|
21
21
|
def filter()
|
22
22
|
@confhash.each do | location, data|
|
23
|
-
|
24
|
-
|
23
|
+
# Do some basic sanity checks on the config hash passed
|
24
|
+
raise ArgumentError, 'environments is not an Array' unless data['metadata']['environments'].kind_of?(Array)
|
25
|
+
raise ArgumentError, 'platforms is not an Array' unless data['metadata']['platforms'].kind_of?(Array)
|
26
|
+
raise ArgumentError, 'priority is not an Integer' unless data['metadata']['priority'].is_a? Integer
|
27
|
+
raise ArgumentError, 'active is not a Boolean' unless data['metadata']['active'].is_a? TrueClass or data['metadata']['active'].is_a? FalseClass
|
28
|
+
if(data['metadata']['environments'] & [@node_environment, 'all']).any? &&
|
29
|
+
(data['metadata']['platforms'] & [@os_version, 'all']).any?
|
25
30
|
|
26
|
-
|
27
|
-
|
31
|
+
prio = data['metadata']['priority']
|
32
|
+
active = data['metadata']['active']
|
28
33
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end # if
|
38
|
-
end # each
|
39
|
-
end # def
|
40
|
-
end # class
|
41
|
-
end
|
34
|
+
data.each do | k, v |
|
35
|
+
next if k == 'metadata'
|
36
|
+
if @flatconf.key?(k)
|
37
|
+
@flatconf[k] = { 'value' => v, 'priority' => prio, 'active' => active } if @flatconf[k]['priority'] > prio
|
38
|
+
else
|
39
|
+
@flatconf[k] = { 'value' => v, 'priority' => prio, 'active' => active }
|
40
|
+
end # if 'metadata'
|
41
|
+
end #data.each
|
42
|
+
end # if any?
|
43
|
+
end # @confhas.each
|
44
|
+
end # def filter
|
45
|
+
end # class FlattenMeta
|
46
|
+
end # module AchFlattenMeta
|